當前位置: 首頁>>代碼示例>>Java>>正文


Java JavacTask.generate方法代碼示例

本文整理匯總了Java中com.sun.source.util.JavacTask.generate方法的典型用法代碼示例。如果您正苦於以下問題:Java JavacTask.generate方法的具體用法?Java JavacTask.generate怎麽用?Java JavacTask.generate使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.sun.source.util.JavacTask的用法示例。


在下文中一共展示了JavacTask.generate方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: compile

import com.sun.source.util.JavacTask; //導入方法依賴的package包/類
private File compile(List<File> classpaths, List<JavaFileObject> files, boolean generate) throws IOException {
    JavaCompiler systemJavaCompiler = ToolProvider.getSystemJavaCompiler();
    try (StandardJavaFileManager fm = systemJavaCompiler.getStandardFileManager(null, null, null)) {
        if (classpaths.size() > 0)
            fm.setLocation(StandardLocation.CLASS_PATH, classpaths);
        JavacTask ct = (JavacTask) systemJavaCompiler.getTask(null, fm, diags, compileOptions, null, files);
        if (generate) {
            File destDir = new File(root, Integer.toString(counter.incrementAndGet()));
            // @@@ Assert that this directory didn't exist, or start counter at max+1
            destDir.mkdirs();
            fm.setLocation(StandardLocation.CLASS_OUTPUT, Arrays.asList(destDir));
            ct.generate();
            return destDir;
        }
        else {
            ct.analyze();
            return nullDir;
        }
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:21,代碼來源:JavacTemplateTestBase.java

示例2: main

import com.sun.source.util.JavacTask; //導入方法依賴的package包/類
public static void main(String... args) throws IOException {
    String testSrc = System.getProperty("test.src", ".");
    String testClasses = System.getProperty("test.classes", ".");
    JavacTool tool = JavacTool.create();
    MyDiagListener dl = new MyDiagListener();
    try (StandardJavaFileManager fm = tool.getStandardFileManager(dl, null, null)) {
        fm.setLocation(StandardLocation.CLASS_OUTPUT, Arrays.asList(new File(testClasses)));
        Iterable<? extends JavaFileObject> files =
            fm.getJavaFileObjectsFromFiles(Arrays.asList(new File(testSrc, T6410706.class.getName()+".java")));
        JavacTask task = tool.getTask(null, fm, dl, null, null, files);
        task.parse();
        task.analyze();
        task.generate();

        // expect 2 notes:
        // Note: T6410706.java uses or overrides a deprecated API.
        // Note: Recompile with -Xlint:deprecation for details.

        if (dl.notes != 2)
            throw new AssertionError(dl.notes + " notes given");
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:23,代碼來源:T6410706.java

示例3: runTest

import com.sun.source.util.JavacTask; //導入方法依賴的package包/類
private void runTest(String code, String expectedDesugar) throws Exception {
    List<JavaFileObject> files = List.nil();

    for (String file : code.split("---")) {
        files = files.prepend(new ToolBox.JavaSource(file));
    }

    Path classes = Paths.get("classes");

    if (Files.exists(classes)) {
        tb.cleanDirectory(classes);
    } else {
        Files.createDirectories(classes);
    }

    JavacTool compiler = (JavacTool) ToolProvider.getSystemJavaCompiler();
    StringWriter out = new StringWriter();
    Context context = new Context();
    TestLower.preRegister(context);
    Iterable<String> options = Arrays.asList("-d", classes.toString());
    JavacTask task = (JavacTask) compiler.getTask(out, null, null, options, null, files, context);

    task.generate();

    out.flush();

    String actual = out.toString().replace(System.getProperty("line.separator"), "\n");

    if (!expectedDesugar.equals(actual)) {
        throw new IllegalStateException("Actual does not match expected: " + actual);
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:33,代碼來源:BoxingAndSuper.java

示例4: compileAndCheck

import com.sun.source.util.JavacTask; //導入方法依賴的package包/類
void compileAndCheck(VarargsMethod m1, VarargsMethod m2, TypeKind actual, ArgumentsArity argsArity) throws Exception {
    final JavaCompiler tool = ToolProvider.getSystemJavaCompiler();
    JavaSource source = new JavaSource(m1, m2, actual, argsArity);
    ErrorChecker ec = new ErrorChecker();
    JavacTask ct = (JavacTask)tool.getTask(null, fm, ec,
            null, null, Arrays.asList(source));
    ct.generate();
    check(source, ec, m1, m2, actual, argsArity);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:10,代碼來源:T6199075.java

示例5: run

import com.sun.source.util.JavacTask; //導入方法依賴的package包/類
void run(JavacTask t) throws IOException {
    t.generate();
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:4,代碼來源:TestSimpleAddRemove.java


注:本文中的com.sun.source.util.JavacTask.generate方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。