@Nullable static DocTreePath getDocTreePath(VisitorState state) { DocCommentTree docCommentTree = getDocCommentTree(state); if (docCommentTree == null) { return null; } return new DocTreePath(state.getPath(), docCommentTree); }
private void scanJavadoc() { DocCommentTree commentTree = trees.getDocCommentTree(getCurrentPath()); if (commentTree != null) { DocTreePath docTrees = new DocTreePath(getCurrentPath(), commentTree); new DocTreeSymbolScanner(trees, fixes).scan(docTrees, null); } } }
private void scanJavadoc(SymbolSink sink) { if (getCurrentPath() == null) { return; } DocCommentTree commentTree = trees.getDocCommentTree(getCurrentPath()); if (commentTree == null) { return; } docTreeSymbolScanner.scan(new DocTreePath(getCurrentPath(), commentTree), sink); }
@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); }
/**Return the deepest DocTreePath at the given position. * * @param treepath for which the {@code doc} comment was determined * @param doc the documentation comment inside which the search should be performed * @param pos the position to search for * @return the deepest DocTreePath at the given position * @since 0.124 */ public DocTreePath pathFor(TreePath treepath, DocCommentTree doc, int pos) { return pathFor(new DocTreePath(treepath, doc), pos); }
/** * Gets a documentation tree path for a tree node within a compilation unit. * @return null if the node is not found */ public static DocTreePath getPath(TreePath treePath, DocCommentTree doc, DocTree target) { return getPath(new DocTreePath(treePath, doc), target); }
/** * Gets a documentation tree path for a tree node within a compilation unit. * @return null if the node is not found */ public static DocTreePath getPath(TreePath treePath, DocCommentTree doc, DocTree target) { return getPath(new DocTreePath(treePath, doc), target); }
/** * Scan a single node. * The current path is updated for the duration of the scan. */ @Override public R scan(DocTree tree, P p) { if (tree == null) return null; DocTreePath prev = path; path = new DocTreePath(path, tree); try { return tree.accept(this, p); } finally { path = prev; } }
/** * Scan a single node. * The current path is updated for the duration of the scan. */ @Override public R scan(DocTree tree, P p) { if (tree == null) return null; DocTreePath prev = path; path = new DocTreePath(path, tree); try { return tree.accept(this, p); } finally { path = prev; } }
@Nullable static DocTreePath getDocTreePath(VisitorState state) { DocCommentTree docCommentTree = getDocCommentTree(state); if (docCommentTree == null) { return null; } return new DocTreePath(state.getPath(), docCommentTree); }
public DocTreePath resolve(CompilationInfo javac) throws IllegalArgumentException { TreePath p = parent.resolve(javac); if (p == null) { return null; } DocCommentTree docCommentTree = javac.getDocTrees().getDocCommentTree(p); return new DocTreePath(p, docCommentTree); }
private void scanJavadoc(SymbolSink sink) { if (getCurrentPath() == null) { return; } DocCommentTree commentTree = trees.getDocCommentTree(getCurrentPath()); if (commentTree == null) { return; } docTreeSymbolScanner.scan(new DocTreePath(getCurrentPath(), commentTree), sink); }
@Override public Void visitThrows(ThrowsTree tree, Void ignore) { ReferenceTree exName = tree.getExceptionName(); Element ex = env.trees.getElement(new DocTreePath(getCurrentPath(), exName)); if (ex == null) { env.messages.error(REFERENCE, tree, "dc.ref.not.found"); } else if (isThrowable(ex.asType())) { switch (env.currElement.getKind()) { case CONSTRUCTOR: case METHOD: if (isCheckedException(ex.asType())) { ExecutableElement ee = (ExecutableElement) env.currElement; checkThrowsDeclared(exName, ex.asType(), ee.getThrownTypes()); } break; default: env.messages.error(REFERENCE, tree, "dc.invalid.throws"); } } else { env.messages.error(REFERENCE, tree, "dc.invalid.throws"); } warnIfEmpty(tree, tree.getDescription()); return scan(tree.getDescription(), ignore); }
@Override public Void visitValue(ValueTree tree, Void ignore) { ReferenceTree ref = tree.getReference(); if (ref == null || ref.getSignature().isEmpty()) { if (!isConstant(env.currElement)) env.messages.error(REFERENCE, tree, "dc.value.not.allowed.here"); } else { Element e = env.trees.getElement(new DocTreePath(getCurrentPath(), ref)); if (!isConstant(e)) env.messages.error(REFERENCE, tree, "dc.value.not.a.constant"); } markEnclosingTag(Flag.HAS_INLINE_TAG); return super.visitValue(tree, ignore); }
@Override public Void visitThrows(ThrowsTree tree, Void ignore) { ReferenceTree exName = tree.getExceptionName(); Element ex = env.trees.getElement(new DocTreePath(getCurrentPath(), exName)); if (ex == null) { env.messages.error(REFERENCE, tree, "dc.ref.not.found"); } else if (isThrowable(ex.asType())) { switch (env.currElement.getKind()) { case CONSTRUCTOR: case METHOD: if (isCheckedException(ex.asType())) { ExecutableElement ee = (ExecutableElement) env.currElement; checkThrowsDeclared(exName, ex.asType(), ee.getThrownTypes()); } break; default: env.messages.error(REFERENCE, tree, "dc.invalid.throws"); } } else { env.messages.error(REFERENCE, tree, "dc.invalid.throws"); } warnIfEmpty(tree, tree.getDescription()); return scan(tree.getDescription(), ignore); }
@Override public Void visitValue(ValueTree tree, Void ignore) { ReferenceTree ref = tree.getReference(); if (ref == null || ref.getSignature().isEmpty()) { if (!isConstant(env.currElement)) env.messages.error(REFERENCE, tree, "dc.value.not.allowed.here"); } else { Element e = env.trees.getElement(new DocTreePath(getCurrentPath(), ref)); if (!isConstant(e)) env.messages.error(REFERENCE, tree, "dc.value.not.a.constant"); } markEnclosingTag(Flag.HAS_INLINE_TAG); return super.visitValue(tree, ignore); }
@Override @SuppressWarnings("fallthrough") public Void visitParam(ParamTree tree, Void ignore) { boolean typaram = tree.isTypeParameter(); IdentifierTree nameTree = tree.getName(); Element paramElement = nameTree != null ? env.trees.getElement(new DocTreePath(getCurrentPath(), nameTree)) : null; if (paramElement == null) { switch (env.currElement.getKind()) { case CLASS: case INTERFACE: { if (!typaram) { env.messages.error(REFERENCE, tree, "dc.invalid.param"); break; } } case METHOD: case CONSTRUCTOR: { env.messages.error(REFERENCE, nameTree, "dc.param.name.not.found"); break; } default: env.messages.error(REFERENCE, tree, "dc.invalid.param"); break; } } else { foundParams.add(paramElement); } warnIfEmpty(tree, tree.getDescription()); return super.visitParam(tree, ignore); }
@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); }
@Override @SuppressWarnings("fallthrough") public Void visitParam(ParamTree tree, Void ignore) { boolean typaram = tree.isTypeParameter(); IdentifierTree nameTree = tree.getName(); Element paramElement = nameTree != null ? env.trees.getElement(new DocTreePath(getCurrentPath(), nameTree)) : null; if (paramElement == null) { switch (env.currElement.getKind()) { case CLASS: case INTERFACE: { if (!typaram) { env.messages.error(REFERENCE, tree, "dc.invalid.param"); break; } } case METHOD: case CONSTRUCTOR: { env.messages.error(REFERENCE, nameTree, "dc.param.name.not.found"); break; } default: env.messages.error(REFERENCE, tree, "dc.invalid.param"); break; } } else { foundParams.add(paramElement); } warnIfEmpty(tree, tree.getDescription()); return super.visitParam(tree, ignore); }
return super.visitReference(node, p); }.scan(new DocTreePath(getCurrentPath(), dcComment), null);