/** 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; }
/** 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; }
@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 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 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 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 visitParam(ParamTree node, Void p) { //XXX: getElement for the param's identifier??? if ( node.getName() != null && positions.getStartPosition(javac.getCompilationUnit(), docComment, node.getName()) <= offset && positions.getEndPosition(javac.getCompilationUnit(), docComment, node.getName()) >= offset) { result[0] = paramElementFor(trees.getElement(tp), node); return null; } return super.visitParam(node, p); } @Override public Void visitSee(SeeTree node, Void p) {
@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 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) {
@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 @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); }
&& span[0] <= offset && span[1] >= offset) { result[0] = trees.getElement(getCurrentPath()); return null;
if (toFind.equals(trees.getElement(getCurrentPath()))) { int[] span = javac.getTreeUtilities().findNameSpan(docComment, node); if (span != null) {