static int getStartPosition(DocTree docTree, VisitorState state) { DocSourcePositions positions = JavacTrees.instance(state.context).getSourcePositions(); CompilationUnitTree compilationUnitTree = state.getPath().getCompilationUnit(); return (int) positions.getStartPosition(compilationUnitTree, getDocCommentTree(state), docTree); }
@Nullable private static DocCommentTree getDocCommentTree(VisitorState state) { return JavacTrees.instance(state.context).getDocCommentTree(state.getPath()); }
new TreeSymbolScanner(JavacTrees.instance(state.context), state.getTypes()) .scan( compilationUnitTree,
/** * Fully qualifies a javadoc reference, e.g. for replacing {@code {@link List}} with {@code {@link * java.util.List}} * * @param fix the fix builder to add to * @param docPath the path to a {@link DCTree.DCReference} element */ public static void qualifyDocReference( SuggestedFix.Builder fix, DocTreePath docPath, VisitorState state) { DocTree leaf = docPath.getLeaf(); checkArgument( leaf.getKind() == DocTree.Kind.REFERENCE, "expected a path to a reference, got %s instead", leaf.getKind()); DCTree.DCReference reference = (DCTree.DCReference) leaf; Symbol sym = (Symbol) JavacTrees.instance(state.context).getElement(docPath); if (sym == null) { return; } String refString = reference.toString(); String qualifiedName; int idx = refString.indexOf('#'); if (idx >= 0) { qualifiedName = sym.owner.getQualifiedName() + refString.substring(idx, refString.length()); } else { qualifiedName = sym.getQualifiedName().toString(); } replaceDocTree(fix, docPath, qualifiedName); }
public JCMethodDecl getTree(ExecutableElement method) { return (JCMethodDecl) getTree((Element) method); }
public TreePath getPath(Element e, AnnotationMirror a) { return getPath(e, a, null); }
private Symbol attributeDocReference(TreePath path, DCReference ref) { Env<AttrContext> env = getAttrContext(path); ? findConstructor(sym, paramTypes) : findMethod(sym, memberName, paramTypes); if (paramTypes != null) { VarSymbol vsym = (ref.paramTypes != null) ? null : findField(sym, memberName);
Copier copier = createCopier(treeMaker.forToplevel(unit)); Assert.check(method.body == tree); method.body = copier.copy((JCBlock)tree, (JCTree) path.getLeaf()); env = attribStatToTree(method.body, env, copier.leafCopy); } finally { method.body = (JCBlock) tree; env = attribStatToTree(body, env, copier.leafCopy); env = memberEnter.getInitEnv(field, env); JCExpression expr = copier.copy((JCExpression)tree, (JCTree) path.getLeaf()); env = attribExprToTree(expr, env, copier.leafCopy); return env;
env = memberEnter.getMethodEnv(method, env); JCTree body = copier.copy((JCTree)tree, (JCTree) path.getLeaf()); env = attribStatToTree(body, env, copier.leafCopy); return env; env = memberEnter.getInitEnv(field, env); JCExpression expr = copier.copy((JCExpression)tree, (JCTree) path.getLeaf()); env = attribExprToTree(expr, env, copier.leafCopy); return env;
@Override public Void visitReference(ReferenceTree referenceTree, Void sink) { // do this first, it attributes the referenceTree as a side-effect trees.getElement(getCurrentPath()); com.sun.source.util.TreeScanner<Void, Void> nonRecursiveScanner = new com.sun.source.util.TreeScanner<Void, Void>() { @Override public Void visitIdentifier(IdentifierTree tree, Void sink) { Symbol sym = ASTHelpers.getSymbol(tree); if (sym != null) { System.out.println("sym = " + sym); } return null; } }; DCReference reference = (DCReference) referenceTree; nonRecursiveScanner.scan(reference.qualifierExpression, sink); nonRecursiveScanner.scan(reference.paramTypes, sink); return null; } }
public static JavacTrees instance(Context context) { JavacTrees instance = context.get(JavacTrees.class); if (instance == null) instance = new JavacTrees(context); return instance; }
public JavacScope getScope(TreePath path) { return new JavacScope(getAttrContext(path)); }
boolean inSdk = true; JavacTrees trees = JavacTrees.instance(state.context); for (AnnotationTree annotationTree : classTree.getModifiers().getAnnotations()) { JCIdent ident = (JCIdent) annotationTree.getAnnotationType();
@Override public Void visitThrows(ThrowsTree throwsTree, Void unused) { ReferenceTree exName = throwsTree.getExceptionName(); Type type = (Type) JavacTrees.instance(state.context) .getElement(new DocTreePath(getCurrentPath(), exName)) .asType(); if (type != null && isCheckedException(type)) { if (methodTree.getThrows().stream().noneMatch(t -> isSubtype(type, getType(t), state))) { state.reportMatch( buildDescription(diagnosticPosition(getCurrentPath(), state)) .addFix(Utils.replace(throwsTree, "", state)) .build()); } } return super.visitThrows(throwsTree, null); }
(DCDocComment) JavacTrees.instance(state.context).getDocCommentTree(state.getPath()); if (docCommentTree != null) { docCommentTree.accept(
public JCTree getTree(Element e, AnnotationMirror a) { return getTree(e, a, null); }
public TreePath getPath(Element e) { return getPath(e, null, null); }
private Symbol attributeDocReference(TreePath path, DCReference ref) { Env<AttrContext> env = getAttrContext(path); ? findConstructor(sym, paramTypes) : findMethod(sym, memberName, paramTypes); if (paramTypes != null) { VarSymbol vsym = (ref.paramTypes != null) ? null : findField(sym, memberName);