Search in sources :

Example 1 with TagElement

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

the class JavadocConverter method convertJavadoc.

/**
   * Returns an AST node for the javadoc comment of a specified class,
   * method, or field element.
   */
static Javadoc convertJavadoc(Element element, String source, JavacEnvironment env, boolean reportWarnings) {
    DocTrees docTrees = DocTrees.instance(env.task());
    TreePath path = docTrees.getPath(element);
    if (path == null) {
        throw new AssertionError("could not find tree path for element");
    }
    DCTree.DCDocComment docComment = (DCTree.DCDocComment) docTrees.getDocCommentTree(path);
    if (docComment == null) {
        // Declaration does not have a javadoc comment.
        return null;
    }
    JavadocConverter converter = new JavadocConverter(element, docComment, source, docTrees, path.getCompilationUnit(), reportWarnings);
    Javadoc result = new Javadoc();
    // First tag has no name.
    TagElement newTag = new TagElement();
    converter.scan(docComment.getFirstSentence(), newTag);
    converter.scan(docComment.getBody(), newTag);
    if (!newTag.getFragments().isEmpty()) {
        List<TreeNode> fragments = newTag.getFragments();
        int start = fragments.get(0).getStartPosition();
        TreeNode lastFragment = fragments.get(fragments.size() - 1);
        int end = start + lastFragment.getLength();
        converter.setPos(newTag, start, end);
        result.addTag(newTag);
    }
    for (DocTree tag : docComment.getBlockTags()) {
        if (tag.getKind() != DocTree.Kind.ERRONEOUS) {
            newTag = new TagElement();
            converter.scan(tag, newTag);
            result.addTag(newTag);
        }
    }
    return result;
}
Also used : Javadoc(com.google.devtools.j2objc.ast.Javadoc) TreePath(com.sun.source.util.TreePath) DocTrees(com.sun.source.util.DocTrees) TreeNode(com.google.devtools.j2objc.ast.TreeNode) TagElement(com.google.devtools.j2objc.ast.TagElement) DocTree(com.sun.source.doctree.DocTree) DCTree(com.sun.tools.javac.tree.DCTree)

Example 2 with TagElement

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

the class JavadocConverter method visitLiteral.

@Override
public Void visitLiteral(LiteralTree node, TagElement tag) {
    TagElement newTag = new TagElement();
    TagKind tagKind = node.getKind() == DocTree.Kind.CODE ? TagKind.CODE : TagKind.LITERAL;
    setTagValues(newTag, tagKind, node, node.getBody());
    tag.addFragment(newTag);
    return null;
}
Also used : TagElement(com.google.devtools.j2objc.ast.TagElement) TagKind(com.google.devtools.j2objc.ast.TagElement.TagKind)

Example 3 with TagElement

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

the class JavadocConverter method convertJavadoc.

/**
 * Returns an AST node for the javadoc comment of a specified class, method, or field element.
 */
static Javadoc convertJavadoc(TreePath path, String source, JavacEnvironment env, boolean reportWarnings) {
    DocTrees docTrees = DocTrees.instance(env.task());
    DocCommentTree docComment = docTrees.getDocCommentTree(path);
    if (docComment == null) {
        // Declaration does not have a javadoc comment.
        return null;
    }
    JavadocConverter converter = new JavadocConverter(env.treeUtilities().getElement(path), docComment, source, docTrees, path.getCompilationUnit(), reportWarnings);
    Javadoc result = new Javadoc();
    // First tag is the description.
    TagElement newTag = new TagElement().setTagKind(TagElement.TagKind.DESCRIPTION);
    converter.scan(docComment.getFirstSentence(), newTag);
    converter.scan(docComment.getBody(), newTag);
    if (!newTag.getFragments().isEmpty()) {
        List<TreeNode> fragments = newTag.getFragments();
        int start = fragments.get(0).getStartPosition();
        TreeNode lastFragment = fragments.get(fragments.size() - 1);
        int end = start + lastFragment.getLength();
        converter.setPos(newTag, start, end);
        result.addTag(newTag);
    }
    for (DocTree tag : docComment.getBlockTags()) {
        if (tag.getKind() != DocTree.Kind.ERRONEOUS) {
            newTag = new TagElement();
            converter.scan(tag, newTag);
            result.addTag(newTag);
        }
    }
    return result;
}
Also used : DocCommentTree(com.sun.source.doctree.DocCommentTree) DocTrees(com.sun.source.util.DocTrees) TreeNode(com.google.devtools.j2objc.ast.TreeNode) Javadoc(com.google.devtools.j2objc.ast.Javadoc) TagElement(com.google.devtools.j2objc.ast.TagElement) DocTree(com.sun.source.doctree.DocTree)

Example 4 with TagElement

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

the class JavadocConverter method visitLink.

@Override
public Void visitLink(LinkTree node, TagElement tag) {
    TagElement newTag = new TagElement().setTagKind(TagKind.parse("@" + node.getTagName()));
    setPos(node, newTag);
    if (node.getLabel().isEmpty()) {
        scan(node.getReference(), newTag);
    } else {
        scan(node.getLabel(), newTag);
    }
    tag.addFragment(newTag);
    return null;
}
Also used : TagElement(com.google.devtools.j2objc.ast.TagElement)

Example 5 with TagElement

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

the class JavadocGenerator method printDocComment.

private void printDocComment(Javadoc javadoc) {
    if (javadoc != null) {
        printIndent();
        // Use HeaderDoc doc-comment start, which is compatible with Xcode Quick Help and Doxygen.
        println("/*!");
        List<TagElement> tags = javadoc.getTags();
        for (TagElement tag : tags) {
            if (tag.getTagKind() == TagKind.DESCRIPTION) {
                String description = printTagFragments(tag.getFragments());
                // Extract first sentence from description.
                BreakIterator iterator = BreakIterator.getSentenceInstance(Locale.US);
                iterator.setText(description.toString());
                int start = iterator.first();
                int end = iterator.next();
                if (end != BreakIterator.DONE) {
                    // Print brief tag first, since Quick Help shows it first. This makes the
                    // generated source easier to review.
                    printDocLine(String.format("@brief %s", description.substring(start, end)).trim());
                    String remainder = description.substring(end);
                    if (!remainder.isEmpty()) {
                        printDocLine(remainder);
                    }
                } else {
                    printDocLine(description);
                }
            } else {
                String doc = printTag(tag);
                if (!doc.isEmpty()) {
                    printDocLine(doc);
                }
            }
        }
        printIndent();
        println(" */");
    }
}
Also used : TagElement(com.google.devtools.j2objc.ast.TagElement) BreakIterator(java.text.BreakIterator)

Aggregations

TagElement (com.google.devtools.j2objc.ast.TagElement)6 TreeNode (com.google.devtools.j2objc.ast.TreeNode)3 Javadoc (com.google.devtools.j2objc.ast.Javadoc)2 DocTree (com.sun.source.doctree.DocTree)2 DocTrees (com.sun.source.util.DocTrees)2 Name (com.google.devtools.j2objc.ast.Name)1 SimpleName (com.google.devtools.j2objc.ast.SimpleName)1 TagKind (com.google.devtools.j2objc.ast.TagElement.TagKind)1 TextElement (com.google.devtools.j2objc.ast.TextElement)1 DocCommentTree (com.sun.source.doctree.DocCommentTree)1 TreePath (com.sun.source.util.TreePath)1 DCTree (com.sun.tools.javac.tree.DCTree)1 BreakIterator (java.text.BreakIterator)1 Element (javax.lang.model.element.Element)1 VariableElement (javax.lang.model.element.VariableElement)1