com.sun.source.doctree.ReferenceTree Java Examples

The following examples show how to use com.sun.source.doctree.ReferenceTree. 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: 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 #2
Source File: ReferenceTest.java    From openjdk-8-source 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: VeryPretty.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
public Void visitReference(ReferenceTree node, Void p) {
    //TODO: should use formatting settings:
    DCReference refNode = (DCReference) node;
    if (refNode.qualifierExpression != null) {
        print(refNode.qualifierExpression);
    }
    if (refNode.memberName != null) {
        print("#");
        print(refNode.memberName);
    }
    if (refNode.paramTypes != null) {
        print("(");
        boolean first = true;
        for (Tree param : refNode.paramTypes) {
            if (!first) print(", ");
            print(param.toString());
            first = false;
        }
        print(")");
    }
    return null;
}
 
Example #4
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 #5
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 #6
Source File: RemoveUnusedImports.java    From google-java-format with Apache License 2.0 6 votes vote down vote up
@Override
public Void visitReference(ReferenceTree referenceTree, Void unused) {
  DCReference reference = (DCReference) referenceTree;
  long basePos =
      reference.getSourcePosition((DCTree.DCDocComment) getCurrentPath().getDocComment());
  // the position of trees inside the reference node aren't stored, but the qualifier's
  // start position is the beginning of the reference node
  if (reference.qualifierExpression != null) {
    new ReferenceScanner(basePos).scan(reference.qualifierExpression, null);
  }
  // Record uses inside method parameters. The javadoc tool doesn't use these, but
  // IntelliJ does.
  if (reference.paramTypes != null) {
    for (JCTree param : reference.paramTypes) {
      // TODO(cushon): get start positions for the parameters
      new ReferenceScanner(-1).scan(param, null);
    }
  }
  return null;
}
 
Example #7
Source File: Checker.java    From openjdk-jdk8u 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 #8
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 #9
Source File: FindLocalUsagesQuery.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
public DocTree visitReference(ReferenceTree node, Element p) {
    DocTrees trees = info.getDocTrees();
    Element el = trees.getElement(getCurrentPath());
    if (el != null && el.equals(toFind)) {
        int[] span = treeUtils.findNameSpan(getCurrentPath().getDocComment(), node);
        if(span != null) {
            try {
                MutablePositionRegion region = createRegion(doc, span[0], span[1]);
                usages.add(region);
            } catch (BadLocationException ex) {
                Exceptions.printStackTrace(ex);
            }
        }
    }
    return super.visitReference(node, p);
}
 
Example #10
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 #11
Source File: Checker.java    From openjdk-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 #12
Source File: Checker.java    From openjdk-jdk8u-backup 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: ReferenceTest.java    From TencentKona-8 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 #14
Source File: ReferenceTest.java    From openjdk-8 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 #15
Source File: ReferenceTest.java    From openjdk-jdk8u-backup 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 #16
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 #17
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 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 #18
Source File: DocTreeMaker.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Override @DefinedBy(Api.COMPILER_TREE)
public DCThrows newExceptionTree(ReferenceTree name, List<? extends DocTree> description) {
    // TODO: verify the reference is just to a type (not a field or method)
    DCThrows tree = new DCThrows(Kind.EXCEPTION, (DCReference) name, cast(description));
    tree.pos = pos;
    return tree;
}
 
Example #19
Source File: Checker.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
@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);
}
 
Example #20
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 #21
Source File: ReferenceTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Void visitSee(SeeTree tree, Void ignore) {
    List<? extends DocTree> refLabel = tree.getReference();
    if (refLabel.size() > 1 && (refLabel.get(0) instanceof ReferenceTree)) {
        ReferenceTree ref = (ReferenceTree) refLabel.get(0);
        List<? extends DocTree> label = refLabel.subList(1, refLabel.size());
        checkReference(ref, label);
    }
    return null;
}
 
Example #22
Source File: DocTreeMaker.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override @DefinedBy(Api.COMPILER_TREE)
public DCValue newValueTree(ReferenceTree ref) {
    // TODO: verify the reference is to a constant value
    DCValue tree = new DCValue((DCReference) ref);
    tree.pos = pos;
    return tree;
}
 
Example #23
Source File: ImmutableDocTreeTranslator.java    From netbeans with Apache License 2.0 5 votes vote down vote up
protected final ValueTree rewriteChildren(ValueTree tree) {
    ValueTree value = tree;
    ReferenceTree reference = (ReferenceTree) translate(tree.getReference());
    if (reference != tree.getReference()) {
        value = make.Value(reference);
    }
    return value;
}
 
Example #24
Source File: ImmutableDocTreeTranslator.java    From netbeans with Apache License 2.0 5 votes vote down vote up
protected final UsesTree rewriteChildren(UsesTree tree) {
    UsesTree value = tree;
    ReferenceTree name = (ReferenceTree) translate(tree.getServiceType());
    List<? extends DocTree> description = translateDoc(tree.getDescription());
    if (name != tree.getServiceType()|| description != tree.getDescription()) {
        value = make.Uses(name, description);
    }
    return value;
}
 
Example #25
Source File: Checker.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
@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);
}
 
Example #26
Source File: Checker.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
@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);
}
 
Example #27
Source File: ImmutableDocTreeTranslator.java    From netbeans with Apache License 2.0 5 votes vote down vote up
protected final ReferenceTree rewriteChildren(ReferenceTree tree) {
    DCReference refTree = (DCReference) tree;
    ReferenceTree value = tree;
    ExpressionTree classReference = (ExpressionTree) translate(refTree.qualifierExpression);
    List<? extends Tree> methodParameters = translate(refTree.paramTypes);
    if(classReference != refTree.qualifierExpression || methodParameters != refTree.paramTypes) {
        value = make.Reference(classReference, refTree.memberName, methodParameters);
    }
    return value;
}
 
Example #28
Source File: ImmutableDocTreeTranslator.java    From netbeans with Apache License 2.0 5 votes vote down vote up
protected final LinkTree rewriteChildren(LinkTree tree) {
    LinkTree value = tree;
    List<? extends DocTree> label = translateDoc(tree.getLabel());
    ReferenceTree ref = (ReferenceTree) translate(tree.getReference());
    if (label != tree.getLabel() || ref != tree.getReference()) {
        value = make.Link(ref, label);
    }
    return value;
}
 
Example #29
Source File: ElementJavadoc.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void appendReference(StringBuilder sb, ReferenceTree ref, List<? extends DocTree> label, TreePath docPath, DocCommentTree doc, DocTrees trees) {
    String sig = ref.getSignature();
    if (sig != null && sig.length() > 0) {
        if (sig.charAt(0) == '#') { //NOI18N
            sig = sig.substring(1);
        }
        sig = sig.replace('#', '.'); //NOI18N
    }
    Element element = trees.getElement(DocTreePath.getPath(docPath, doc, ref));        
    if (element != null) {
        createLink(sb, element, label == null || label.isEmpty() ? sig : inlineTags(label, docPath, doc, trees, null)); //NOI18N
    } else {
        sb.append(label == null || label.isEmpty() ? sig : inlineTags(label, docPath, doc, trees, null));
    }
}
 
Example #30
Source File: Checker.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
private void checkThrowsDeclared(ReferenceTree tree, TypeMirror t, List<? extends TypeMirror> list) {
    boolean found = false;
    for (TypeMirror tl : list) {
        if (env.types.isAssignable(t, tl)) {
            foundThrows.add(tl);
            found = true;
        }
    }
    if (!found)
        env.messages.error(REFERENCE, tree, "dc.exception.not.thrown", t);
}