Skip to content

Commit

Permalink
Dynamically detect class tree kinds, avoid hardcoded enum set
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelhixson committed Dec 26, 2019
1 parent 85b30f1 commit a41a532
Showing 1 changed file with 5 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -802,18 +802,12 @@ public static boolean isCompileTimeString(ExpressionTree node) {
// Adding Tree.Kind.NEW_CLASS here doesn't work, because then a
// tree gets cast to ClassTree when it is actually a NewClassTree,
// for example in enclosingClass above.
private static final Set<Tree.Kind> classTreeKinds =
EnumSet.of(
Tree.Kind.CLASS,
Tree.Kind.ENUM,
Tree.Kind.INTERFACE,
Tree.Kind.ANNOTATION_TYPE);

private static final Set<Tree.Kind> classTreeKinds = EnumSet.noneOf(Tree.Kind.class);
static {
try {
classTreeKinds.add(Tree.Kind.valueOf("RECORD"));
} catch (IllegalArgumentException ignored) {
// We're using a version of Java that doesn't have records.
for (Tree.Kind kind : Tree.Kind.values()) {
if (kind.asInterface() == ClassTree.class) {
classTreeKinds.add(kind);
}
}
}

Expand Down

0 comments on commit a41a532

Please sign in to comment.