Skip to content

Commit 8364f6c

Browse files
committed
Fix another import ordering / newline issue
MOE_MIGRATED_REVID=172516439
1 parent 352aac7 commit 8364f6c

File tree

3 files changed

+14
-7
lines changed

3 files changed

+14
-7
lines changed

core/src/main/java/com/google/googlejavaformat/java/ImportOrderer.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -227,10 +227,6 @@ private ImportsAndIndex scanImports(int i) throws FormatterException {
227227
if (isNewlineToken(i)) {
228228
trailing.append(tokenAt(i));
229229
i++;
230-
} else if (tokenAt(i).equals("import")) {
231-
// continue
232-
} else {
233-
throw new FormatterException("Extra tokens after import: " + tokenAt(i));
234230
}
235231
imports.add(new Import(importedName, trailing.toString(), isStatic));
236232
// Remember the position just after the import we just saw, before skipping blank lines.

core/src/main/java/com/google/googlejavaformat/java/JavacTokens.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public static ImmutableList<RawTok> getTokens(
9999
}
100100
if (stopTokens.contains(t.kind)) {
101101
if (t.kind != TokenKind.EOF) {
102-
end = t.endPos - 1;
102+
end = t.pos;
103103
}
104104
break;
105105
}

core/src/test/java/com/google/googlejavaformat/java/ImportOrdererTest.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ public static Collection<Object[]> parameters() {
286286
"import com.foo.First;",
287287
},
288288
{
289-
"!!Extra tokens after import: /* no block comments after imports */",
289+
"!!Imports not contiguous (perhaps a comment separates them?)",
290290
}
291291
},
292292
{
@@ -353,7 +353,18 @@ public static Collection<Object[]> parameters() {
353353
"",
354354
"class Test {}",
355355
}
356-
}
356+
},
357+
{
358+
{
359+
"import com.foo.Second; import com.foo.First; class Test {}",
360+
},
361+
{
362+
"import com.foo.First;", //
363+
"import com.foo.Second;",
364+
"",
365+
"class Test {}",
366+
}
367+
},
357368
};
358369
ImmutableList.Builder<Object[]> builder = ImmutableList.builder();
359370
for (String[][] inputAndOutput : inputsOutputs) {

0 commit comments

Comments
 (0)