Search in sources :

Example 1 with Javadoc

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

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

the class GenerationUnit method addPackageJavadoc.

// Collect javadoc from the package declarations to display in the header.
private void addPackageJavadoc(CompilationUnit unit, String qualifiedMainType) {
    Javadoc javadoc = unit.getPackage().getJavadoc();
    if (javadoc == null) {
        return;
    }
    SourceBuilder builder = new SourceBuilder(false);
    JavadocGenerator.printDocComment(builder, javadoc);
    javadocBlocks.put(qualifiedMainType, builder.toString());
}
Also used : Javadoc(com.google.devtools.j2objc.ast.Javadoc)

Example 3 with Javadoc

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

the class TreeConverter method convertAssociatedComment.

private Comment convertAssociatedComment(JCTree node, Element element) {
    boolean docCommentsEnabled = newUnit.getEnv().options().docCommentsEnabled();
    DocCommentTable docComments = unit.docComments;
    if (!docCommentsEnabled || docComments == null || !docComments.hasComment(node)) {
        return null;
    }
    com.sun.tools.javac.parser.Tokens.Comment javacComment = docComments.getComment(node);
    Comment comment;
    switch(javacComment.getStyle()) {
        case BLOCK:
            comment = new BlockComment();
            break;
        case JAVADOC:
            comment = docCommentsEnabled ? convertJavadocComment(element) : new Javadoc();
            break;
        case LINE:
            comment = new LineComment();
            break;
        default:
            throw new AssertionError("unknown comment type");
    }
    int startPos = javacComment.getSourcePos(0);
    int endPos = startPos + javacComment.getText().length();
    comment.setSourceRange(startPos, endPos);
    comment.setLineNumber(unit.getLineMap().getLineNumber(startPos));
    return comment;
}
Also used : LineComment(com.google.devtools.j2objc.ast.LineComment) BlockComment(com.google.devtools.j2objc.ast.BlockComment) Comment(com.google.devtools.j2objc.ast.Comment) BlockComment(com.google.devtools.j2objc.ast.BlockComment) DocCommentTable(com.sun.tools.javac.tree.DocCommentTable) Javadoc(com.google.devtools.j2objc.ast.Javadoc) LineComment(com.google.devtools.j2objc.ast.LineComment)

Aggregations

Javadoc (com.google.devtools.j2objc.ast.Javadoc)3 BlockComment (com.google.devtools.j2objc.ast.BlockComment)1 Comment (com.google.devtools.j2objc.ast.Comment)1 LineComment (com.google.devtools.j2objc.ast.LineComment)1 TagElement (com.google.devtools.j2objc.ast.TagElement)1 TreeNode (com.google.devtools.j2objc.ast.TreeNode)1 DocTree (com.sun.source.doctree.DocTree)1 DocTrees (com.sun.source.util.DocTrees)1 TreePath (com.sun.source.util.TreePath)1 DCTree (com.sun.tools.javac.tree.DCTree)1 DocCommentTable (com.sun.tools.javac.tree.DocCommentTable)1