com.sun.source.doctree.ReturnTree Java Examples

The following examples show how to use com.sun.source.doctree.ReturnTree. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Checker.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
@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);
}
 
Example #2
Source File: JavadocConverter.java    From j2objc with Apache License 2.0 5 votes vote down vote up
@Override
public Void visitReturn(ReturnTree node, TagElement tag) {
  tag.setTagKind(TagElement.TagKind.RETURN);
  setPos(node, tag);
  scan(node.getDescription(), tag);
  return null;
}
 
Example #3
Source File: Checker.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
@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);
}
 
Example #4
Source File: Checker.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
@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);
}
 
Example #5
Source File: Checker.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
@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);
}
 
Example #6
Source File: Checker.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Override @DefinedBy(Api.COMPILER_TREE)
public Void visitReturn(ReturnTree tree, Void ignore) {
    if (foundReturn) {
        env.messages.warning(REFERENCE, tree, "dc.exists.return");
    }

    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);
}
 
Example #7
Source File: JavadocFormatter.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Override @DefinedBy(Api.COMPILER_TREE)
public Object visitReturn(ReturnTree node, Object p) {
    reflownTo = result.length();
    try {
        return super.visitReturn(node, p);
    } finally {
        reflow(result, reflownTo, 0, limit);
    }
}
 
Example #8
Source File: Checker.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
@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);
}
 
Example #9
Source File: Analyzer.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
@NbBundle.Messages({"WRONG_RETURN_DESC=@return tag cannot be used in method with void return type.",
                    "WRONG_CONSTRUCTOR_RETURN_DESC=Illegal @return tag.",
                    "DUPLICATE_RETURN_DESC=Duplicate @return tag."})
public Void visitReturn(ReturnTree node, List<ErrorDescription> errors) {
    boolean oldInheritDoc = foundInheritDoc;
    DocTreePath currentDocPath = getCurrentPath();
    DocTreePathHandle dtph = DocTreePathHandle.create(currentDocPath, javac);
    if(dtph == null) {
        return null;
    }
    DocSourcePositions sp = (DocSourcePositions) javac.getTrees().getSourcePositions();
    int start = (int) sp.getStartPosition(javac.getCompilationUnit(), currentDocPath.getDocComment(), node);
    int end = (int) sp.getEndPosition(javac.getCompilationUnit(), currentDocPath.getDocComment(), node);
    if(returnType == null) {
        errors.add(ErrorDescriptionFactory.forSpan(ctx, start, end, WRONG_CONSTRUCTOR_RETURN_DESC(),
                new RemoveTagFix(dtph, "@return").toEditorFix()));
    } else if (returnType.getKind() == TypeKind.VOID) {
        errors.add(ErrorDescriptionFactory.forSpan(ctx, start, end, WRONG_RETURN_DESC(),
                new RemoveTagFix(dtph, "@return").toEditorFix()));
    } else if(returnTypeFound) {
        errors.add(ErrorDescriptionFactory.forSpan(ctx, start, end, DUPLICATE_RETURN_DESC(),
                new RemoveTagFix(dtph, "@return").toEditorFix()));
    } else {
        returnTypeFound = true;
    }
    super.visitReturn(node, errors);
    foundInheritDoc = oldInheritDoc;
    return null;
}
 
Example #10
Source File: VeryPretty.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public Void visitReturn(ReturnTree node, Void p) {
    printTagName(node);
    print(" ");
    for (DocTree docTree : node.getDescription()) {
        doAccept((DCTree)docTree);
    }
    return null;
}
 
Example #11
Source File: ImmutableDocTreeTranslator.java    From netbeans with Apache License 2.0 5 votes vote down vote up
protected final ReturnTree rewriteChildren(ReturnTree tree) {
    ReturnTree value = tree;
    List<? extends DocTree> description = translateDoc(tree.getDescription());
    if (description != tree.getDescription()) {
        value = make.Return(description);
    }
    return value;
}
 
Example #12
Source File: Checker.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
@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);
}
 
Example #13
Source File: Checker.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
@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);
}
 
Example #14
Source File: RefactoringVisitor.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public DocTree visitReturn(ReturnTree node, Element p, Void ignore) {
    return super.visitReturn(node, p);
}
 
Example #15
Source File: RefactoringVisitor.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@Override
public DocTree visitReturn(ReturnTree node, Element p) {
    return instance.visitReturn(node, p);
}
 
Example #16
Source File: RefactoringVisitor.java    From netbeans with Apache License 2.0 4 votes vote down vote up
/**
 * @since 1.47
 */
@Override
public DocTree visitReturn(ReturnTree node, Element p) {
    return docScanner.visitReturn(node, p, null);
}
 
Example #17
Source File: ImmutableDocTreeTranslator.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@Override
public DocTree visitReturn(ReturnTree tree, Object p) {
    return rewriteChildren(tree);
}
 
Example #18
Source File: DumpJavaDoc.java    From cxf with Apache License 2.0 4 votes vote down vote up
@Override
public boolean run(DocletEnvironment docEnv) {
    final Elements utils = docEnv.getElementUtils();
    final DocTrees docTrees = docEnv.getDocTrees();
    
    try (OutputStream os = Files.newOutputStream(Paths.get(dumpFileName))) {
        final Properties javaDocMap = new Properties();
        for (Element element : docEnv.getIncludedElements()) {
            if (element.getKind() == ElementKind.CLASS) {
                final TypeElement classDoc = (TypeElement) element;
                final DocCommentTree classCommentTree = docTrees.getDocCommentTree(classDoc);
                
                if (classCommentTree != null) {
                    javaDocMap.put(classDoc.toString(), getAllComments(classCommentTree.getFullBody()));
                }
                
                for (Element member: classDoc.getEnclosedElements()) {
                    // Skip all non-public methods
                    if (!member.getModifiers().contains(Modifier.PUBLIC)) {
                        continue;
                    }
                    
                    if (member.getKind() == ElementKind.METHOD) {
                        final ExecutableElement method = (ExecutableElement) member;
                        final DocCommentTree methodCommentTree = docTrees.getDocCommentTree(method);
                        final String qualifiedName = utils.getBinaryName(classDoc) + "." + method.getSimpleName();
                        
                        if (methodCommentTree == null) {
                            javaDocMap.put(qualifiedName, "");
                        } else  {
                            javaDocMap.put(qualifiedName, getAllComments(methodCommentTree.getFullBody()));
                            for (DocTree tree: methodCommentTree.getBlockTags()) {
                                if (tree.getKind() == DocTree.Kind.RETURN) {
                                    final ReturnTree returnTree = (ReturnTree) tree;
                                    javaDocMap.put(qualifiedName + ".returnCommentTag", 
                                        getAllComments(returnTree.getDescription()));
                                } else if (tree.getKind() == DocTree.Kind.PARAM) {
                                    final ParamTree paramTree = (ParamTree) tree;
                                    final int index = getParamIndex(method, paramTree);
                                    if (index >= 0) {
                                        javaDocMap.put(qualifiedName + ".paramCommentTag." + index, 
                                            getAllComments(paramTree.getDescription()));
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        
        javaDocMap.store(os, "");
        os.flush();
    } catch (final IOException ex) {
        reporter.print(Diagnostic.Kind.ERROR, ex.getMessage());
    }
    
    return true;
}
 
Example #19
Source File: DocTreeFactory.java    From openjdk-jdk9 with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Create a new {@code ReturnTree} object, to represent a {@code @return } tag.
 * @param description the description of the return value of a method
 * @return a {@code ReturnTree} object
 */
ReturnTree newReturnTree(List<? extends DocTree> description);
 
Example #20
Source File: DocTreeFactory.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 2 votes vote down vote up
/**
 * Create a new {@code ReturnTree} object, to represent a {@code @return } tag.
 * @param description the description of the return value of a method
 * @return a {@code ReturnTree} object
 */
ReturnTree newReturnTree(List<? extends DocTree> description);