Skip to content

Commit b769e81

Browse files
cushongoogle-java-format Team
authored and
google-java-format Team
committed
Tolerate extra semi-colons in import lists
even if they're own their own line (which g-j-f does if it runs with import cleanup disabled). PiperOrigin-RevId: 337192414
1 parent ea4828a commit b769e81

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,10 @@ private ImportsAndIndex scanImports(int i) throws FormatterException {
346346
i++;
347347
}
348348
}
349+
while (tokenAt(i).equals(";")) {
350+
// Extra semicolons are not allowed by the JLS but are accepted by javac.
351+
i++;
352+
}
349353
imports.add(new Import(importedName, trailing.toString(), isStatic));
350354
// Remember the position just after the import we just saw, before skipping blank lines.
351355
// If the next thing after the blank lines is not another import then we don't want to

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -800,6 +800,27 @@ public static Collection<Object[]> parameters() {
800800
"public class Blim {}",
801801
},
802802
},
803+
{
804+
{
805+
"package p;",
806+
"",
807+
"import java.lang.Bar;",
808+
"import java.lang.Baz;",
809+
";",
810+
"import java.lang.Foo;",
811+
"",
812+
"interface Test {}",
813+
},
814+
{
815+
"package p;",
816+
"",
817+
"import java.lang.Bar;",
818+
"import java.lang.Baz;",
819+
"import java.lang.Foo;",
820+
"",
821+
"interface Test {}",
822+
}
823+
}
803824
};
804825
ImmutableList.Builder<Object[]> builder = ImmutableList.builder();
805826
Arrays.stream(inputsOutputs).forEach(input -> builder.add(createRow(input)));

0 commit comments

Comments
 (0)