Java Code Examples for com.sun.source.util.JavacTask#generate()

The following examples show how to use com.sun.source.util.JavacTask#generate() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JavacTemplateTestBase.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
private File compile(List<File> classpaths, List<JavaFileObject> files, boolean generate) throws IOException {
    JavaCompiler systemJavaCompiler = ToolProvider.getSystemJavaCompiler();
    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;
    }
}
 
Example 2
Source File: T6410706.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
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();
    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");
}
 
Example 3
Source File: JavacTemplateTestBase.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
private File compile(List<File> classpaths, List<JavaFileObject> files, boolean generate) throws IOException {
    JavaCompiler systemJavaCompiler = ToolProvider.getSystemJavaCompiler();
    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;
    }
}
 
Example 4
Source File: JavacTemplateTestBase.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
private File compile(List<File> classpaths, List<JavaFileObject> files, boolean generate) throws IOException {
    JavaCompiler systemJavaCompiler = ToolProvider.getSystemJavaCompiler();
    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;
    }
}
 
Example 5
Source File: JavacTemplateTestBase.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
private File compile(List<File> classpaths, List<JavaFileObject> files, boolean generate) throws IOException {
    JavaCompiler systemJavaCompiler = ToolProvider.getSystemJavaCompiler();
    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;
    }
}
 
Example 6
Source File: JavacTemplateTestBase.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
private File compile(List<File> classpaths, List<JavaFileObject> files, boolean generate) throws IOException {
    JavaCompiler systemJavaCompiler = ToolProvider.getSystemJavaCompiler();
    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;
    }
}
 
Example 7
Source File: T6410706.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
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();
    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");
}
 
Example 8
Source File: T6410706.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
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();
    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");
}
 
Example 9
Source File: JavacTemplateTestBase.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
private File compile(List<File> classpaths, List<JavaFileObject> files, boolean generate) throws IOException {
    JavaCompiler systemJavaCompiler = ToolProvider.getSystemJavaCompiler();
    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;
    }
}
 
Example 10
Source File: T6410706.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
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();
    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");
}
 
Example 11
Source File: T6410706.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
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();
    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");
}
 
Example 12
Source File: T6199075.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
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);
}
 
Example 13
Source File: T6199075.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
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);
}
 
Example 14
Source File: TestLambdaToMethodStats.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
public void run() {
    JavacTask ct = (JavacTask)comp.getTask(null, fm.get(), diagChecker,
            Arrays.asList("-XDdumpLambdaToMethodStats"),
            null, Arrays.asList(source));
    try {
        ct.generate();
    } catch (Throwable ex) {
        throw new
            AssertionError("Error thron when analyzing the following source:\n" +
                source.getCharContent(true));
    }
    check();
}
 
Example 15
Source File: TestSimpleAddRemove.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
void run(JavacTask t) throws IOException {
    t.generate();
}
 
Example 16
Source File: TestSimpleAddRemove.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
void run(JavacTask t) throws IOException {
    t.generate();
}
 
Example 17
Source File: TestSimpleAddRemove.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
void run(JavacTask t) throws IOException {
    t.generate();
}
 
Example 18
Source File: TestSimpleAddRemove.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
void run(JavacTask t) throws IOException {
    t.generate();
}
 
Example 19
Source File: TestSimpleAddRemove.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
void run(JavacTask t) throws IOException {
    t.generate();
}
 
Example 20
Source File: TestSimpleAddRemove.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
void run(JavacTask t) throws IOException {
    t.generate();
}