com.sun.source.doctree.IdentifierTree Java Examples

The following examples show how to use com.sun.source.doctree.IdentifierTree. 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: JavadocConverter.java    From j2objc with Apache License 2.0 5 votes vote down vote up
@Override
public Void visitParam(ParamTree node, TagElement tag) {
  IdentifierTree identifier = node.getName();
  if (identifier == null || node.isTypeParameter()) {
    return null;
  }
  List<? extends VariableElement> params = element instanceof ExecutableElement
      ? ((ExecutableElement) element).getParameters() : Collections.emptyList();
      tag.setTagKind(TagElement.TagKind.PARAM);
  String name = identifier.toString();
  VariableElement param = null;
  for (VariableElement p : params) {
    if (name.equals(p.getSimpleName().toString())) {
      param = p;
      break;
    }
  }
  // param will be null if the @param tag refers to a nonexistent parameter.
  TreeNode nameNode = param != null ? new SimpleName(param) : new SimpleName(name);
  setPos(identifier, nameNode);
  tag.addFragment(nameNode);
  scan(node.getDescription(), tag);
  int lastEnd = nameNode.getStartPosition();
  for (TreeNode fragment : tag.getFragments()) {
    // Fix up positions to match JDT's.
    // TODO(tball): remove and fix JavadocGenerator after javac switch.
    if (fragment.getKind() == TreeNode.Kind.TEXT_ELEMENT) {
      TextElement text = (TextElement) fragment;
      text.setText(" " + text.getText());
      text.setSourceRange(text.getStartPosition(), text.getLength() + 1);
    }
    int thisEnd = lastEnd + fragment.getLength();
    setPos(fragment, lastEnd, thisEnd);
    lastEnd = thisEnd;
  }
  setPos(tag, pos(node), endPos(node));
  tag.setLineNumber(nameNode.getLineNumber());
  return null;
}
 
Example #2
Source File: Checker.java    From TencentKona-8 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 #3
Source File: Checker.java    From openjdk-jdk8u-backup 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 #4
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)
@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 {
        boolean unique = foundParams.add(paramElement);

        if (!unique) {
            env.messages.warning(REFERENCE, tree, "dc.exists.param", nameTree);
        }
    }

    warnIfEmpty(tree, tree.getDescription());
    return super.visitParam(tree, ignore);
}
 
Example #5
Source File: ImmutableDocTreeTranslator.java    From netbeans with Apache License 2.0 5 votes vote down vote up
protected final SerialFieldTree rewriteChildren(SerialFieldTree tree) {
    SerialFieldTree value = tree;
    IdentifierTree name = (IdentifierTree) translate(tree.getName());
    List<? extends DocTree> description = translateDoc(tree.getDescription());
    ReferenceTree ref = (ReferenceTree) translate(tree.getType());
    if (ref != tree.getType() || name != tree.getName() || description != tree.getDescription()) {
        value = make.SerialField(name, ref, description);
    }
    return value;
}
 
Example #6
Source File: ImmutableDocTreeTranslator.java    From netbeans with Apache License 2.0 5 votes vote down vote up
protected final ParamTree rewriteChildren(ParamTree tree) {
    ParamTree value = tree;
    IdentifierTree name = (IdentifierTree) translate(tree.getName());
    List<? extends DocTree> description = translateDoc(tree.getDescription());
    if (name != tree.getName() || description != tree.getDescription()) {
        value = make.Param(tree.isTypeParameter(), name, description);
    }
    return value;
}
 
Example #7
Source File: CommentUtils.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public void setEnumValueOfTree(Configuration config, Element e) {

        List<DocTree> fullBody = new ArrayList<>();
        fullBody.add(treeFactory.newTextTree(config.getText("doclet.enum_valueof_doc.fullbody")));

        List<DocTree> tags = new ArrayList<>();

        List<DocTree> paramDescs = new ArrayList<>();
        paramDescs.add(treeFactory.newTextTree(config.getText("doclet.enum_valueof_doc.param_name")));
        ExecutableElement ee = (ExecutableElement) e;
        java.util.List<? extends VariableElement> parameters = ee.getParameters();
        VariableElement param = parameters.get(0);
        IdentifierTree id = treeFactory.newIdentifierTree(elementUtils.getName(param.getSimpleName().toString()));
        tags.add(treeFactory.newParamTree(false, id, paramDescs));

        List<DocTree> returnDescs = new ArrayList<>();
        returnDescs.add(treeFactory.newTextTree(config.getText("doclet.enum_valueof_doc.return")));
        tags.add(treeFactory.newReturnTree(returnDescs));

        List<DocTree> throwsDescs = new ArrayList<>();
        throwsDescs.add(treeFactory.newTextTree(config.getText("doclet.enum_valueof_doc.throws_ila")));

        ReferenceTree ref = treeFactory.newReferenceTree("java.lang.IllegalArgumentException");
        tags.add(treeFactory.newThrowsTree(ref, throwsDescs));

        throwsDescs = new ArrayList<>();
        throwsDescs.add(treeFactory.newTextTree(config.getText("doclet.enum_valueof_doc.throws_npe")));

        ref = treeFactory.newReferenceTree("java.lang.NullPointerException");
        tags.add(treeFactory.newThrowsTree(ref, throwsDescs));

        DocCommentTree docTree = treeFactory.newDocCommentTree(fullBody, tags);

        dcTreesMap.put(e, new DocCommentDuo(null, docTree));
    }
 
Example #8
Source File: CommentHelper.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public IdentifierTree getName(DocTree dtree) {
    switch (dtree.getKind()) {
        case PARAM:
            return ((ParamTree)dtree).getName();
        case SERIAL_FIELD:
            return ((SerialFieldTree)dtree).getName();
        default:
            return null;
        }
}
 
Example #9
Source File: Checker.java    From hottub 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 #10
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 #11
Source File: Checker.java    From openjdk-8 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 #12
Source File: Checker.java    From openjdk-jdk8u 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 #13
Source File: Checker.java    From jdk8u60 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 #14
Source File: JavadocConverter.java    From j2objc with Apache License 2.0 4 votes vote down vote up
@Override
public Void visitIdentifier(IdentifierTree node, TagElement tag) {
  tag.addFragment(setPos(node, new TextElement().setText(node.getName().toString())));
  return null;
}
 
Example #15
Source File: DocTreeMaker.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
@Override @DefinedBy(Api.COMPILER_TREE)
public DCSerialField newSerialFieldTree(IdentifierTree name, ReferenceTree type, List<? extends DocTree> description) {
    DCSerialField tree = new DCSerialField((DCIdentifier) name, (DCReference) type, cast(description));
    tree.pos = pos;
    return tree;
}
 
Example #16
Source File: DocTreeMaker.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
@Override @DefinedBy(Api.COMPILER_TREE)
public DCParam newParamTree(boolean isTypeParameter, IdentifierTree name, List<? extends DocTree> description) {
    DCParam tree = new DCParam(isTypeParameter, (DCIdentifier) name, cast(description));
    tree.pos = pos;
    return tree;
}
 
Example #17
Source File: RefactoringVisitor.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@Override
public DocTree visitIdentifier(IdentifierTree node, Element p) {
    return instance.visitIdentifier(node, p);
}
 
Example #18
Source File: Analyzer.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@Override
public Void visitIdentifier(IdentifierTree node, List<ErrorDescription> errors) {
    return super.visitIdentifier(node, errors);
}
 
Example #19
Source File: RefactoringVisitor.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public DocTree visitIdentifier(IdentifierTree node, Element p, Void ignore) {
    return super.visitIdentifier(node, p);
}
 
Example #20
Source File: RefactoringVisitor.java    From netbeans with Apache License 2.0 4 votes vote down vote up
/**
 * @since 1.47
 */
@Override
public DocTree visitIdentifier(IdentifierTree node, Element p) {
    return docScanner.visitIdentifier(node, p, null);
}
 
Example #21
Source File: DoctreeTest.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public void testCreateAll() throws Exception {
    testFile = new File(getWorkDir(), "Test.java");
    TestUtilities.copyStringToFile(testFile,
            "package hierbas.del.litoral;\n"
            + "\n"
            + "public class Test {\n"
            + "\n"
            + "    /**\n"
            + "     */\n"
            + "    private void test() {\n"
            + "    }\n"
            + "}\n");
    String golden =
            "package hierbas.del.litoral;\n"
            + "\n"
            + "public class Test {\n"
            + "\n"
            + "    /**\n"
            + "     * <!-- comment -->{@docRoot}</a>&a;{@inheritDoc}{@link H#H(H, H) H}{@literal H}<a a/>{@a H}{@value H#H(H, H)}\n"
            + "     * @author H\n"
            + "     * @deprecated H\n"
            + "     * @param a H\n"
            + "     * @param <A> H\n"
            + "     * @return H\n"
            + "     * @see H#H(H, H)\n"
            + "     * @serialData H\n"
            + "     * @serialField a H#H(H, H) H\n"
            + "     * @serial H\n"
            + "     * @since H\n"
            + "     * @throws H#H(H, H) H\n"
            + "     * @H H\n"
            + "     * @version H\n"
            + "     */\n"
            + "    private void test() {\n"
            + "    }\n"
            + "}\n";

    JavaSource src = getJavaSource(testFile);
    Task<WorkingCopy> task = new Task<WorkingCopy>() {
        @Override
        public void run(final WorkingCopy wc) throws IOException {
            wc.toPhase(JavaSource.Phase.RESOLVED);
            final TreeMaker make = wc.getTreeMaker();
            final DocTrees trees = wc.getDocTrees();
            new ErrorAwareTreePathScanner<Void, Void>() {
                @Override
                public Void visitMethod(final MethodTree mt, Void p) {
                    DocCommentTree docTree = trees.getDocCommentTree(getCurrentPath());
                    List<DocTree> firstSentence = new LinkedList<DocTree>();
                    List<DocTree> tags = new LinkedList<DocTree>();
                    
                    List<TextTree> text = Collections.singletonList(make.Text("H"));
                    IdentifierTree ident = make.DocIdentifier("a");
                    ReferenceTree reference = make.Reference((ExpressionTree)make.Type("H"), "H", Collections.<ExpressionTree>nCopies(2, (ExpressionTree)make.Type("H")));
                    AttributeTree attribute = make.Attribute("a", AttributeTree.ValueKind.EMPTY, null);

                    firstSentence.add(make.Comment("<!-- comment -->"));
                    firstSentence.add(make.DocRoot());
                    firstSentence.add(make.EndElement("a"));
                    firstSentence.add(make.Entity("a"));
                    firstSentence.add(make.InheritDoc());
                    firstSentence.add(make.Link(reference, text));
                    firstSentence.add(make.DocLiteral(text.get(0)));
                    firstSentence.add(make.StartElement("a", Collections.singletonList(attribute), true));
                    firstSentence.add(make.UnknownInlineTag("a", text));
                    firstSentence.add(make.Value(reference));

                    tags.add(make.Author(text));
                    tags.add(make.Deprecated(text));
                    tags.add(make.Param(false, ident, text));
                    tags.add(make.Param(true, make.DocIdentifier("A"), text));
                    tags.add(make.DocReturn(text));
                    tags.add(make.See(Collections.singletonList(reference)));
                    tags.add(make.SerialData(text));
                    tags.add(make.SerialField(ident, reference, text));
                    tags.add(make.Serial(text));
                    tags.add(make.Since(text));
                    tags.add(make.Throws(reference, text));
                    tags.add(make.UnknownBlockTag("H", text));
                    tags.add(make.Version(text));
                    
                    DocCommentTree newDoc = make.DocComment(firstSentence, Collections.EMPTY_LIST, tags);
                    wc.rewrite(mt, docTree, newDoc);
                    return super.visitMethod(mt, p);
                }
            }.scan(wc.getCompilationUnit(), null);
        }
    };
    src.runModificationTask(task).commit();
    String res = TestUtilities.copyFileToString(testFile);
    //System.err.println(res);
    assertEquals(golden, res);
}
 
Example #22
Source File: VeryPretty.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@Override
public Void visitIdentifier(IdentifierTree node, Void p) {
    print(node.getName());
    return null;
}
 
Example #23
Source File: ImmutableDocTreeTranslator.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@Override
public DocTree visitIdentifier(IdentifierTree tree, Object p) {
    return rewriteChildren(tree);
}
 
Example #24
Source File: ImmutableDocTreeTranslator.java    From netbeans with Apache License 2.0 4 votes vote down vote up
protected final IdentifierTree rewriteChildren(IdentifierTree tree) {
    return tree; // Nothing to do for a string
}
 
Example #25
Source File: DocTreeMaker.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override @DefinedBy(Api.COMPILER_TREE)
public DCSerialField newSerialFieldTree(IdentifierTree name, ReferenceTree type, List<? extends DocTree> description) {
    DCSerialField tree = new DCSerialField((DCIdentifier) name, (DCReference) type, cast(description));
    tree.pos = pos;
    return tree;
}
 
Example #26
Source File: DocTreeMaker.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override @DefinedBy(Api.COMPILER_TREE)
public DCParam newParamTree(boolean isTypeParameter, IdentifierTree name, List<? extends DocTree> description) {
    DCParam tree = new DCParam(isTypeParameter, (DCIdentifier) name, cast(description));
    tree.pos = pos;
    return tree;
}
 
Example #27
Source File: ApiDoclet.java    From uyuni with GNU General Public License v2.0 4 votes vote down vote up
@Override
public String visitIdentifier(IdentifierTree node, Void p) {
    return node.getName().toString();
}
 
Example #28
Source File: DocTreeFactory.java    From openjdk-jdk9 with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Create a new {@code IdentifierTree} object, to represent an identifier, such as in a
 * {@code @param } tag.
 * @param name the name of the identifier
 * @return an {@code IdentifierTree} object
 */
IdentifierTree newIdentifierTree(Name name);
 
Example #29
Source File: DocTreeFactory.java    From openjdk-jdk9 with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Create a new {@code ParamTree} object, to represent a {@code @param } tag.
 * @param isTypeParameter true if this is a type parameter, and false otherwise
 * @param name the parameter being described
 * @param description the description of the parameter
 * @return a {@code ParamTree} object
 */
ParamTree newParamTree(boolean isTypeParameter, IdentifierTree name, List<? extends DocTree> description);
 
Example #30
Source File: DocTreeFactory.java    From openjdk-jdk9 with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Create a new {@code SerialFieldTree} object, to represent a {@code @serialField } tag.
 * @param name the name of the field
 * @param type the type of the field
 * @param description the description of the field
 * @return a {@code SerialFieldTree} object
 */
SerialFieldTree newSerialFieldTree(IdentifierTree name, ReferenceTree type, List<? extends DocTree> description);