@Override public Void visitEndElement(EndElementTree endElementTree, Void aVoid) { return super.visitEndElement(endElementTree, aVoid); }
@Override public Void visitParam(ParamTree paramTree, Void unused) { ImmutableSet<String> paramNames = paramTree.isTypeParameter() ? typeParameters : parameters; if (!paramNames.contains(paramTree.getName().toString())) { ImmutableSet<String> documentedParamNames = paramTree.isTypeParameter() ? documentedTypeParameters : documentedParameters; Set<String> undocumentedParameters = Sets.difference(paramNames, documentedParamNames); Optional<String> bestMatch = getBestMatch(paramTree.getName().toString(), undocumentedParameters); String message = String.format("Parameter name `%s` is unknown.", paramTree.getName()); state.reportMatch( bestMatch .map( bm -> buildDescription(diagnosticPosition(getCurrentPath(), state)) .setMessage(message + String.format(" Did you mean %s?", bm)) .addFix(replace(paramTree.getName(), bm, state)) .build()) .orElse( buildDescription(diagnosticPosition(getCurrentPath(), state)) .setMessage(message) .addFix(replace(paramTree, "", state)) .build())); } return super.visitParam(paramTree, null); } }
@Override public Void visitStartElement(StartElementTree startElementTree, Void unused) { if (CODE_TAGS.contains(startElementTree.getName().toString())) { codeTagNestedDepth++; } return super.visitStartElement(startElementTree, null); }
@Override public Void visitReference(ReferenceTree node, Void p) { new TreePathScanner<Void, Void>() { @Override public Void visitIdentifier(IdentifierTree node, Void p) { Element el = trees.getElement(getCurrentPath()); if (el != null && (el.getKind().isClass() || el.getKind().isInterface())) { result.add((TypeElement) el); } return super.visitIdentifier(node, p); } public Void scan(Iterable<? extends TreePath> toAnalyze, Void p) { for (TreePath tp : toAnalyze) { scan(tp, p); } return null; } }.scan(referenceEmbeddedSourceNodes(javac, getCurrentPath()), null); return super.visitReference(node, p); } @Override public Void visitSee(SeeTree node, Void p) {
@Override public Void visitLiteral(LiteralTree literalTree, Void unused) { excludeFromCodeFixes(literalTree); return super.visitLiteral(literalTree, null); }
@Override public Void visitReturn(ReturnTree returnTree, Void unused) { if (isSameType(getType(methodTree.getReturnType()), state.getSymtab().voidType, state)) { state.reportMatch( buildDescription(diagnosticPosition(getCurrentPath(), state)) .addFix(Utils.replace(returnTree, "", state)) .build()); } return super.visitReturn(returnTree, null); } }
.build()); fixedTags.add(unknownInlineTagTree); return super.visitUnknownInlineTag(unknownInlineTagTree, null); .build()); fixedTags.add(unknownInlineTagTree); return super.visitUnknownInlineTag(unknownInlineTagTree, null); return super.visitUnknownInlineTag(unknownInlineTagTree, null);
JavadocTag tag = blockTag(tagName); if (JavadocTag.KNOWN_OTHER_TAGS.contains(tag)) { return super.visitUnknownBlockTag(unknownBlockTagTree, null); .build()); fixedTags.add(unknownBlockTagTree); return super.visitUnknownBlockTag(unknownBlockTagTree, null); .build()); fixedTags.add(unknownBlockTagTree); return super.visitUnknownBlockTag(unknownBlockTagTree, null); .build()); fixedTags.add(unknownBlockTagTree); return super.visitUnknownBlockTag(unknownBlockTagTree, null); return super.visitUnknownBlockTag(unknownBlockTagTree, null);
@Override public Void visitLink(LinkTree linkTree, Void unused) { excludeFromCodeFixes(linkTree); return super.visitLink(linkTree, null); }
return super.visitInheritDoc(inheritDocTree, null);
@Override public Void visitReference(ReferenceTree tree, Void ignore) { String sig = tree.getSignature(); if (sig.contains("<") || sig.contains(">")) env.messages.error(REFERENCE, tree, "dc.type.arg.not.allowed"); Element e = env.trees.getElement(getCurrentPath()); if (e == null) env.messages.error(REFERENCE, tree, "dc.ref.not.found"); return super.visitReference(tree, ignore); }
@Override public Void visitLiteral(LiteralTree node, Void unused) { Matcher matcher = HTML_ENTITY.matcher(node.getBody().getBody()); if (matcher.find()) { state.reportMatch(buildDescription(diagnosticPosition(getCurrentPath(), state)).build()); } return super.visitLiteral(node, null); } }
@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); }
@Override public Void visitUnknownInlineTag(UnknownInlineTagTree tree, Void ignore) { checkUnknownTag(tree, tree.getTagName()); return super.visitUnknownInlineTag(tree, ignore); }
@Override public Void visitUnknownBlockTag(UnknownBlockTagTree tree, Void ignore) { checkUnknownTag(tree, tree.getTagName()); return super.visitUnknownBlockTag(tree, ignore); }
@Override public Void visitLink(LinkTree tree, Void ignore) { markEnclosingTag(Flag.HAS_INLINE_TAG); // simulate inline context on tag stack HtmlTag t = (tree.getKind() == DocTree.Kind.LINK) ? HtmlTag.CODE : HtmlTag.SPAN; tagStack.push(new TagStackItem(tree, t)); try { return super.visitLink(tree, ignore); } finally { tagStack.pop(); } }
@Override public Void visitInheritDoc(InheritDocTree tree, Void ignore) { markEnclosingTag(Flag.HAS_INLINE_TAG); // TODO: verify on overridden method foundInheritDoc = true; return super.visitInheritDoc(tree, ignore); }
@Override public Void visitParam(ParamTree paramTree, Void unused) { ImmutableSet<String> paramNames = paramTree.isTypeParameter() ? typeParameters : parameters; if (!paramNames.contains(paramTree.getName().toString())) { ImmutableSet<String> documentedParamNames = paramTree.isTypeParameter() ? documentedTypeParameters : documentedParameters; Set<String> undocumentedParameters = Sets.difference(paramNames, documentedParamNames); Optional<String> bestMatch = getBestMatch(paramTree.getName().toString(), undocumentedParameters); String message = String.format("Parameter name `%s` is unknown.", paramTree.getName().toString()); state.reportMatch( bestMatch .map( bm -> buildDescription(diagnosticPosition(getCurrentPath(), state)) .setMessage(message + String.format(" Did you mean %s?", bm)) .addFix(replace(paramTree.getName(), bm, state)) .build()) .orElse( buildDescription(diagnosticPosition(getCurrentPath(), state)) .setMessage(message) .addFix(replace(paramTree, "", state)) .build())); } return super.visitParam(paramTree, null); } }
@Override public Void visitStartElement(StartElementTree startTree, Void unused) { if (PRE_TAGS.contains(startTree.getName().toString())) { startPosStack.offerLast(getEndPosition(startTree, state)); containsAnotherTag = false; } return super.visitStartElement(startTree, null); }
@Override public Void visitEndElement(EndElementTree endElementTree, Void unused) { if (CODE_TAGS.contains(endElementTree.getName().toString())) { codeTagNestedDepth--; } return super.visitEndElement(endElementTree, null); }