当前位置: 首页>>代码示例>>Java>>正文


Java DocTrees.getDocCommentTree方法代码示例

本文整理汇总了Java中com.sun.source.util.DocTrees.getDocCommentTree方法的典型用法代码示例。如果您正苦于以下问题:Java DocTrees.getDocCommentTree方法的具体用法?Java DocTrees.getDocCommentTree怎么用?Java DocTrees.getDocCommentTree使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.sun.source.util.DocTrees的用法示例。


在下文中一共展示了DocTrees.getDocCommentTree方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: run

import com.sun.source.util.DocTrees; //导入方法依赖的package包/类
public boolean run(DocletEnvironment root) {
    DocTrees docTrees = root.getDocTrees();
    System.out.println("classes:" + ElementFilter.typesIn(root.getIncludedElements()));

    Element klass = ElementFilter.typesIn(root.getIncludedElements()).iterator().next();
    String text = "";
    try {
        DocCommentTree dcTree = docTrees.getDocCommentTree(klass, overviewpath);
        text = dcTree.getFullBody().toString();
    } catch (IOException ioe) {
        throw new Error(ioe);
    }

    if (text.length() < 64)
        System.err.println("text: '" + text + "'");
    else
        System.err.println("text: '"
                + text.substring(0, 20)
                + "..."
                + text.substring(text.length() - 20)
                + "'");
    return text.startsWith("ABC") && text.endsWith("XYZ");
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:24,代码来源:Test.java

示例2: run

import com.sun.source.util.DocTrees; //导入方法依赖的package包/类
public boolean run(DocletEnvironment root) {
        DocTrees trees = root.getDocTrees();
        TypeElement cd = ElementFilter.typesIn(root.getIncludedElements()).iterator().next();
        DocCommentTree docCommentTree = trees.getDocCommentTree(cd);
        List<? extends DocTree> tags = docCommentTree.getBody();

        for (int i = 0; i < tags.size(); i++) {
            System.out.println(tags.get(0).getKind());
//            if (!tags[i].name().equals(expectedTags[i]) ||
//                        !tags[i].text().equals(expectedText[i])) {
//                throw new Error("Tag \"" + tags[i] + "\" not as expected");
//            }
        }

        return true;
    }
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:17,代码来源:InlineTagsWithBraces.java

示例3: run

import com.sun.source.util.DocTrees; //导入方法依赖的package包/类
public boolean run(DocletEnvironment root) {
    DocTrees docTrees = root.getDocTrees();
    System.out.println("classes:" + root.getIncludedClasses());

    Element klass = root.getIncludedClasses().iterator().next();
    String text = "";
    try {
        DocCommentTree dcTree = docTrees.getDocCommentTree(klass, overviewpath);
        text = dcTree.getFullBody().toString();
    } catch (IOException ioe) {
        throw new Error(ioe);
    }

    if (text.length() < 64)
        System.err.println("text: '" + text + "'");
    else
        System.err.println("text: '"
                + text.substring(0, 20)
                + "..."
                + text.substring(text.length() - 20)
                + "'");
    return text.startsWith("ABC") && text.endsWith("XYZ");
}
 
开发者ID:campolake,项目名称:openjdk9,代码行数:24,代码来源:Test.java

示例4: run

import com.sun.source.util.DocTrees; //导入方法依赖的package包/类
public boolean run(DocletEnvironment root) {
        DocTrees trees = root.getDocTrees();
        TypeElement cd = root.getIncludedClasses().iterator().next();
        DocCommentTree docCommentTree = trees.getDocCommentTree(cd);
        List<? extends DocTree> tags = docCommentTree.getBody();

        for (int i = 0; i < tags.size(); i++) {
            System.out.println(tags.get(0).getKind());
//            if (!tags[i].name().equals(expectedTags[i]) ||
//                        !tags[i].text().equals(expectedText[i])) {
//                throw new Error("Tag \"" + tags[i] + "\" not as expected");
//            }
        }

        return true;
    }
 
开发者ID:campolake,项目名称:openjdk9,代码行数:17,代码来源:InlineTagsWithBraces.java

示例5: resolveContext

import com.sun.source.util.DocTrees; //导入方法依赖的package包/类
private boolean resolveContext(CompilationInfo javac, JavadocContext jdctx) throws IOException {
    jdctx.doc = javac.getDocument();
    // find class context: class, method, ...
    DocTrees trees = javac.getDocTrees();
    TreePath javadocFor = JavadocCompletionUtils.findJavadoc(javac, this.caretOffset);
    if (javadocFor == null) {
        return false;
    }
    jdctx.javadocFor = javadocFor;
    DocCommentTree docCommentTree = trees.getDocCommentTree(javadocFor);
    if (docCommentTree == null) {
        return false;
    }
    jdctx.comment = docCommentTree;
    Element elm = trees.getElement(javadocFor);
    if (elm == null) {
        return false;
    }
    jdctx.handle = ElementHandle.create(elm);
    jdctx.commentFor = elm;
    jdctx.jdts = JavadocCompletionUtils.findJavadocTokenSequence(javac, this.caretOffset);
    if (jdctx.jdts == null) {
        return false;
    }
    jdctx.positions = (DocSourcePositions) trees.getSourcePositions();
    return jdctx.positions != null;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:28,代码来源:JavadocCompletionQuery.java

示例6: parseDocComment

import com.sun.source.util.DocTrees; //导入方法依赖的package包/类
private DocCommentTree parseDocComment(JavacTask task, String javadoc) {
    DocTrees trees = DocTrees.instance(task);
    try {
        return trees.getDocCommentTree(new SimpleJavaFileObject(new URI("mem://doc.html"), javax.tools.JavaFileObject.Kind.HTML) {
            @Override @DefinedBy(Api.COMPILER)
            public CharSequence getCharContent(boolean ignoreEncodingErrors) throws IOException {
                return "<body>" + javadoc + "</body>";
            }
        });
    } catch (URISyntaxException ex) {
        return null;
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:14,代码来源:JavadocHelper.java

示例7: formatJavadoc

import com.sun.source.util.DocTrees; //导入方法依赖的package包/类
/**Format javadoc to plain text.
 *
 * @param header element caption that should be used
 * @param javadoc to format
 * @return javadoc formatted to plain text
 */
public String formatJavadoc(String header, String javadoc) {
    try {
        StringBuilder result = new StringBuilder();

        result.append(escape(CODE_HIGHLIGHT)).append(header).append(escape(CODE_RESET)).append("\n");

        if (javadoc == null) {
            return result.toString();
        }

        JavacTask task = (JavacTask) ToolProvider.getSystemJavaCompiler().getTask(null, null, null, null, null, null);
        DocTrees trees = DocTrees.instance(task);
        DocCommentTree docComment = trees.getDocCommentTree(new SimpleJavaFileObject(new URI("mem://doc.html"), Kind.HTML) {
            @Override @DefinedBy(Api.COMPILER)
            public CharSequence getCharContent(boolean ignoreEncodingErrors) throws IOException {
                return "<body>" + javadoc + "</body>";
            }
        });

        new FormatJavadocScanner(result, task).scan(docComment, null);

        addNewLineIfNeeded(result);

        return result.toString();
    } catch (URISyntaxException ex) {
        throw new InternalError("Unexpected exception", ex);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:35,代码来源:JavadocFormatter.java

示例8: printElement

import com.sun.source.util.DocTrees; //导入方法依赖的package包/类
/**
 * Prints an element.
 *
 * @param trees the utility class
 * @param e the element to be printed
 */
public void printElement(DocTrees trees, Element e) {
    DocCommentTree docCommentTree = trees.getDocCommentTree(e);
    if (docCommentTree != null) {
        System.out.println("Element (" + e.getKind() + ": "
                + e + ") has the following comments:");
        System.out.println("Entire body: " + docCommentTree.getFullBody());
        System.out.println("Block tags: " + docCommentTree.getBlockTags());
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:16,代码来源:Example.java

示例9: run

import com.sun.source.util.DocTrees; //导入方法依赖的package包/类
public boolean run(DocletEnvironment root) {
    TypeElement cd = ElementFilter.typesIn(root.getIncludedElements()).iterator().next();
    VariableElement fd = getFields(cd).get(0);
    DocTrees docTrees = root.getDocTrees();
    DocCommentTree docCommentTree = docTrees.getDocCommentTree(fd);
    List<? extends DocTree> firstSentence = docCommentTree.getFirstSentence();
    return true;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:9,代码来源:BreakIteratorWarning.java

示例10: run

import com.sun.source.util.DocTrees; //导入方法依赖的package包/类
public boolean run(DocletEnvironment root) {
    Set<TypeElement> classes = ElementFilter.typesIn(root.getIncludedElements());
    if (classes.size() != 1)
        throw new Error("1 " + Arrays.asList(classes));
    TypeElement self = classes.iterator().next();
    DocTrees trees = root.getDocTrees();
    DocCommentTree docCommentTree = trees.getDocCommentTree(self);
    String c = docCommentTree.getFullBody().toString();
    System.out.println("\"" + c + "\"");
    return c.equals("First sentence.\n0\n 1\n  2\n   3\n    4\n     5");
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:12,代码来源:NoStar.java

示例11: runElementAndBreakIteratorTests

import com.sun.source.util.DocTrees; //导入方法依赖的package包/类
/**
 * Tests getting a DocCommentTree from an element, as well
 * as test if break iterator setter/getter works correctly.
 *
 * @param javaFileName a test file to be processed
 * @param expected the expected output
 * @throws java.io.IOException
 */
public void runElementAndBreakIteratorTests(String javaFileName, String expected) throws IOException {
    List<File> javaFiles = new ArrayList<>();
    javaFiles.add(new File(testSrc, javaFileName));

    List<File> dirs = new ArrayList<>();
    dirs.add(new File(testSrc));

    try (StandardJavaFileManager fm = javac.getStandardFileManager(null, null, null)) {
        fm.setLocation(javax.tools.StandardLocation.SOURCE_PATH, dirs);
        Iterable<? extends JavaFileObject> fos = fm.getJavaFileObjectsFromFiles(javaFiles);

        final JavacTask t = javac.getTask(null, fm, null, null, null, fos);
        final DocTrees trees = DocTrees.instance(t);

        Iterable<? extends Element> elements = t.analyze();

        Element klass = elements.iterator().next();
        DocCommentTree dcTree = trees.getDocCommentTree(klass);

        List<? extends DocTree> firstSentence = dcTree.getFirstSentence();
        StringWriter sw = new StringWriter();
        DocPretty pretty = new DocPretty(sw);
        pretty.print(firstSentence);
        check("getDocCommentTree(Element)", expected, sw.toString());

        BreakIterator bi = BreakIterator.getSentenceInstance(Locale.FRENCH);
        trees.setBreakIterator(bi);
        BreakIterator nbi = trees.getBreakIterator();
        if (bi.equals(nbi)) {
            pass++;
            check("getDocCommentTree(Element) with BreakIterator", expected, sw.toString());
        } else {
            fail++;
            System.err.println("BreakIterators don't match");
        }
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:46,代码来源:DocCommentTreeApiTester.java

示例12: runRelativePathTest

import com.sun.source.util.DocTrees; //导入方法依赖的package包/类
/**
 * Tests DocTrees.getDocCommentTree(Element e, String relpath) using relative path.
 *
 * @param javaFileName the reference java file
 * @param fileName the relative html file
 * @throws java.lang.Exception ouch
 */
public void runRelativePathTest(String javaFileName, String fileName) throws Exception  {
    List<File> javaFiles = new ArrayList<>();
    javaFiles.add(new File(testSrc, javaFileName));

    List<File> dirs = new ArrayList<>();
    dirs.add(new File(testSrc));

    try (StandardJavaFileManager fm = javac.getStandardFileManager(null, null, null)) {
        fm.setLocation(javax.tools.StandardLocation.SOURCE_PATH, dirs);
        Iterable<? extends JavaFileObject> fos = fm.getJavaFileObjectsFromFiles(javaFiles);

        final JavacTask t = javac.getTask(null, fm, null, null, null, fos);
        final DocTrees trees = DocTrees.instance(t);

        Iterable<? extends Element> elements = t.analyze();

        Element klass = elements.iterator().next();

        DocCommentTree dcTree = trees.getDocCommentTree(klass, fileName);
        StringWriter sw = new StringWriter();
        printer.print(dcTree, sw);
        String found = sw.toString();

        FileObject htmlFo = fm.getFileForInput(javax.tools.StandardLocation.SOURCE_PATH,
                t.getElements().getPackageOf(klass).getQualifiedName().toString(),
                fileName);

        String expected = getExpected(htmlFo.openReader(true));
        astcheck(fileName, expected, found);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:39,代码来源:DocCommentTreeApiTester.java

示例13: run

import com.sun.source.util.DocTrees; //导入方法依赖的package包/类
public boolean run(DocletEnvironment root) {
    TypeElement cd = root.getIncludedClasses().iterator().next();
    VariableElement fd = getFields(cd).get(0);
    DocTrees docTrees = root.getDocTrees();
    DocCommentTree docCommentTree = docTrees.getDocCommentTree(fd);
    List<? extends DocTree> firstSentence = docCommentTree.getFirstSentence();
    return true;
}
 
开发者ID:campolake,项目名称:openjdk9,代码行数:9,代码来源:BreakIteratorWarning.java

示例14: run

import com.sun.source.util.DocTrees; //导入方法依赖的package包/类
public boolean run(DocletEnvironment root) {
    Set<TypeElement> classes = root.getIncludedClasses();
    if (classes.size() != 1)
        throw new Error("1 " + Arrays.asList(classes));
    TypeElement self = classes.iterator().next();
    DocTrees trees = root.getDocTrees();
    DocCommentTree docCommentTree = trees.getDocCommentTree(self);
    String c = docCommentTree.getFullBody().toString();
    System.out.println("\"" + c + "\"");
    return c.equals("First sentence.\n0\n 1\n  2\n   3\n    4\n     5");
}
 
开发者ID:campolake,项目名称:openjdk9,代码行数:12,代码来源:NoStar.java


注:本文中的com.sun.source.util.DocTrees.getDocCommentTree方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。