@Override protected Iterable<? extends AnnotationTree> getChildNodes(T tree, VisitorState state) { if (tree instanceof ClassTree) { return ((ClassTree) tree).getModifiers().getAnnotations(); } else if (tree instanceof VariableTree) { return ((VariableTree) tree).getModifiers().getAnnotations(); } else if (tree instanceof MethodTree) { return ((MethodTree) tree).getModifiers().getAnnotations(); } else if (tree instanceof CompilationUnitTree) { return ((CompilationUnitTree) tree).getPackageAnnotations(); } else if (tree instanceof PackageTree) { return ((PackageTree) tree).getAnnotations(); } else { throw new IllegalArgumentException( "Cannot access annotations from tree of type " + tree.getClass()); } }
/** * Gets the symbol declared by a tree. Returns null if {@code tree} does not declare a symbol or * is null. */ public static Symbol getDeclaredSymbol(Tree tree) { if (tree instanceof AnnotationTree) { return getSymbol(((AnnotationTree) tree).getAnnotationType()); } if (tree instanceof PackageTree) { return getSymbol((PackageTree) tree); } if (tree instanceof ParameterizedTypeTree) { return getSymbol(((ParameterizedTypeTree) tree).getType()); } if (tree instanceof TypeParameterTree) { Type type = ((JCTypeParameter) tree).type; return type == null ? null : type.tsym; } if (tree instanceof ClassTree) { return getSymbol((ClassTree) tree); } if (tree instanceof MethodTree) { return getSymbol((MethodTree) tree); } if (tree instanceof VariableTree) { return getSymbol((VariableTree) tree); } return null; }
@Override public Tree visitPackage(PackageTree tree, Void p) { PackageTree n = make.Package(tree.getAnnotations(), tree.getPackageName()); model.setElement(n, model.getElement(tree)); comments.copyComments(tree, n); model.setPos(n, model.getPos(tree)); return n; }
@Override public Void visitPackage(PackageTree tree, List<Node> d) { List<Node> below = new ArrayList<Node>(); addCorrespondingType(below); addCorrespondingComments(below); super.visitPackage(tree, below); d.add(new TreeNode(info, getCurrentPath(), below)); return null; }
@Override public List<? extends TypeMirror> visitPackage(PackageTree pt, Object p) { return null; }
@Override @DefinedBy(Api.COMPILER_TREE) public Void visitPackage(PackageTree tree, Void ignore) { visitDecl(tree, null); return super.visitPackage(tree, ignore); }
@Override public Void visitPackage(PackageTree node, Set<String> p) { return null; }
@Override @DefinedBy(Api.COMPILER_TREE) public Void visitPackage(PackageTree node, Set<String> p) { return null; }
@Override public R visitPackage(PackageTree pt, P p) { return null; }
@Override public List<T> visitPackage(PackageTree pt, T p) { throw new UnsupportedOperationException("Not supported yet."); }
@Override public PackageTree getPackage() { throw new UnsupportedOperationException("Not supported yet."); }
/** Gets the symbol for a package. */ public static PackageSymbol getSymbol(PackageTree tree) { return ((JCPackageDecl) tree).packge; }