Skip to content

Commit e44b58a

Browse files
committed
Handle extra semis in import lists
as a work-around for https://bugs.openjdk.java.net/browse/JDK-8027682. MOE_MIGRATED_REVID=145835186
1 parent d3d9a9c commit e44b58a

File tree

4 files changed

+22
-2
lines changed

4 files changed

+22
-2
lines changed

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,11 @@ public Void visitCompilationUnit(CompilationUnitTree node, Void unused) {
342342
}
343343
dropEmptyDeclarations();
344344
for (Tree type : node.getTypeDecls()) {
345+
if (type.getKind() == Tree.Kind.IMPORT) {
346+
// javac treats extra semicolons in the import list as type declarations
347+
// TODO(cushon): remove this if https://bugs.openjdk.java.net/browse/JDK-8027682 is fixed
348+
continue;
349+
}
345350
if (!first) {
346351
builder.blankLineWanted(BlankLineWanted.YES);
347352
}
@@ -1070,6 +1075,8 @@ public Void visitImport(ImportTree node, Void unused) {
10701075
}
10711076
visitName(node.getQualifiedIdentifier());
10721077
token(";");
1078+
// TODO(cushon): remove this if https://bugs.openjdk.java.net/browse/JDK-8027682 is fixed
1079+
dropEmptyDeclarations();
10731080
return null;
10741081
}
10751082

core/src/test/resources/com/google/googlejavaformat/java/testdata/B21647014.output

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package test;
22

3-
import java.util.List;
4-
;;
3+
import java.util.List;;;
54

65
class Test {;
76
public int x = 42;;;;;
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import a.A;;
2+
import b.B;
3+
4+
class Test {
5+
A a;
6+
B b;
7+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import a.A;;
2+
import b.B;
3+
4+
class Test {
5+
A a;
6+
B b;
7+
}

0 commit comments

Comments
 (0)