Search in sources :

Example 1 with TextElement

use of com.google.devtools.j2objc.ast.TextElement in project j2objc by google.

the class JavadocConverter method visitEntity.

@Override
public Void visitEntity(EntityTree node, TagElement tag) {
    String text = String.format("&%s;", node.getName().toString());
    tag.addFragment(setPos(node, new TextElement().setText(text)));
    return null;
}
Also used : TextElement(com.google.devtools.j2objc.ast.TextElement)

Example 2 with TextElement

use of com.google.devtools.j2objc.ast.TextElement in project j2objc by google.

the class JavadocConverter method visitErroneous.

@Override
public Void visitErroneous(ErroneousTree node, TagElement tag) {
    if (reportWarnings) {
        // Update node's position to be relative to the whole source file, instead of just
        // the doc-comment's start. That way, the diagnostic printer will fetch the correct
        // text for the line the error is on.
        ((DCTree.DCErroneous) node).pos = ((DCTree) node).pos((DCTree.DCDocComment) docComment).getStartPosition();
        ErrorUtil.warning(node.getDiagnostic().toString());
    } else {
        // Include erroneous text in doc-comment as is.
        TreeNode newNode = setPos(node, new TextElement().setText(node.getBody()));
        tag.addFragment(newNode);
    }
    return null;
}
Also used : TextElement(com.google.devtools.j2objc.ast.TextElement) TreeNode(com.google.devtools.j2objc.ast.TreeNode) DCTree(com.sun.tools.javac.tree.DCTree)

Example 3 with TextElement

use of com.google.devtools.j2objc.ast.TextElement 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)

Example 4 with TextElement

use of com.google.devtools.j2objc.ast.TextElement in project j2objc by google.

the class JavadocConverter method visitText.

@Override
public Void visitText(TextTree node, TagElement tag) {
    String[] lines = node.getBody().split("\n");
    int linePos = pos(node);
    for (String line : lines) {
        if (line.length() > 0) {
            linePos = source.indexOf(line, linePos);
            int endPos = linePos + line.length();
            TreeNode newNode = setPos(new TextElement().setText(line), linePos, endPos);
            tag.addFragment(newNode);
        }
    }
    return null;
}
Also used : TextElement(com.google.devtools.j2objc.ast.TextElement) TreeNode(com.google.devtools.j2objc.ast.TreeNode)

Example 5 with TextElement

use of com.google.devtools.j2objc.ast.TextElement in project j2objc by google.

the class JavadocConverter method visitEndElement.

@Override
public Void visitEndElement(EndElementTree node, TagElement tag) {
    String text = String.format("</%s>", node.getName().toString());
    int pos = pos(node);
    tag.addFragment(setPos(new TextElement().setText(text), pos, pos + text.length()));
    return null;
}
Also used : TextElement(com.google.devtools.j2objc.ast.TextElement)

Aggregations

TextElement (com.google.devtools.j2objc.ast.TextElement)8 TreeNode (com.google.devtools.j2objc.ast.TreeNode)5 SimpleName (com.google.devtools.j2objc.ast.SimpleName)2 VariableElement (javax.lang.model.element.VariableElement)2 Name (com.google.devtools.j2objc.ast.Name)1 TagElement (com.google.devtools.j2objc.ast.TagElement)1 DocTree (com.sun.source.doctree.DocTree)1 IdentifierTree (com.sun.source.doctree.IdentifierTree)1 DCTree (com.sun.tools.javac.tree.DCTree)1 Element (javax.lang.model.element.Element)1 ExecutableElement (javax.lang.model.element.ExecutableElement)1