Skip to content

Commit

Permalink
Tolerate extra semi-colons in import lists
Browse files Browse the repository at this point in the history
even if they're own their own line (which g-j-f does if it runs with import
cleanup disabled).

PiperOrigin-RevId: 337192414
  • Loading branch information
cushon authored and google-java-format Team committed Oct 14, 2020
1 parent ea4828a commit b769e81
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,10 @@ private ImportsAndIndex scanImports(int i) throws FormatterException {
i++;
}
}
while (tokenAt(i).equals(";")) {
// Extra semicolons are not allowed by the JLS but are accepted by javac.
i++;
}
imports.add(new Import(importedName, trailing.toString(), isStatic));
// Remember the position just after the import we just saw, before skipping blank lines.
// If the next thing after the blank lines is not another import then we don't want to
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -800,6 +800,27 @@ public static Collection<Object[]> parameters() {
"public class Blim {}",
},
},
{
{
"package p;",
"",
"import java.lang.Bar;",
"import java.lang.Baz;",
";",
"import java.lang.Foo;",
"",
"interface Test {}",
},
{
"package p;",
"",
"import java.lang.Bar;",
"import java.lang.Baz;",
"import java.lang.Foo;",
"",
"interface Test {}",
}
}
};
ImmutableList.Builder<Object[]> builder = ImmutableList.builder();
Arrays.stream(inputsOutputs).forEach(input -> builder.add(createRow(input)));
Expand Down

0 comments on commit b769e81

Please sign in to comment.