public void scan(TreePath p) { DocCommentTree dc = env.trees.getDocCommentTree(p); checker.scan(dc, p); }
/**Return the deepest DocTreePath at the given position. * * @param path where the search should start * @param pos the position to search for * @return the deepest DocTreePath at the given position * @since 0.124 */ public DocTreePath pathFor(DocTreePath path, int pos) { return pathFor(path, pos, info.getDocTrees().getSourcePositions()); }
@Override public void init(ProcessingEnvironment env) { docTrees = DocTrees.instance(env); processingEnv = env; }
private void appendComment( Tree node, StringBuilder out ) { if( _docTrees == null ) { return; } TreePath path = _docTrees.getPath( _compilationUnit, node ); if( path != null ) { DocCommentTree docTree = _docTrees.getDocCommentTree( path ); String docComment = _docTrees.getDocComment( path ); if( docComment != null ) { out.append( "/**\n" ); for( String line : docComment.split( "\\r?\\n" ) ) { appendIndent( out ); out.append( " *" ); out.append( line ); out.append( "\n" ); } appendIndent( out ); out.append( " */\n" ); appendIndent( out ); } } }
final DocCommentTree docComment = javac.getDocTrees().getDocCommentTree(tp); final DocSourcePositions positions = trees.getSourcePositions(); final Element[] result = new Element[1];
/** Set the current declaration and its doc comment. */ void setCurrent(TreePath path, DocCommentTree comment) { currPath = path; currDocComment = comment; currElement = trees.getElement(currPath); currOverriddenMethods = ((JavacTypes) types).getOverriddenMethods(currElement); AccessKind ak = AccessKind.PUBLIC; for (TreePath p = path; p != null; p = p.getParentPath()) { Element e = trees.getElement(p); if (e != null && e.getKind() != ElementKind.PACKAGE) { ak = min(ak, AccessKind.of(e.getModifiers())); } } currAccess = ak; }
TreePath pkgPath = docTrees.getPath(pkgElt); DocCommentTree docTree = docTrees.getDocCommentTree(pkgPath); DocTreeVisitor<Void, Void> visitor = new DocTreeScanner<Void, Void>() {
@Override public Void visitParam(ParamTree node, Void p) { if ( node.getName() != null && toFind.equals(paramElementFor(trees.getElement(forElement), node))) { handleUsage((int) trees.getSourcePositions().getStartPosition(javac.getCompilationUnit(), docComment, node.getName())); return null; } return super.visitParam(node, p); } @Override public Void visitSee(SeeTree node, Void p) {
public String renderSource(TypeElement elt, String source) { TreePath path = docTrees.getPath(elt); ClassTree classTree = (ClassTree) path.getLeaf(); return renderSource(path, Collections.singletonList(classTree), source); }
protected void report(Group group, Diagnostic.Kind dkind, Tree tree, String code, Object... args) { if (options.isEnabled(group, env.currAccess)) { String msg = localize(code, args); env.trees.printMessage(dkind, msg, tree, env.currPath.getCompilationUnit()); stats.record(group, dkind, code); } }
/** * Gets a DocTrees object for a given ProcessingEnvironment. * @param env the processing environment for which to get the Trees object * @throws IllegalArgumentException if the env does not support the Trees API. */ public static DocTrees instance(ProcessingEnvironment env) { if (!env.getClass().getName().equals("com.sun.tools.javac.processing.JavacProcessingEnvironment")) throw new IllegalArgumentException(); return (DocTrees) getJavacTrees(ProcessingEnvironment.class, env); }
final DocCommentTree docComment = javac.getDocTrees().getDocCommentTree(tp); final DocSourcePositions positions = trees.getSourcePositions(); final Token[] result = new Token[1];
/** Set the current declaration and its doc comment. */ void setCurrent(TreePath path, DocCommentTree comment) { currPath = path; currDocComment = comment; currElement = trees.getElement(currPath); currOverriddenMethods = ((JavacTypes) types).getOverriddenMethods(currElement); AccessKind ak = AccessKind.PUBLIC; for (TreePath p = path; p != null; p = p.getParentPath()) { Element e = trees.getElement(p); if (e != null && e.getKind() != ElementKind.PACKAGE) { ak = min(ak, AccessKind.of(e.getModifiers())); } } currAccess = ak; }
/** * Returns the file that contains the current tag, or {@code null} if the method * can not determine the file. * * @return file containing the current tag, or {@code null}. */ protected final Path getCurrentFile() { if (trees != null && element != null) { final TreePath path = trees.getPath(element); if (path != null) { // Following methods do not document 'null' as a possible return value. return Paths.get(path.getCompilationUnit().getSourceFile().toUri()); } } return null; }
protected void report(Group group, Diagnostic.Kind dkind, DocTree tree, String code, Object... args) { if (options.isEnabled(group, env.currAccess)) { String msg = (code == null) ? (String) args[0] : localize(code, args); env.trees.printMessage(dkind, msg, tree, env.currDocComment, env.currPath.getCompilationUnit()); stats.record(group, dkind, code); } }
/** * Gets a DocTrees object for a given ProcessingEnvironment. * @param env the processing environment for which to get the Trees object * @throws IllegalArgumentException if the env does not support the Trees API. */ public static DocTrees instance(ProcessingEnvironment env) { if (!env.getClass().getName().equals("com.sun.tools.javac.processing.JavacProcessingEnvironment")) throw new IllegalArgumentException(); return (DocTrees) getJavacTrees(ProcessingEnvironment.class, env); }
public void scan(TreePath p) { DocCommentTree dc = env.trees.getDocCommentTree(p); checker.scan(dc, p); }
public Helper(ProcessingEnvironment env) { typeUtils = env.getTypeUtils(); elementUtils = env.getElementUtils(); docTrees = DocTrees.instance(env); }
private void copyContent(DocTree node) { int from = (int) docTrees.getSourcePositions().getStartPosition(pkgPath.getCompilationUnit(), docTree, node); int to = (int) docTrees.getSourcePositions().getEndPosition(pkgPath.getCompilationUnit(), docTree, node); writer.append(pkgSource, from, to); }
@Override public Void visitReturn(ReturnTree tree, Void ignore) { Element e = env.trees.getElement(env.currPath); if (e.getKind() != ElementKind.METHOD || ((ExecutableElement) e).getReturnType().getKind() == TypeKind.VOID) env.messages.error(REFERENCE, tree, "dc.invalid.return"); foundReturn = true; warnIfEmpty(tree, tree.getDescription()); return super.visitReturn(tree, ignore); }