+48
-18
lines changedFilter options
+48
-18
lines changed Original file line number Diff line number Diff line change
@@ -49,7 +49,7 @@ public int line() {
49
49
}
50
50
51
51
/**
52
-
* Returns the 0-indexed column number on which the error occurred, or {@code -1} if the error
52
+
* Returns the 1-indexed column number on which the error occurred, or {@code -1} if the error
53
53
* does not have a column.
54
54
*/
55
55
public int column() {
@@ -61,14 +61,14 @@ public String message() {
61
61
return message;
62
62
}
63
63
64
+
@Override
64
65
public String toString() {
65
66
StringBuilder sb = new StringBuilder();
66
67
if (lineNumber >= 0) {
67
68
sb.append(lineNumber).append(':');
68
69
}
69
70
if (column >= 0) {
70
-
// internal column numbers are 0-based, but diagnostics use 1-based indexing by convention
71
-
sb.append(column + 1).append(':');
71
+
sb.append(column).append(':');
72
72
}
73
73
if (lineNumber >= 0 || column >= 0) {
74
74
sb.append(' ');
Original file line number Diff line number Diff line change
@@ -69,7 +69,7 @@ public String formatDiagnostics(String path, String input) {
69
69
if (line != -1 && column != -1) {
70
70
sb.append(CharMatcher.breakingWhitespace().trimTrailingFrom(lines.get(line - 1)))
71
71
.append(System.lineSeparator());
72
-
sb.append(" ".repeat(column)).append('^').append(System.lineSeparator());
72
+
sb.append(" ".repeat(column - 1)).append('^').append(System.lineSeparator());
73
73
}
74
74
}
75
75
return sb.toString();
Original file line number Diff line number Diff line change
@@ -79,7 +79,7 @@ public void parseError() throws Exception {
79
79
80
80
int result = main.format(path.toString());
81
81
assertThat(stdout.toString()).isEmpty();
82
-
assertThat(stderr.toString()).contains("InvalidSyntax.java:2:29: error: <identifier> expected");
82
+
assertThat(stderr.toString()).contains("InvalidSyntax.java:2:28: error: <identifier> expected");
83
83
assertThat(result).isEqualTo(1);
84
84
}
85
85
@@ -119,7 +119,7 @@ public void oneFileParseError() throws Exception {
119
119
120
120
int result = main.format(pathOne.toString(), pathTwo.toString());
121
121
assertThat(stdout.toString()).isEqualTo(two);
122
-
assertThat(stderr.toString()).contains("One.java:1:13: error: reached end of file");
122
+
assertThat(stderr.toString()).contains("One.java:1:12: error: reached end of file");
123
123
assertThat(result).isEqualTo(1);
124
124
}
125
125
@@ -141,7 +141,7 @@ public void oneFileParseErrorReplace() throws Exception {
141
141
142
142
int result = main.format("-i", pathOne.toString(), pathTwo.toString());
143
143
assertThat(stdout.toString()).isEmpty();
144
-
assertThat(stderr.toString()).contains("One.java:1:14: error: class, interface");
144
+
assertThat(stderr.toString()).contains("One.java:1:13: error: class, interface");
145
145
assertThat(result).isEqualTo(1);
146
146
// don't edit files with parse errors
147
147
assertThat(Files.readAllLines(pathOne, UTF_8)).containsExactly("class One {}}");
@@ -164,7 +164,7 @@ public void parseError2() throws FormatterException, IOException, UsageException
164
164
int exitCode = main.format(args);
165
165
166
166
assertThat(exitCode).isEqualTo(1);
167
-
assertThat(err.toString()).contains("A.java:2:6: error: ';' expected");
167
+
assertThat(err.toString()).contains("A.java:2:5: error: ';' expected");
168
168
}
169
169
170
170
@Test
@@ -179,7 +179,7 @@ public void parseErrorStdin() throws FormatterException, IOException, UsageExcep
179
179
int exitCode = main.format(args);
180
180
181
181
assertThat(exitCode).isEqualTo(1);
182
-
assertThat(err.toString()).contains("<stdin>:2:6: error: ';' expected");
182
+
assertThat(err.toString()).contains("<stdin>:2:5: error: ';' expected");
183
183
}
184
184
185
185
@Test
@@ -198,7 +198,7 @@ public void lexError2() throws FormatterException, IOException, UsageException {
198
198
int exitCode = main.format(args);
199
199
200
200
assertThat(exitCode).isEqualTo(1);
201
-
assertThat(err.toString()).contains("A.java:2:5: error: unclosed character literal");
201
+
assertThat(err.toString()).contains("A.java:2:4: error: unclosed character literal");
202
202
}
203
203
204
204
@Test
@@ -212,6 +212,6 @@ public void lexErrorStdin() throws FormatterException, IOException, UsageExcepti
212
212
int exitCode = main.format(args);
213
213
214
214
assertThat(exitCode).isEqualTo(1);
215
-
assertThat(err.toString()).contains("<stdin>:2:5: error: unclosed character literal");
215
+
assertThat(err.toString()).contains("<stdin>:2:4: error: unclosed character literal");
216
216
}
217
217
}
Original file line number Diff line number Diff line change
@@ -307,7 +307,7 @@ public void importRemoveErrorParseError() throws Exception {
307
307
new PrintWriter(err, true),
308
308
new ByteArrayInputStream(joiner.join(input).getBytes(UTF_8)));
309
309
assertThat(main.format("-")).isEqualTo(1);
310
-
assertThat(err.toString()).contains("<stdin>:4:3: error: class, interface");
310
+
assertThat(err.toString()).contains("<stdin>:4:2: error: class, interface");
311
311
312
312
} finally {
313
313
Locale.setDefault(backupLocale);
@@ -508,7 +508,7 @@ public void assumeFilename_error() throws Exception {
508
508
new PrintWriter(err, true),
509
509
new ByteArrayInputStream(joiner.join(input).getBytes(UTF_8)));
510
510
assertThat(main.format("--assume-filename=Foo.java", "-")).isEqualTo(1);
511
-
assertThat(err.toString()).contains("Foo.java:1:15: error: class, interface");
511
+
assertThat(err.toString()).contains("Foo.java:1:14: error: class, interface");
512
512
}
513
513
514
514
@Test
@@ -637,11 +637,13 @@ public void reorderModifiersOptionTest() throws Exception {
637
637
}
638
638
639
639
@Test
640
-
public void badIdentifier() throws Exception {
640
+
public void syntaxError() throws Exception {
641
641
Path path = testFolder.newFile("Test.java").toPath();
642
642
String[] input = {
643
643
"class Test {", //
644
-
" void f(int package) {}",
644
+
" void f(int package) {",
645
+
" int",
646
+
" }",
645
647
"}",
646
648
"",
647
649
};
@@ -653,9 +655,37 @@ public void badIdentifier() throws Exception {
653
655
int errorCode = main.format(path.toAbsolutePath().toString());
654
656
assertWithMessage("Error Code").that(errorCode).isEqualTo(1);
655
657
String[] expected = {
656
-
path + ":2:14: error: <identifier> expected", //
657
-
" void f(int package) {}",
658
-
" ^",
658
+
path + ":2:13: error: <identifier> expected",
659
+
" void f(int package) {",
660
+
" ^",
661
+
path + ":3:5: error: not a statement",
662
+
" int",
663
+
" ^",
664
+
path + ":3:8: error: ';' expected",
665
+
" int",
666
+
" ^",
667
+
"",
668
+
};
669
+
assertThat(err.toString()).isEqualTo(joiner.join(expected));
670
+
}
671
+
672
+
@Test
673
+
public void syntaxErrorBeginning() throws Exception {
674
+
Path path = testFolder.newFile("Test.java").toPath();
675
+
String[] input = {
676
+
"error", //
677
+
};
678
+
String source = joiner.join(input);
679
+
Files.writeString(path, source, UTF_8);
680
+
StringWriter out = new StringWriter();
681
+
StringWriter err = new StringWriter();
682
+
Main main = new Main(new PrintWriter(out, true), new PrintWriter(err, true), System.in);
683
+
int errorCode = main.format(path.toAbsolutePath().toString());
684
+
assertWithMessage("Error Code").that(errorCode).isEqualTo(1);
685
+
String[] expected = {
686
+
path + ":1:1: error: reached end of file while parsing", //
687
+
"error",
688
+
"^",
659
689
"",
660
690
};
661
691
assertThat(err.toString()).isEqualTo(joiner.join(expected));
You can’t perform that action at this time.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4