Skip to content

Commit

Permalink
Don't crash on empty enum declarations
Browse files Browse the repository at this point in the history
Fixes #281

MOE_MIGRATED_REVID=197211835
  • Loading branch information
cushon committed May 18, 2018
1 parent c68bb9c commit 9cf8dc1
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -834,10 +834,24 @@ public boolean visitEnumDeclaration(ClassTree node) {
members.add(member);
}
if (enumConstants.isEmpty() && members.isEmpty()) {
builder.open(ZERO);
builder.blankLineWanted(BlankLineWanted.NO);
token("}");
builder.close();
if (builder.peekToken().equals(Optional.of(";"))) {
builder.open(plusTwo);
builder.forcedBreak();
token(";");
builder.forcedBreak();
dropEmptyDeclarations();
builder.close();
builder.open(ZERO);
builder.forcedBreak();
builder.blankLineWanted(BlankLineWanted.NO);
token("}", plusTwo);
builder.close();
} else {
builder.open(ZERO);
builder.blankLineWanted(BlankLineWanted.NO);
token("}");
builder.close();
}
} else {
builder.open(plusTwo);
builder.blankLineWanted(BlankLineWanted.NO);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
public enum Empty {}
public enum Empty {;}
public enum Empty {;;;}
public enum Empty {; // comment
;;}
public enum Empty {;
;; // comment
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
public enum Empty {}

public enum Empty {
;
}

public enum Empty {
;
;;
}

public enum Empty {
; // comment
;;
}

public enum Empty {
;
;; // comment
}

0 comments on commit 9cf8dc1

Please sign in to comment.