/** * Gets a {@link DiagnosticPosition} for the {@link DocTree} pointed to by {@code path}, attached * to the {@link Tree} which it documents. */ static DiagnosticPosition diagnosticPosition(DocTreePath path, VisitorState state) { int startPosition = getStartPosition(path.getLeaf(), state); Tree tree = path.getTreePath().getLeaf(); return getDiagnosticPosition(startPosition, tree); }
private void handleDanglingParams(TextTree node) { Matcher matcher = PARAM_MATCHER.matcher(node.getBody()); Comment comment = ((DCDocComment) getCurrentPath().getDocComment()).comment; while (matcher.find()) { int startPos = comment.getSourcePos(((DCText) node).pos + matcher.start()); int endPos = comment.getSourcePos(((DCText) node).pos + matcher.end()); String paramName = matcher.group(1); SuggestedFix fix = SuggestedFix.replace(startPos, endPos, String.format("{@code %s}", paramName)); state.reportMatch( buildDescription( getDiagnosticPosition(startPos, getCurrentPath().getTreePath().getLeaf())) .addFix(fix) .build()); } }
}.visit(getCurrentPath().getTreePath().getLeaf(), null); return super.visitInheritDoc(inheritDocTree, null);
private void handleMalformedTags(TextTree node) { Matcher matcher = misplacedCurly.matcher(node.getBody()); Comment comment = ((DCDocComment) getCurrentPath().getDocComment()).comment; while (matcher.find()) { int beforeAt = comment.getSourcePos(((DCText) node).pos + matcher.start()); int startOfCurly = comment.getSourcePos(((DCText) node).pos + matcher.end(1)); SuggestedFix fix = SuggestedFix.builder() .replace(beforeAt, beforeAt, "{") .replace(startOfCurly, startOfCurly + 1, " ") .build(); state.reportMatch( buildDescription( getDiagnosticPosition(beforeAt, getCurrentPath().getTreePath().getLeaf())) .addFix(fix) .build()); } }
return NO_MATCH; if (!requiresJavadoc(docTreePath.getTreePath().getLeaf(), state)) { return Description.NO_MATCH; return NO_MATCH; Symbol symbol = getSymbol(docTreePath.getTreePath().getLeaf()); if (symbol == null) { return NO_MATCH;
@Override public JCTree getTree() { return (JCTree) path.getTreePath().getLeaf(); }
private static Iterable<? extends TreePath> referenceEmbeddedSourceNodes(CompilationInfo info, DocTreePath ref) { List<TreePath> result = new ArrayList<TreePath>(); if (info.getTreeUtilities().getReferenceClass(ref) != null) { result.add(new TreePath(ref.getTreePath(), info.getTreeUtilities().getReferenceClass(ref))); } List<? extends Tree> params = info.getTreeUtilities().getReferenceParameters(ref); if (params != null) { for (Tree et : params) { result.add(new TreePath(ref.getTreePath(), et)); } } return result; }
@Override public Element getElement(DocTreePath path) { DocTree forTree = path.getLeaf(); if (forTree instanceof DCReference) return attributeDocReference(path.getTreePath(), ((DCReference) forTree)); if (forTree instanceof DCIdentifier) { if (path.getParentPath().getLeaf() instanceof DCParam) { return attributeParamIdentifier(path.getTreePath(), (DCParam) path.getParentPath().getLeaf()); } } return null; }
@Override public Element getElement(DocTreePath path) { DocTree forTree = path.getLeaf(); if (forTree instanceof DCReference) return attributeDocReference(path.getTreePath(), ((DCReference) forTree)); if (forTree instanceof DCIdentifier) { if (path.getParentPath().getLeaf() instanceof DCParam) { return attributeParamIdentifier(path.getTreePath(), (DCParam) path.getParentPath().getLeaf()); } } return null; }
/**Find the type (the part before {@code #}) that is being referenced by the given {@link ReferenceTree}. * * @param path the leaf must be {@link ReferenceTree} * @return the referred type, or {@code null} if none. * @since 0.124 */ public @CheckForNull ExpressionTree getReferenceClass(@NonNull DocTreePath path) { TreePath tp = path.getTreePath(); DCReference ref = (DCReference) path.getLeaf(); ((JavacTrees) this.info.getTrees()).ensureDocReferenceAttributed(tp, ref); return (ExpressionTree) ref.qualifierExpression; }
/**Find the parameters that are specified in the given {@link ReferenceTree}. * * @param path the leaf must be {@link ReferenceTree} * @return the parameters for the referred method, or {@code null} if none. * @since 0.124 */ public @CheckForNull List<? extends Tree> getReferenceParameters(@NonNull DocTreePath path) { TreePath tp = path.getTreePath(); DCReference ref = (DCReference) path.getLeaf(); ((JavacTrees) this.info.getTrees()).ensureDocReferenceAttributed(tp, ref); return ref.paramTypes; }
new PathFinder(pos, sourcePositions).scan(path, path.getTreePath()); } catch (Result result) { path = result.path;
/** * Factory method for creating {@link DocTreePathHandle}. * * @param docTreePath for which the {@link DocTreePathHandle} should be created. * @param javac * @return a new {@link DocTreePathHandle} * @throws java.lang.IllegalArgumentException if arguments are not supported */ public static DocTreePathHandle create(final DocTreePath docTreePath, CompilationInfo javac) throws IllegalArgumentException { Parameters.notNull("docTreePath", docTreePath); Parameters.notNull("javac", javac); TreePathHandle treePathHandle = TreePathHandle.create(docTreePath.getTreePath(), javac); if(treePathHandle.getFileObject() == null) { return null; } int position = (int) ((DCTree) docTreePath.getLeaf()).getSourcePosition((DCTree.DCDocComment)docTreePath.getDocComment()); if (position == (-1)) { DocTree docTree = docTreePath.getLeaf(); if(docTree == docTreePath.getDocComment()) { return new DocTreePathHandle(new DocCommentDelegate(treePathHandle)); } int index = listChildren(docTreePath.getParentPath().getLeaf()).indexOf(docTree); assert index != (-1); return new DocTreePathHandle(new CountingDelegate(treePathHandle, index, docTreePath.getLeaf().getKind())); } Position pos = createPositionRef(treePathHandle.getFileObject(), position, Bias.Forward); return new DocTreePathHandle(new DocTreeDelegate(pos, new DocTreeDelegate.KindPath(docTreePath), treePathHandle)); }