/** * Returns the class tree that matches the given symbol within the compilation unit, or null if * none was found. */ @Nullable public static ClassTree findClass(ClassSymbol symbol, VisitorState state) { return JavacTrees.instance(state.context).getTree(symbol); }
/** * Returns the method tree that matches the given symbol within the compilation unit, or null if * none was found. */ @Nullable public static MethodTree findMethod(MethodSymbol symbol, VisitorState state) { return JavacTrees.instance(state.context).getTree(symbol); }
@Nullable private static DocCommentTree getDocCommentTree(VisitorState state) { return JavacTrees.instance(state.context).getDocCommentTree(state.getPath()); }
return; ClassTree tree = JavacTrees.instance(context).getTree(taskEvent.getTypeElement()); if (tree == null) { return;
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); }
static int getEndPosition(DocTree docTree, VisitorState state) { DocSourcePositions positions = JavacTrees.instance(state.context).getSourcePositions(); CompilationUnitTree compilationUnitTree = state.getPath().getCompilationUnit(); return (int) positions.getEndPosition(compilationUnitTree, getDocCommentTree(state), docTree); }
/** * 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); }
new TreeSymbolScanner(JavacTrees.instance(state.context), state.getTypes()) .scan( compilationUnitTree,
static SuggestedFix replace(DocTree docTree, String replacement, VisitorState state) { DocSourcePositions positions = JavacTrees.instance(state.context).getSourcePositions(); CompilationUnitTree compilationUnitTree = state.getPath().getCompilationUnit(); int startPos = getStartPosition(docTree, state); int endPos = (int) positions.getEndPosition(compilationUnitTree, getDocCommentTree(state), docTree); return SuggestedFix.replace(startPos, endPos, replacement); }
@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); }
boolean inSdk = true; JavacTrees trees = JavacTrees.instance(state.context); for (AnnotationTree annotationTree : classTree.getModifiers().getAnnotations()) { JCIdent ident = (JCIdent) annotationTree.getAnnotationType();
JavacTrees.instance(state.context).getDocCommentTree(state.getPath()); if (docCommentTree != null) { return NO_MATCH;
(DCDocComment) JavacTrees.instance(state.context).getDocCommentTree(state.getPath()); if (docCommentTree != null) { docCommentTree.accept(
@Override public Void visitParam(ParamTree paramTree, Void unused) { if (paramTree.isTypeParameter() && paramTree.getName().getName().contentEquals(name)) { DocSourcePositions positions = JavacTrees.instance(state.context).getSourcePositions(); CompilationUnitTree compilationUnitTree = state.getPath().getCompilationUnit(); int startPos = (int) positions.getStartPosition( compilationUnitTree, docCommentTree, paramTree.getName()); int endPos = (int) positions.getEndPosition( compilationUnitTree, docCommentTree, paramTree.getName()); fixBuilder.replace(startPos, endPos, typeVarReplacement); } return super.visitParam(paramTree, null); } },
return; TreePath path = JavacTrees.instance(context).getPath(taskEvent.getTypeElement()); if (path == null) { path = new TreePath(taskEvent.getCompilationUnit());
/** * Returns the method tree that matches the given symbol within the compilation unit, or null if * none was found. */ @Nullable public static MethodTree findMethod(MethodSymbol symbol, VisitorState state) { return JavacTrees.instance(state.context).getTree(symbol); }
public static JavacTrees instance(JavaCompiler.CompilationTask task) { if (!(task instanceof BasicJavacTask)) throw new IllegalArgumentException(); return instance(((BasicJavacTask)task).getContext()); }
public static JavacTrees instance(ProcessingEnvironment env) { if (!(env instanceof JavacProcessingEnvironment)) throw new IllegalArgumentException(); return instance(((JavacProcessingEnvironment)env).getContext()); }
/** * Returns the class tree that matches the given symbol within the compilation unit, or null if * none was found. */ @Nullable public static ClassTree findClass(ClassSymbol symbol, VisitorState state) { return JavacTrees.instance(state.context).getTree(symbol); }
public static JavacTrees instance(ProcessingEnvironment env) { if (!(env instanceof JavacProcessingEnvironment)) throw new IllegalArgumentException(); return instance(((JavacProcessingEnvironment)env).getContext()); }