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


Java DocTrees.instance方法代码示例

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


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

示例1: runFileObjectTest

import com.sun.source.util.DocTrees; //导入方法依赖的package包/类
/**
 * Tests DocTrees.getDocCommentTree(FileObject fo).
 *
 * @param htmlfileName the file to be parsed
 * @throws Exception when an error occurs.
 */
public void runFileObjectTest(String htmlfileName) throws Exception {
    List<File> javaFiles =  Collections.emptyList();

    List<File> otherFiles = new ArrayList<>();
    otherFiles.add(new File(testSrc, htmlfileName));

    try (StandardJavaFileManager fm = javac.getStandardFileManager(null, null, null)) {
        Iterable<? extends JavaFileObject> fos = fm.getJavaFileObjectsFromFiles(javaFiles);
        Iterable<? extends JavaFileObject> others = fm.getJavaFileObjectsFromFiles(otherFiles);

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

        StringWriter sw = new StringWriter();

        printer.print(trees.getDocCommentTree(others.iterator().next()), sw);
        String found = sw.toString();
        String expected = getExpected(otherFiles.iterator().next().toPath());
        astcheck(otherFiles.toString(), expected, found);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:28,代码来源:DocCommentTreeApiTester.java

示例2: run

import com.sun.source.util.DocTrees; //导入方法依赖的package包/类
void run() throws Exception {
    List<File> files = new ArrayList<File>();
    File testSrc = new File(System.getProperty("test.src"));
    for (File f: testSrc.listFiles()) {
        if (f.isFile() && f.getName().endsWith(".java"))
            files.add(f);
    }

    JavacTool javac = JavacTool.create();
    StandardJavaFileManager fm = javac.getStandardFileManager(null, null, null);

    Iterable<? extends JavaFileObject> fos = fm.getJavaFileObjectsFromFiles(files);

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

    Iterable<? extends CompilationUnitTree> units = t.parse();

    DeclScanner ds = new DeclScanner(trees);
    for (CompilationUnitTree unit: units) {
        ds.scan(unit, null);
    }

    if (errors > 0)
        throw new Exception(errors + " errors occurred");
}
 
开发者ID:ojdkbuild,项目名称:lookaside_java-1.8.0-openjdk,代码行数:27,代码来源:DocTreePathScannerTest.java

示例3: 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

示例4: 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

示例5: testAnnoProcessor

import com.sun.source.util.DocTrees; //导入方法依赖的package包/类
void testAnnoProcessor(JavacTool javac, StandardJavaFileManager fm,
        Iterable<? extends JavaFileObject> files, PrintWriter out,
        int expectedDocComments) {
    out.println("Test annotation processor");
    JavacTask task = javac.getTask(out, fm, null, null, null, files);
    AnnoProc ap = new AnnoProc(DocTrees.instance(task));
    task.setProcessors(Arrays.asList(ap));
    task.call();
    ap.checker.checkDocComments(expectedDocComments);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:11,代码来源:Test.java

示例6: testTaskListener

import com.sun.source.util.DocTrees; //导入方法依赖的package包/类
void testTaskListener(JavacTool javac, StandardJavaFileManager fm,
        Iterable<? extends JavaFileObject> files, PrintWriter out,
        int expectedDocComments) {
    out.println("Test task listener");
    JavacTask task = javac.getTask(out, fm, null, null, null, files);
    TaskListnr tl = new TaskListnr(DocTrees.instance(task));
    task.addTaskListener(tl);
    task.call();
    tl.checker.checkDocComments(expectedDocComments);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:11,代码来源:Test.java

示例7: 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

示例8: 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

示例9: runDocTreePath

import com.sun.source.util.DocTrees; //导入方法依赖的package包/类
/**
 * Tests DocTrees.getDocTreePath(PackageElement p, FileObject fo).
 *
 * @param javaFileName the java anchor file
 * @param pkgFileName the package file name
 * @throws Exception e if something goes awry
 */
public void runDocTreePath(String javaFileName, String pkgFileName) 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);
        final Elements elementUtils = t.getElements();

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

        Element klass = elements.iterator().next();
        PackageElement pkg = elementUtils.getPackageOf(klass);

        FileObject htmlFo = fm.getFileForInput(javax.tools.StandardLocation.SOURCE_PATH,
                t.getElements().getPackageOf(klass).getQualifiedName().toString(),
                "package.html");
        System.out.println();
        DocTreePath treePath = trees.getDocTreePath(htmlFo, pkg);
        DocCommentTree dcTree = treePath.getDocComment();

        StringWriter sw = new StringWriter();
        printer.print(dcTree, sw);
        String found = sw.toString();

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

示例10: run

import com.sun.source.util.DocTrees; //导入方法依赖的package包/类
void run() throws Exception {
    List<File> files = new ArrayList<File>();
    File testSrc = new File(System.getProperty("test.src"));
    for (File f: testSrc.listFiles()) {
        if (f.isFile() && f.getName().endsWith(".java"))
            files.add(f);
    }

    JavacTool javac = JavacTool.create();
    try (StandardJavaFileManager fm = javac.getStandardFileManager(null, null, null)) {

        Iterable<? extends JavaFileObject> fos = fm.getJavaFileObjectsFromFiles(files);

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

        Iterable<? extends CompilationUnitTree> units = t.parse();

        DeclScanner ds = new DeclScanner(trees);
        for (CompilationUnitTree unit: units) {
            ds.scan(unit, null);
        }

        if (errors > 0)
            throw new Exception(errors + " errors occurred");
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:28,代码来源:DocTreePathScannerTest.java

示例11: run

import com.sun.source.util.DocTrees; //导入方法依赖的package包/类
void run() throws Exception {
    List<File> files = new ArrayList<File>();
    File testSrc = new File(System.getProperty("test.src"));
    for (File f: testSrc.listFiles()) {
        if (f.isFile() && f.getName().endsWith(".java"))
            files.add(f);
    }

    JavacTool javac = JavacTool.create();
    try (StandardJavaFileManager fm = javac.getStandardFileManager(null, null, null)) {

        Iterable<? extends JavaFileObject> fos = fm.getJavaFileObjectsFromFiles(files);

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

        Iterable<? extends CompilationUnitTree> units = t.parse();

        Set<DocTree.Kind> found = EnumSet.noneOf(DocTree.Kind.class);
        DeclScanner ds = new DeclScanner(trees, found);
        for (CompilationUnitTree unit: units) {
            ds.scan(unit, null);
        }

        for (DocTree.Kind k: DocTree.Kind.values()) {
            if (!found.contains(k) && k != DocTree.Kind.OTHER)
                error("not found: " + k);
        }

        if (errors > 0)
            throw new Exception(errors + " errors occurred");
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:34,代码来源:SimpleDocTreeVisitorTest.java

示例12: run

import com.sun.source.util.DocTrees; //导入方法依赖的package包/类
void run() throws Exception {
    List<File> files = new ArrayList<File>();
    File testSrc = new File(System.getProperty("test.src"));
    for (File f: testSrc.listFiles()) {
        if (f.isFile() && f.getName().endsWith(".java"))
            files.add(f);
    }

    JavacTool javac = JavacTool.create();
    StandardJavaFileManager fm = javac.getStandardFileManager(null, null, null);

    Iterable<? extends JavaFileObject> fos = fm.getJavaFileObjectsFromFiles(files);

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

    Iterable<? extends CompilationUnitTree> units = t.parse();

    Set<DocTree.Kind> found = EnumSet.noneOf(DocTree.Kind.class);
    DeclScanner ds = new DeclScanner(trees, found);
    for (CompilationUnitTree unit: units) {
        ds.scan(unit, null);
    }

    for (DocTree.Kind k: DocTree.Kind.values()) {
        if (!found.contains(k) && k != DocTree.Kind.OTHER)
            error("not found: " + k);
    }

    if (errors > 0)
        throw new Exception(errors + " errors occurred");
}
 
开发者ID:ojdkbuild,项目名称:lookaside_java-1.8.0-openjdk,代码行数:33,代码来源:SimpleDocTreeVisitorTest.java

示例13: init

import com.sun.source.util.DocTrees; //导入方法依赖的package包/类
@Override
public synchronized void init(ProcessingEnvironment processingEnv) {
  super.init(processingEnv);
  String sourceOpt = processingEnv.getOptions().get("docgen.source");
  if (sourceOpt != null) {
    sources = new ArrayList<>(Arrays.asList(sourceOpt.split("\\s*,\\s*")));
  }
  docTrees = DocTrees.instance(processingEnv);
  helper = new Helper(processingEnv);
  registerPostProcessor(new LanguageFilterPostProcessor());
}
 
开发者ID:vert-x3,项目名称:vertx-docgen,代码行数:12,代码来源:BaseProcessor.java

示例14: getThrownException

import com.sun.source.util.DocTrees; //导入方法依赖的package包/类
private String getThrownException(JavacTask task, TreePath rootOn, DocCommentTree comment, ThrowsTree tt) {
    DocTrees trees = DocTrees.instance(task);
    Element exc = trees.getElement(new DocTreePath(new DocTreePath(rootOn, comment), tt.getExceptionName()));
    return exc != null ? exc.toString() : null;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:6,代码来源:JavadocHelper.java

示例15: init

import com.sun.source.util.DocTrees; //导入方法依赖的package包/类
@Override
public void init(ProcessingEnvironment pEnv) {
    super.init(pEnv);
    trees = DocTrees.instance(pEnv);
    messager = pEnv.getMessager();
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:7,代码来源:DocCommentProcessor.java


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