com.sun.source.util.DocTreePath Java Examples

The following examples show how to use com.sun.source.util.DocTreePath. 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: RenameTransformer.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
public DocTree visitReference(ReferenceTree node, Element elementToFind) {
    DocTreePath currentDocPath = getCurrentDocPath();
    DocTrees trees = workingCopy.getDocTrees();
    Element el = trees.getElement(currentDocPath);
    ExpressionTree classReference = workingCopy.getTreeUtilities().getReferenceClass(currentDocPath);
    if((el == null || !(el.equals(elementToFind) || isMethodMatch(el))) && classReference != null) {
        el = trees.getElement(new TreePath(getCurrentPath(), classReference));
    }
    if (el != null && (el.equals(elementToFind) || isMethodMatch(el))) {
        ReferenceTree newRef;
        Name memberName = workingCopy.getTreeUtilities().getReferenceName(currentDocPath);
        List<? extends Tree> methodParameters = workingCopy.getTreeUtilities().getReferenceParameters(currentDocPath);
        if(el.getKind().isClass() || el.getKind().isInterface()) {
            newRef = make.Reference(make.setLabel(classReference, newName), memberName, methodParameters);
        } else {
            newRef = make.Reference(classReference, newName, methodParameters);
        }
        rewrite(currentDocPath.getTreePath().getLeaf(), node, newRef);
    }
    return super.visitReference(node, elementToFind);
}
 
Example #2
Source File: ReferenceTest.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
void checkReference(ReferenceTree tree, List<? extends DocTree> label) {
    String sig = tree.getSignature();

    Element found = trees.getElement(new DocTreePath(getCurrentPath(), tree));
    if (found == null) {
        System.err.println(sig + " NOT FOUND");
    } else {
        System.err.println(sig + " found " + found.getKind() + " " + found);
    }

    String expect = "UNKNOWN";
    if (label.size() > 0 && label.get(0) instanceof TextTree)
        expect = ((TextTree) label.get(0)).getBody();

    if (!expect.equalsIgnoreCase(found == null ? "bad" : found.getKind().name())) {
        error(tree, "Unexpected value found: " + found +", expected: " + expect);
    }
}
 
Example #3
Source File: Checker.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
@Override @DefinedBy(Api.COMPILER_TREE)
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);
}
 
Example #4
Source File: Checker.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
@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);
}
 
Example #5
Source File: JavadocImports.java    From netbeans with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example #6
Source File: RemoveTagFix.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
protected void performRewrite(TransformationContext ctx) throws Exception {
    WorkingCopy javac = ctx.getWorkingCopy();
    DocTreePath path = dtph.resolve(javac);
    if(path == null) {
        LOG.log(Level.WARNING, "Cannot resolve DocTreePathHandle: {0}", dtph);
        return;
    }
    DocCommentTree docComment = path.getDocComment();
    TreeMaker make = javac.getTreeMaker();
    final List<DocTree> blockTags = new LinkedList<DocTree>();
    for (DocTree docTree : docComment.getBlockTags()) {
        if (docTree != path.getLeaf()) {
            blockTags.add(docTree);
        }
    }
    DocCommentTree newDoc = make.DocComment(docComment.getFirstSentence(), docComment.getBody(), blockTags);
    Tree tree = ctx.getPath().getLeaf();
    javac.rewrite(tree, docComment, newDoc);
}
 
Example #7
Source File: Analyzer.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private void checkParamsDocumented(List<? extends Element> list, List<? extends Tree> trees, DocTreePath docTreePath, Set<String> inheritedParams, List<ErrorDescription> errors) {
    if(foundInheritDoc) return;
    for (int i = 0; i < list.size() && i < trees.size(); i++) {
        if(ctx.isCanceled()) { return; }
        Element e = list.get(i);
        Tree t = trees.get(i);
        if (!foundParams.contains(e) && !inheritedParams.contains(e.getSimpleName().toString())) {
            boolean isTypeParam = e.getKind() == ElementKind.TYPE_PARAMETER;
            CharSequence paramName = (isTypeParam)
                    ? "<" + e.getSimpleName() + ">"
                    : e.getSimpleName();
            DocTreePathHandle dtph = DocTreePathHandle.create(docTreePath, javac);
            if (dtph != null) {
                errors.add(ErrorDescriptionFactory.forTree(ctx, t, MISSING_PARAM_DESC(paramName), AddTagFix.createAddParamTagFix(dtph, e.getSimpleName().toString(), isTypeParam, i).toEditorFix()));
            }
        }
    }
}
 
Example #8
Source File: ReferenceTest.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
void checkReference(ReferenceTree tree, List<? extends DocTree> label) {
    String sig = tree.getSignature();

    Element found = trees.getElement(new DocTreePath(getCurrentPath(), tree));
    if (found == null) {
        System.err.println(sig + " NOT FOUND");
    } else {
        System.err.println(sig + " found " + found.getKind() + " " + found);
    }

    String expect = "UNKNOWN";
    if (label.size() > 0 && label.get(0) instanceof TextTree)
        expect = ((TextTree) label.get(0)).getBody();

    if (!expect.equalsIgnoreCase(found == null ? "bad" : found.getKind().name())) {
        error(tree, "Unexpected value found: " + found +", expected: " + expect);
    }
}
 
Example #9
Source File: ReferenceTest.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
void checkReference(ReferenceTree tree, List<? extends DocTree> label) {
    String sig = tree.getSignature();

    Element found = trees.getElement(new DocTreePath(getCurrentPath(), tree));
    if (found == null) {
        System.err.println(sig + " NOT FOUND");
    } else {
        System.err.println(sig + " found " + found.getKind() + " " + found);
    }

    String expect = "UNKNOWN";
    if (label.size() > 0 && label.get(0) instanceof TextTree)
        expect = ((TextTree) label.get(0)).getBody();

    if (!expect.equalsIgnoreCase(found == null ? "bad" : found.getKind().name())) {
        error(tree, "Unexpected value found: " + found +", expected: " + expect);
    }
}
 
Example #10
Source File: ReferenceTest.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
void checkReference(ReferenceTree tree, List<? extends DocTree> label) {
    String sig = tree.getSignature();

    Element found = trees.getElement(new DocTreePath(getCurrentPath(), tree));
    if (found == null) {
        System.err.println(sig + " NOT FOUND");
    } else {
        System.err.println(sig + " found " + found.getKind() + " " + found);
    }

    String expect = "UNKNOWN";
    if (label.size() > 0 && label.get(0) instanceof TextTree)
        expect = ((TextTree) label.get(0)).getBody();

    if (!expect.equalsIgnoreCase(found == null ? "bad" : found.getKind().name())) {
        error(tree, "Unexpected value found: " + found +", expected: " + expect);
    }
}
 
Example #11
Source File: Checker.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
@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);
}
 
Example #12
Source File: Checker.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
@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);
}
 
Example #13
Source File: DocTreePathHandle.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/**
 * 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));
}
 
Example #14
Source File: JavadocCompletionQuery.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private void completeParamName(DocTreePath tag, String prefix, int substitutionOffset, JavadocContext jdctx) {
    if (EXECUTABLE.contains(jdctx.commentFor.getKind())) {
        List<? extends DocTree> blockTags = jdctx.comment.getBlockTags();
        ExecutableElement method = (ExecutableElement) jdctx.commentFor;
        for (VariableElement param : method.getParameters()) {
            String name = param.getSimpleName().toString();

            if (!containsParam(blockTags, name) && name.startsWith(prefix)) {
                items.add(JavadocCompletionItem.createNameItem(name, substitutionOffset));
            }
        }
        
        completeTypeVarName(jdctx.commentFor, prefix, substitutionOffset);
    } else if (jdctx.commentFor.getKind().isClass() || jdctx.commentFor.getKind().isInterface()) {
        completeTypeVarName(jdctx.commentFor, prefix, substitutionOffset);
    }
}
 
Example #15
Source File: JavadocCompletionQuery.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private void insideTag(DocTreePath tag, JavadocContext jdctx) {
    switch (tag.getLeaf().getKind()) {
        case IDENTIFIER:
            if (tag.getParentPath() == null || tag.getParentPath().getLeaf().getKind() != Kind.PARAM)
                break;
            tag = tag.getParentPath();
            //intentional fall-through:
        case PARAM:
            insideParamTag(tag, jdctx);
            break;
        case SEE: case THROWS: case VALUE:
        case LINK: case LINK_PLAIN://XXX: was only unclosed???
            insideSeeTag(tag, jdctx);
            break;
        case REFERENCE:
            insideReference(tag, jdctx);
            break;
    }
}
 
Example #16
Source File: FindLocalUsagesQuery.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private void handleJavadoc(TreePath el) {
    if(el != null) {
        switch(el.getLeaf().getKind()) {
            case METHOD:
            case ANNOTATION_TYPE:
            case CLASS:
            case ENUM:
            case INTERFACE:
            case VARIABLE:
                DocCommentTree docCommentTree = info.getDocTrees().getDocCommentTree(el);
                if(docCommentTree != null) {
                    DocTreePath docTreePath = new DocTreePath(el, docCommentTree);
                    docScanner.scan(docTreePath, null);
                }
            default:
                break;
        }
    }
}
 
Example #17
Source File: Analyzer.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
public Void visitDocComment(DocCommentTree node, List<ErrorDescription> errors) {
    DocTreePath currentDocPath = getCurrentPath();
    Void value = super.visitDocComment(node, errors);
    DocSourcePositions sp = (DocSourcePositions) javac.getTrees().getSourcePositions();

    while (!tagStack.isEmpty()) {
        StartElementTree startTree = tagStack.pop();
        Name tagName = startTree.getName();
        HtmlTag tag = HtmlTag.get(tagName);
        if (tag.endKind == HtmlTag.EndKind.REQUIRED) {
            int s = (int) sp.getStartPosition(javac.getCompilationUnit(), currentDocPath.getDocComment(), startTree);
            int e = (int) sp.getEndPosition(javac.getCompilationUnit(), currentDocPath.getDocComment(), startTree);
            errors.add(ErrorDescriptionFactory.forSpan(ctx, s, e, TAG_START_UNMATCHED(tagName)));
        }
    }
    return value;
}
 
Example #18
Source File: DocTreePathHandle.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/**
 * Resolves an {@link TreePath} from the {@link TreePathHandle}.
 *
 * @param javac representing the
 * {@link javax.tools.CompilationTask}
 * @return resolved subclass of {@link Element} or null if the element
 * does not exist on the classpath/sourcepath of
 * {@link javax.tools.CompilationTask}.
 * @throws IllegalArgumentException when this {@link TreePathHandle} is
 * not created for a source represented by the compilationInfo.
 */
public DocTreePath resolve(final CompilationInfo javac) throws IllegalArgumentException {
    assert javac != null;
    TreePath treePath = treePathHandle.resolve(javac);
    if(treePath == null) {
        throw new IllegalArgumentException("treePathHandle.resolve(compilationInfo) returned null for treePathHandle " + treePathHandle);    //NOI18N
    }
    DocTreePath tp = null;
    DocCommentTree doc = javac.getDocTrees().getDocCommentTree(treePath);
    if (doc == null) {
        // no doc comment for the TreePath
        return null;
    }
    int pos = position.getOffset();
    tp = resolvePathForPos(javac, treePath, doc, pos + 1);
    if (tp != null) {
        return tp;
    }
    tp = resolvePathForPos(javac, treePath, doc, pos);
    return tp;
}
 
Example #19
Source File: Checker.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
@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);
}
 
Example #20
Source File: Messager.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public void printNotice(DocTreePath path, String msg) {
    String prefix = getDiagSource(path);
    if (diagListener != null) {
        report(DiagnosticType.NOTE, null, prefix + ": " + msg);
        return;
    }

    PrintWriter noticeWriter = getWriter(WriterKind.NOTICE);
    if (path == null) {
        printRawLines(noticeWriter, msg);
    } else {
        printRawLines(noticeWriter, prefix + ": " + msg);
    }
    noticeWriter.flush();
}
 
Example #21
Source File: FindLocalUsagesQuery.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public DocTree visitText(TextTree node, Element p) {
    if(searchComment) {
        DocTrees trees = info.getDocTrees();
        DocSourcePositions sourcePositions = trees.getSourcePositions();
        DocTreePath currentDocPath = getCurrentPath();
        if(toFind.getKind() == ElementKind.PARAMETER) {
            VariableElement var = (VariableElement) toFind;
            Element method = trees.getElement(currentDocPath);
            if(!var.getEnclosingElement().equals(method)) {
                return super.visitText(node, p);
            }
        }
        String text = node.getBody();
        String name = toFind.getSimpleName().toString();
        if(text.contains(name)) {
            int start = (int) sourcePositions.getStartPosition(info.getCompilationUnit(), currentDocPath.getDocComment(), node);
            int length = name.length();
            int offset = -1;
            do {
                offset = text.indexOf(name, ++offset);
                if(offset != -1) {
                    try {
                        MutablePositionRegion region = createRegion(doc, start + offset, start + offset + length);
                        comments.add(region);
                    } catch(BadLocationException ex) {
                        Exceptions.printStackTrace(ex);
                    }
                }
            } while (offset != -1);
        }
    }
    return super.visitText(node, p);
}
 
Example #22
Source File: TreeUtilities.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**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();
        
        ((DocTrees) this.info.getTrees()).getElement(path);
//        was:
//        ((JavacTrees) this.info.getTrees()).ensureDocReferenceAttributed(tp, ref);
        
        return ref.paramTypes;
    }
 
Example #23
Source File: RenameTransformer.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public DocTree visitIdentifier(com.sun.source.doctree.IdentifierTree node, Element elementToFind) {
    DocTreePath currentDocPath = getCurrentDocPath();
    DocTrees trees = workingCopy.getDocTrees();
    Element el = trees.getElement(currentDocPath);
    if (el != null && (el.equals(elementToFind))) {
        com.sun.source.doctree.IdentifierTree newIdent = make.DocIdentifier(newName);
        rewrite(currentDocPath.getTreePath().getLeaf(), node, newIdent);
    }
    return super.visitIdentifier(node, elementToFind);
}
 
Example #24
Source File: JavadocCompletionQuery.java    From netbeans with Apache License 2.0 5 votes vote down vote up
void resolveBlockTag(DocTreePath tag, JavadocContext jdctx) {
    int pos;
    String prefix;
    if (tag != null) {
        pos = (int) jdctx.positions.getStartPosition(jdctx.javac.getCompilationUnit(), jdctx.comment, tag.getLeaf());
        prefix = JavadocCompletionUtils.getCharSequence(jdctx.doc, pos, caretOffset).toString();
    } else {
        prefix = ""; // NOI18N
        pos = caretOffset;
    }
    
    items.addAll(JavadocCompletionItem.addBlockTagItems(jdctx.handle.getKind(), prefix, pos));
    jdctx.anchorOffset = pos;
}
 
Example #25
Source File: Checker.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
@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);
}
 
Example #26
Source File: Checker.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
@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);
}
 
Example #27
Source File: RenameTransformer.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public DocTree visitText(TextTree node, Element p) {
    if(renameInComments && refactoring.getContext().lookup(RenamePropertyRefactoringPlugin.class) == null) {
        DocTreePath currentDocPath = getCurrentDocPath();
        if(p.getKind() == ElementKind.PARAMETER) {
            VariableElement var = (VariableElement) p;
            Element method = workingCopy.getTrees().getElement(currentDocPath.getTreePath());
            if(!var.getEnclosingElement().equals(method)) {
                return super.visitText(node, p);
            }
        }
        String originalName = getOldSimpleName(p);
        if(node.getBody().contains(originalName)) {
            StringBuilder text = new StringBuilder(node.getBody());
            for (int index = text.indexOf(originalName); index != -1; index = text.indexOf(originalName, index + 1)) {
                if (index > 0 && Character.isJavaIdentifierPart(text.charAt(index - 1))) {
                    continue;
                }
                if ((index + originalName.length() < text.length()) && Character.isJavaIdentifierPart(text.charAt(index + originalName.length()))) {
                    continue;
                }
                text.delete(index, index + originalName.length());
                text.insert(index, newName);
            }
            if(!node.getBody().contentEquals(text)) {
                TextTree newText = make.Text(text.toString());
                rewrite(currentDocPath.getTreePath().getLeaf(), node, newText);
            }
        }
    }
    return super.visitText(node, p);
}
 
Example #28
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 visitUses(UsesTree tree, Void ignore) {
    Element e = env.trees.getElement(env.currPath);
    if (e.getKind() != ElementKind.MODULE) {
        env.messages.error(REFERENCE, tree, "dc.invalid.uses");
    }
    ReferenceTree serviceType = tree.getServiceType();
    Element se = env.trees.getElement(new DocTreePath(getCurrentPath(), serviceType));
    if (se == null) {
        env.messages.error(REFERENCE, tree, "dc.service.not.found");
    }
    return super.visitUses(tree, ignore);
}
 
Example #29
Source File: RemoveUnusedImports.java    From google-java-format with Apache License 2.0 5 votes vote down vote up
private void scanJavadoc() {
  if (getCurrentPath() == null) {
    return;
  }
  DocCommentTree commentTree = trees.getDocCommentTree(getCurrentPath());
  if (commentTree == null) {
    return;
  }
  docTreeSymbolScanner.scan(new DocTreePath(getCurrentPath(), commentTree), null);
}
 
Example #30
Source File: DocTreePathHandle.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public DocTreePath resolve(CompilationInfo javac) throws IllegalArgumentException {
    TreePath p = parent.resolve(javac);

    if (p == null) {
        return null;
    }
    
    DocCommentTree docCommentTree = javac.getDocTrees().getDocCommentTree(p);
    return getChild(docCommentTree, index);
}