Search in sources :

Example 1 with IdentifierTree

use of com.sun.source.doctree.IdentifierTree in project j2objc by google.

the class JavadocConverter method visitParam.

@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()) {
        // 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;
}
Also used : TextElement(com.google.devtools.j2objc.ast.TextElement) TreeNode(com.google.devtools.j2objc.ast.TreeNode) ExecutableElement(javax.lang.model.element.ExecutableElement) SimpleName(com.google.devtools.j2objc.ast.SimpleName) IdentifierTree(com.sun.source.doctree.IdentifierTree) VariableElement(javax.lang.model.element.VariableElement)

Aggregations

SimpleName (com.google.devtools.j2objc.ast.SimpleName)1 TextElement (com.google.devtools.j2objc.ast.TextElement)1 TreeNode (com.google.devtools.j2objc.ast.TreeNode)1 IdentifierTree (com.sun.source.doctree.IdentifierTree)1 ExecutableElement (javax.lang.model.element.ExecutableElement)1 VariableElement (javax.lang.model.element.VariableElement)1