/** Is t an anonymous inner class or a lambda? */ private boolean isValidTreeType(Tree t) { if (t instanceof LambdaExpressionTree) { return true; } if (t instanceof ClassTree) { NestingKind nestingKind = ASTHelpers.getSymbol((ClassTree) t).getNestingKind(); return nestingKind.equals(NestingKind.ANONYMOUS) || nestingKind.equals(NestingKind.LOCAL); } return false; } }
@Nullable private ClassTree findEnclosingLocalOrAnonymousClass(ClassTree classTree) { Symbol.ClassSymbol symbol = ASTHelpers.getSymbol(classTree); // we need this while loop since we can have a NestingKind.NESTED class (i.e., a nested // class declared at the top-level within its enclosing class) nested (possibly deeply) // within a NestingKind.ANONYMOUS or NestingKind.LOCAL class while (symbol.getNestingKind().isNested()) { if (symbol.getNestingKind().equals(NestingKind.ANONYMOUS) || symbol.getNestingKind().equals(NestingKind.LOCAL)) { return Trees.instance(JavacProcessingEnvironment.instance(context)).getTree(symbol); } else { // symbol.owner is the enclosing element, which could be a class or a method. // if it's a class, the enclClass() method will (surprisingly) return the class itself, // so this works symbol = symbol.owner.enclClass(); } } return null; }
public static boolean isTopLevelType(Element e) { if (!ElementKind.CLASS.equals(e.getKind())) { return false; } TypeElement te = (TypeElement)e; if (!NestingKind.TOP_LEVEL.equals(te.getNestingKind())) { return false; } return true; } }
"A pljava function must not have a non-public " + "enclosing class"); if ( ((TypeElement)ee).getNestingKind().equals( NestingKind.TOP_LEVEL) ) break;