Search in sources :

Example 6 with DocTree

use of com.sun.source.doctree.DocTree in project morphia by mongodb.

the class QueryFilterTaglet method toString.

@Override
public String toString(List<? extends DocTree> tags, Element element) {
    if (tags.size() == 0) {
        return null;
    }
    StringBuilder buf = new StringBuilder(String.format("<dl><dt><span class=\"strong\">%s</span></dt>", getHeader()));
    for (DocTree tag : tags) {
        String text = ((UnknownBlockTagTree) tag).getContent().get(0).toString();
        buf.append("<dd>").append(genLink(text)).append("</dd>");
    }
    return buf.toString();
}
Also used : UnknownBlockTagTree(com.sun.source.doctree.UnknownBlockTagTree) DocTree(com.sun.source.doctree.DocTree)

Example 7 with DocTree

use of com.sun.source.doctree.DocTree in project ignite by apache.

the class IgniteLinkTaglet method toString.

/**
 * Given the <code>DocTree</code> representation of this custom tag, return its string representation.
 * <p>
 * Input: org.apache.ignite.grid.spi.indexing.h2.GridH2IndexingSpi#setIndexCustomFunctionClasses(Class[])
 * <p>
 * Output: &lt;a href="../../../../../org/apache/ignite/grid/spi/indexing/h2/GridH2IndexingSpi.html#
 * setIndexCustomFunctionClasses(java.lang.Class...)"&gt;
 * &lt;code&gt;GridH2IndexingSpi.setIndexCustomFunctionClasses(java.lang.Class[])&lt;/code&gt;&lt;/a&gt;
 *
 * @param tags <code>DocTree</code> representation of this custom tag.
 * @param element The element to which the enclosing comment belongs.
 */
@Override
public String toString(List<? extends DocTree> tags, Element element) {
    for (DocTree tag : tags) {
        String text = new SimpleDocTreeVisitor<String, Void>() {

            @Override
            public String visitUnknownInlineTag(UnknownInlineTagTree node, Void param) {
                return node.getContent().toString();
            }
        }.visit(tag, null);
        if (text == null || text.isEmpty())
            return "";
        File f = new File(env.getDocTrees().getPath(element).getCompilationUnit().getSourceFile().toUri());
        String curCls = f == null ? "" : f.getAbsolutePath().replace(File.separator, ".");
        String packPref = "src.main.java.";
        int idx = curCls.indexOf(packPref);
        StringBuilder path = new StringBuilder();
        if (idx != -1) {
            curCls = curCls.substring(idx + packPref.length());
            for (int i = 0, n = curCls.split("\\.").length - 2; i < n; i++) path.append("../");
        }
        String[] tokens = text.split("#");
        int lastIdx = tokens[0].lastIndexOf('.');
        String simpleClsName = lastIdx != -1 && lastIdx + 1 < tokens[0].length() ? tokens[0].substring(lastIdx + 1) : tokens[0];
        String fullyQClsName = tokens[0].replace(".", "/");
        return "<a href=\"" + path + fullyQClsName + ".html" + (tokens.length > 1 ? ("#" + tokens[1].replace("[]", "...")) : "") + "\"><code>" + simpleClsName + (tokens.length > 1 ? ("." + tokens[1]) : "") + "</code></a>";
    }
    return "";
}
Also used : UnknownInlineTagTree(com.sun.source.doctree.UnknownInlineTagTree) DocTree(com.sun.source.doctree.DocTree) File(java.io.File)

Example 8 with DocTree

use of com.sun.source.doctree.DocTree in project cxf by apache.

the class DumpJavaDoc method run.

@Override
public boolean run(DocletEnvironment docEnv) {
    final Elements utils = docEnv.getElementUtils();
    final DocTrees docTrees = docEnv.getDocTrees();
    try (OutputStream os = Files.newOutputStream(Paths.get(dumpFileName))) {
        final Properties javaDocMap = new Properties();
        for (Element element : docEnv.getIncludedElements()) {
            if (element.getKind() == ElementKind.CLASS) {
                final TypeElement classDoc = (TypeElement) element;
                final DocCommentTree classCommentTree = docTrees.getDocCommentTree(classDoc);
                if (classCommentTree != null) {
                    javaDocMap.put(classDoc.toString(), getAllComments(classCommentTree.getFullBody()));
                }
                for (Element member : classDoc.getEnclosedElements()) {
                    // Skip all non-public methods
                    if (!member.getModifiers().contains(Modifier.PUBLIC)) {
                        continue;
                    }
                    if (member.getKind() == ElementKind.METHOD) {
                        final ExecutableElement method = (ExecutableElement) member;
                        final DocCommentTree methodCommentTree = docTrees.getDocCommentTree(method);
                        final String qualifiedName = utils.getBinaryName(classDoc) + "." + method.getSimpleName();
                        if (methodCommentTree == null) {
                            javaDocMap.put(qualifiedName, "");
                        } else {
                            javaDocMap.put(qualifiedName, getAllComments(methodCommentTree.getFullBody()));
                            for (DocTree tree : methodCommentTree.getBlockTags()) {
                                if (tree.getKind() == DocTree.Kind.RETURN) {
                                    final ReturnTree returnTree = (ReturnTree) tree;
                                    javaDocMap.put(qualifiedName + ".returnCommentTag", getAllComments(returnTree.getDescription()));
                                } else if (tree.getKind() == DocTree.Kind.PARAM) {
                                    final ParamTree paramTree = (ParamTree) tree;
                                    final int index = getParamIndex(method, paramTree);
                                    if (index >= 0) {
                                        javaDocMap.put(qualifiedName + ".paramCommentTag." + index, getAllComments(paramTree.getDescription()));
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        javaDocMap.store(os, "");
        os.flush();
    } catch (final IOException ex) {
        reporter.print(Diagnostic.Kind.ERROR, ex.getMessage());
    }
    return true;
}
Also used : ParamTree(com.sun.source.doctree.ParamTree) TypeElement(javax.lang.model.element.TypeElement) OutputStream(java.io.OutputStream) VariableElement(javax.lang.model.element.VariableElement) TypeElement(javax.lang.model.element.TypeElement) ExecutableElement(javax.lang.model.element.ExecutableElement) Element(javax.lang.model.element.Element) ExecutableElement(javax.lang.model.element.ExecutableElement) ReturnTree(com.sun.source.doctree.ReturnTree) IOException(java.io.IOException) Elements(javax.lang.model.util.Elements) Properties(java.util.Properties) DocCommentTree(com.sun.source.doctree.DocCommentTree) DocTrees(com.sun.source.util.DocTrees) DocTree(com.sun.source.doctree.DocTree)

Example 9 with DocTree

use of com.sun.source.doctree.DocTree 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 10 with DocTree

use of com.sun.source.doctree.DocTree in project checker-framework by typetools.

the class ManualTaglet method toString.

@Override
public String toString(List<? extends DocTree> tags, Element element) {
    if (tags.isEmpty()) {
        return "";
    }
    StringJoiner sb = new StringJoiner(", ");
    for (DocTree t : tags) {
        String text = getText(t);
        String[] split = text.split(" ", 2);
        sb.add(formatLink(split));
    }
    return formatHeader(sb.toString());
}
Also used : DocTree(com.sun.source.doctree.DocTree) StringJoiner(java.util.StringJoiner)

Aggregations

DocTree (com.sun.source.doctree.DocTree)13 UnknownBlockTagTree (com.sun.source.doctree.UnknownBlockTagTree)5 DocTrees (com.sun.source.util.DocTrees)3 DCTree (com.sun.tools.javac.tree.DCTree)3 Javadoc (com.google.devtools.j2objc.ast.Javadoc)2 TagElement (com.google.devtools.j2objc.ast.TagElement)2 TreeNode (com.google.devtools.j2objc.ast.TreeNode)2 DocCommentTree (com.sun.source.doctree.DocCommentTree)2 TextElement (com.google.devtools.j2objc.ast.TextElement)1 ASTHelpers.getSymbol (com.google.errorprone.util.ASTHelpers.getSymbol)1 ParamTree (com.sun.source.doctree.ParamTree)1 ReturnTree (com.sun.source.doctree.ReturnTree)1 UnknownInlineTagTree (com.sun.source.doctree.UnknownInlineTagTree)1 TreePath (com.sun.source.util.TreePath)1 Symbol (com.sun.tools.javac.code.Symbol)1 File (java.io.File)1 IOException (java.io.IOException)1 OutputStream (java.io.OutputStream)1 Properties (java.util.Properties)1 StringJoiner (java.util.StringJoiner)1