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


Java JavacTaskImpl.generate方法代码示例

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


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

示例1: run

import com.sun.tools.javac.api.JavacTaskImpl; //导入方法依赖的package包/类
public void run(JavaCompiler comp) {
    JavaSource source = new JavaSource();
    JavacTaskImpl ct = (JavacTaskImpl)comp.getTask(null, null, dc,
            Arrays.asList("-g"), null, Arrays.asList(source));
    Context context = ct.getContext();
    Symtab syms = Symtab.instance(context);
    Names names = Names.instance(context);
    Types types = Types.instance(context);
    ct.addTaskListener(new Indifier(syms, names, types));
    try {
        ct.generate();
    } catch (Throwable t) {
        t.printStackTrace();
        throw new AssertionError(
                String.format("Error thrown when compiling following code\n%s",
                        source.source));
    }
    if (dc.diagFound) {
        throw new AssertionError(
                String.format("Diags found when compiling following code\n%s\n\n%s",
                        source.source, dc.printDiags()));
    }
    verifyBytecode();
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:25,代码来源:TestBootstrapMethodsCount.java

示例2: testParseEnterAnalyze

import com.sun.tools.javac.api.JavacTaskImpl; //导入方法依赖的package包/类
@Test
public void testParseEnterAnalyze(Path base) throws Exception {
    JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
    try (StandardJavaFileManager fm = compiler.getStandardFileManager(null, null, null)) {
        Path moduleSrc = base.resolve("module-src");
        Path m1 = moduleSrc.resolve("m1x");

        tb.writeJavaFiles(m1, "module m1x { }",
                              "package p;",
                              "package p; class T { }");

        Path classes = base.resolve("classes");
        Iterable<? extends JavaFileObject> files = fm.getJavaFileObjects(findJavaFiles(moduleSrc));
        List<String> options = Arrays.asList("-d", classes.toString(), "-Xpkginfo:always");
        JavacTaskImpl task = (JavacTaskImpl) compiler.getTask(null, fm, null, options, null, files);

        Iterable<? extends CompilationUnitTree> parsed = task.parse();
        Iterable<? extends Element> entered = task.enter(parsed);
        Iterable<? extends Element> analyzed = task.analyze(entered);
        Iterable<? extends JavaFileObject> generatedFiles = task.generate(analyzed);

        Set<String> generated = new HashSet<>();

        for (JavaFileObject jfo : generatedFiles) {
            generated.add(jfo.getName());
        }

        Set<String> expected = new HashSet<>(
                Arrays.asList(Paths.get("testParseEnterAnalyze", "classes", "p", "package-info.class").toString(),
                              Paths.get("testParseEnterAnalyze", "classes", "module-info.class").toString(),
                              Paths.get("testParseEnterAnalyze", "classes", "p", "T.class").toString())
        );

        if (!Objects.equals(expected, generated))
            throw new AssertionError("Incorrect generated files: " + generated);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:38,代码来源:EdgeCases.java


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