Java Code Examples for com.sun.tools.javac.file.JavacFileManager#setContext()

The following examples show how to use com.sun.tools.javac.file.JavacFileManager#setContext() . 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: T6358168.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
static void testNoAnnotationProcessing(JavacFileManager fm, JavaFileObject f) throws Throwable {
    Context context = new Context();
    fm.setContext(context);

    Main compilerMain = new Main("javac", new PrintWriter(System.err, true));
    compilerMain.setOptions(Options.instance(context));
    compilerMain.filenames = new LinkedHashSet<File>();
    compilerMain.processArgs(new String[] { "-d", "." });

    JavaCompiler compiler = JavaCompiler.instance(context);
    compiler.compile(List.of(f));
    try {
        compiler.compile(List.of(f));
        throw new Error("Error: AssertionError not thrown after second call of compile");
    } catch (AssertionError e) {
        System.err.println("Exception from compiler (expected): " + e);
    }
}
 
Example 2
Source File: T6358168.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
static void testNoAnnotationProcessing(JavacFileManager fm, JavaFileObject f) throws Throwable {
    Context context = new Context();
    fm.setContext(context);

    Main compilerMain = new Main("javac", new PrintWriter(System.err, true));
    compilerMain.setOptions(Options.instance(context));
    compilerMain.filenames = new LinkedHashSet<File>();
    compilerMain.processArgs(new String[] { "-d", "." });

    JavaCompiler compiler = JavaCompiler.instance(context);
    compiler.compile(List.of(f));
    try {
        compiler.compile(List.of(f));
        throw new Error("Error: AssertionError not thrown after second call of compile");
    } catch (AssertionError e) {
        System.err.println("Exception from compiler (expected): " + e);
    }
}
 
Example 3
Source File: T6358166.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
static void test(JavacFileManager fm, JavaFileObject f, String... args) throws Throwable {
    Context context = new Context();
    fm.setContext(context);

    Main compilerMain = new Main("javac", new PrintWriter(System.err, true));
    compilerMain.setOptions(Options.instance(context));
    compilerMain.filenames = new LinkedHashSet<File>();
    compilerMain.processArgs(args);

    JavaCompiler c = JavaCompiler.instance(context);

    c.compile(List.of(f));

    if (c.errorCount() != 0)
        throw new AssertionError("compilation failed");

    long msec = c.elapsed_msec;
    if (msec < 0 || msec > 5 * 60 * 1000) // allow test 5 mins to execute, should be more than enough!
        throw new AssertionError("elapsed time is suspect: " + msec);
}
 
Example 4
Source File: T6358168.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
static void testAnnotationProcessing(JavacFileManager fm, JavaFileObject f) throws Throwable {
    Context context = new Context();
    fm.setContext(context);

    Main compilerMain = new Main("javac", new PrintWriter(System.err, true));
    compilerMain.setOptions(Options.instance(context));
    compilerMain.filenames = new LinkedHashSet<File>();
    compilerMain.processArgs(new String[] {
                                 "-XprintRounds",
                                 "-processorpath", testClasses,
                                 "-processor", self,
                                 "-d", "."});

    JavaCompiler compiler = JavaCompiler.instance(context);
    compiler.initProcessAnnotations(null);
    JavaCompiler compiler2 = compiler.processAnnotations(compiler.enterTrees(compiler.parseFiles(List.of(f))));
    try {
        compiler2.compile(List.of(f));
        throw new Error("Error: AssertionError not thrown after second call of compile");
    } catch (AssertionError e) {
        System.err.println("Exception from compiler (expected): " + e);
    }
}
 
Example 5
Source File: T6358168.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
static void testNoAnnotationProcessing(JavacFileManager fm, JavaFileObject f) throws Throwable {
    Context context = new Context();
    fm.setContext(context);

    Main compilerMain = new Main("javac", new PrintWriter(System.err, true));
    compilerMain.setOptions(Options.instance(context));
    compilerMain.filenames = new LinkedHashSet<File>();
    compilerMain.processArgs(new String[] { "-d", "." });

    JavaCompiler compiler = JavaCompiler.instance(context);
    compiler.compile(List.of(f));
    try {
        compiler.compile(List.of(f));
        throw new Error("Error: AssertionError not thrown after second call of compile");
    } catch (AssertionError e) {
        System.err.println("Exception from compiler (expected): " + e);
    }
}
 
Example 6
Source File: T6358166.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
static void test(JavacFileManager fm, JavaFileObject f, String... args) throws Throwable {
    Context context = new Context();
    fm.setContext(context);

    Main compilerMain = new Main("javac", new PrintWriter(System.err, true));
    compilerMain.setOptions(Options.instance(context));
    compilerMain.filenames = new LinkedHashSet<File>();
    compilerMain.processArgs(args);

    JavaCompiler c = JavaCompiler.instance(context);

    c.compile(List.of(f));

    if (c.errorCount() != 0)
        throw new AssertionError("compilation failed");

    long msec = c.elapsed_msec;
    if (msec < 0 || msec > 5 * 60 * 1000) // allow test 5 mins to execute, should be more than enough!
        throw new AssertionError("elapsed time is suspect: " + msec);
}
 
Example 7
Source File: T6358168.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
static void testAnnotationProcessing(JavacFileManager fm, JavaFileObject f) throws Throwable {
    Context context = new Context();
    fm.setContext(context);

    Main compilerMain = new Main("javac", new PrintWriter(System.err, true));
    compilerMain.setOptions(Options.instance(context));
    compilerMain.filenames = new LinkedHashSet<File>();
    compilerMain.processArgs(new String[] {
                                 "-XprintRounds",
                                 "-processorpath", testClasses,
                                 "-processor", self,
                                 "-d", "."});

    JavaCompiler compiler = JavaCompiler.instance(context);
    compiler.initProcessAnnotations(null);
    JavaCompiler compiler2 = compiler.processAnnotations(compiler.enterTrees(compiler.parseFiles(List.of(f))));
    try {
        compiler2.compile(List.of(f));
        throw new Error("Error: AssertionError not thrown after second call of compile");
    } catch (AssertionError e) {
        System.err.println("Exception from compiler (expected): " + e);
    }
}
 
Example 8
Source File: T6358168.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
static void testNoAnnotationProcessing(JavacFileManager fm, JavaFileObject f) throws Throwable {
    Context context = new Context();
    fm.setContext(context);

    Main compilerMain = new Main("javac", new PrintWriter(System.err, true));
    compilerMain.setOptions(Options.instance(context));
    compilerMain.filenames = new LinkedHashSet<File>();
    compilerMain.processArgs(new String[] { "-d", "." });

    JavaCompiler compiler = JavaCompiler.instance(context);
    compiler.compile(List.of(f));
    try {
        compiler.compile(List.of(f));
        throw new Error("Error: AssertionError not thrown after second call of compile");
    } catch (AssertionError e) {
        System.err.println("Exception from compiler (expected): " + e);
    }
}
 
Example 9
Source File: T6358166.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
static void test(JavacFileManager fm, JavaFileObject f, String... args) throws Throwable {
    Context context = new Context();
    fm.setContext(context);

    Main compilerMain = new Main("javac", new PrintWriter(System.err, true));
    compilerMain.setOptions(Options.instance(context));
    compilerMain.filenames = new LinkedHashSet<File>();
    compilerMain.processArgs(args);

    JavaCompiler c = JavaCompiler.instance(context);

    c.compile(List.of(f));

    if (c.errorCount() != 0)
        throw new AssertionError("compilation failed");

    long msec = c.elapsed_msec;
    if (msec < 0 || msec > 5 * 60 * 1000) // allow test 5 mins to execute, should be more than enough!
        throw new AssertionError("elapsed time is suspect: " + msec);
}
 
Example 10
Source File: T6358168.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
static void testAnnotationProcessing(JavacFileManager fm, JavaFileObject f) throws Throwable {
    Context context = new Context();
    fm.setContext(context);

    Main compilerMain = new Main("javac", new PrintWriter(System.err, true));
    compilerMain.setOptions(Options.instance(context));
    compilerMain.filenames = new LinkedHashSet<File>();
    compilerMain.processArgs(new String[] {
                                 "-XprintRounds",
                                 "-processorpath", testClasses,
                                 "-processor", self,
                                 "-d", "."});

    JavaCompiler compiler = JavaCompiler.instance(context);
    compiler.initProcessAnnotations(null);
    JavaCompiler compiler2 = compiler.processAnnotations(compiler.enterTrees(compiler.parseFiles(List.of(f))));
    try {
        compiler2.compile(List.of(f));
        throw new Error("Error: AssertionError not thrown after second call of compile");
    } catch (AssertionError e) {
        System.err.println("Exception from compiler (expected): " + e);
    }
}
 
Example 11
Source File: T6358166.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
static void test(JavacFileManager fm, JavaFileObject f, String... args) throws Throwable {
    Context context = new Context();
    fm.setContext(context);

    Main compilerMain = new Main("javac", new PrintWriter(System.err, true));
    compilerMain.setOptions(Options.instance(context));
    compilerMain.filenames = new LinkedHashSet<File>();
    compilerMain.processArgs(args);

    JavaCompiler c = JavaCompiler.instance(context);

    c.compile(List.of(f));

    if (c.errorCount() != 0)
        throw new AssertionError("compilation failed");

    long msec = c.elapsed_msec;
    if (msec < 0 || msec > 5 * 60 * 1000) // allow test 5 mins to execute, should be more than enough!
        throw new AssertionError("elapsed time is suspect: " + msec);
}
 
Example 12
Source File: T6358166.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
static void test(JavacFileManager fm, JavaFileObject f, String... args) throws Throwable {
    Context context = new Context();
    fm.setContext(context);

    Main compilerMain = new Main("javac", new PrintWriter(System.err, true));
    compilerMain.setOptions(Options.instance(context));
    compilerMain.filenames = new LinkedHashSet<File>();
    compilerMain.processArgs(args);

    JavaCompiler c = JavaCompiler.instance(context);

    c.compile(List.of(f));

    if (c.errorCount() != 0)
        throw new AssertionError("compilation failed");

    long msec = c.elapsed_msec;
    if (msec < 0 || msec > 5 * 60 * 1000) // allow test 5 mins to execute, should be more than enough!
        throw new AssertionError("elapsed time is suspect: " + msec);
}
 
Example 13
Source File: T6358168.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
static void testAnnotationProcessing(JavacFileManager fm, JavaFileObject f) throws Throwable {
    Context context = new Context();
    fm.setContext(context);

    Main compilerMain = new Main("javac", new PrintWriter(System.err, true));
    compilerMain.setOptions(Options.instance(context));
    compilerMain.filenames = new LinkedHashSet<File>();
    compilerMain.processArgs(new String[] {
                                 "-XprintRounds",
                                 "-processorpath", testClasses,
                                 "-processor", self,
                                 "-d", "."});

    JavaCompiler compiler = JavaCompiler.instance(context);
    compiler.initProcessAnnotations(null);
    JavaCompiler compiler2 = compiler.processAnnotations(compiler.enterTrees(compiler.parseFiles(List.of(f))));
    try {
        compiler2.compile(List.of(f));
        throw new Error("Error: AssertionError not thrown after second call of compile");
    } catch (AssertionError e) {
        System.err.println("Exception from compiler (expected): " + e);
    }
}
 
Example 14
Source File: T6358168.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
static void testNoAnnotationProcessing(JavacFileManager fm, JavaFileObject f) throws Throwable {
    Context context = new Context();
    fm.setContext(context);

    Main compilerMain = new Main("javac", new PrintWriter(System.err, true));
    compilerMain.setOptions(Options.instance(context));
    compilerMain.filenames = new LinkedHashSet<File>();
    compilerMain.processArgs(new String[] { "-d", "." });

    JavaCompiler compiler = JavaCompiler.instance(context);
    compiler.compile(List.of(f));
    try {
        compiler.compile(List.of(f));
        throw new Error("Error: AssertionError not thrown after second call of compile");
    } catch (AssertionError e) {
        System.err.println("Exception from compiler (expected): " + e);
    }
}
 
Example 15
Source File: T6358166.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
static void test(JavacFileManager fm, JavaFileObject f, String... args) throws Throwable {
    Context context = new Context();
    fm.setContext(context);

    Main compilerMain = new Main("javac", new PrintWriter(System.err, true));
    compilerMain.setOptions(Options.instance(context));
    compilerMain.filenames = new LinkedHashSet<File>();
    compilerMain.processArgs(args);

    JavaCompiler c = JavaCompiler.instance(context);

    c.compile(List.of(f));

    if (c.errorCount() != 0)
        throw new AssertionError("compilation failed");

    long msec = c.elapsed_msec;
    if (msec < 0 || msec > 5 * 60 * 1000) // allow test 5 mins to execute, should be more than enough!
        throw new AssertionError("elapsed time is suspect: " + msec);
}
 
Example 16
Source File: T6358168.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
static void testAnnotationProcessing(JavacFileManager fm, JavaFileObject f) throws Throwable {
    Context context = new Context();
    fm.setContext(context);

    Main compilerMain = new Main("javac", new PrintWriter(System.err, true));
    compilerMain.setOptions(Options.instance(context));
    compilerMain.filenames = new LinkedHashSet<File>();
    compilerMain.processArgs(new String[] {
                                 "-XprintRounds",
                                 "-processorpath", testClasses,
                                 "-processor", self,
                                 "-d", "."});

    JavaCompiler compiler = JavaCompiler.instance(context);
    compiler.initProcessAnnotations(null);
    JavaCompiler compiler2 = compiler.processAnnotations(compiler.enterTrees(compiler.parseFiles(List.of(f))));
    try {
        compiler2.compile(List.of(f));
        throw new Error("Error: AssertionError not thrown after second call of compile");
    } catch (AssertionError e) {
        System.err.println("Exception from compiler (expected): " + e);
    }
}
 
Example 17
Source File: T6358168.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
static void testNoAnnotationProcessing(JavacFileManager fm, JavaFileObject f) throws Throwable {
    Context context = new Context();
    fm.setContext(context);

    Main compilerMain = new Main("javac", new PrintWriter(System.err, true));
    compilerMain.setOptions(Options.instance(context));
    compilerMain.filenames = new LinkedHashSet<File>();
    compilerMain.processArgs(new String[] { "-d", "." });

    JavaCompiler compiler = JavaCompiler.instance(context);
    compiler.compile(List.of(f));
    try {
        compiler.compile(List.of(f));
        throw new Error("Error: AssertionError not thrown after second call of compile");
    } catch (AssertionError e) {
        System.err.println("Exception from compiler (expected): " + e);
    }
}
 
Example 18
Source File: T6358166.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
static void test(JavacFileManager fm, JavaFileObject f, String... args) throws Throwable {
    Context context = new Context();
    fm.setContext(context);

    Main compilerMain = new Main("javac", new PrintWriter(System.err, true));
    compilerMain.setOptions(Options.instance(context));
    compilerMain.filenames = new LinkedHashSet<File>();
    compilerMain.processArgs(args);

    JavaCompiler c = JavaCompiler.instance(context);

    c.compile(List.of(f));

    if (c.errorCount() != 0)
        throw new AssertionError("compilation failed");

    long msec = c.elapsed_msec;
    if (msec < 0 || msec > 5 * 60 * 1000) // allow test 5 mins to execute, should be more than enough!
        throw new AssertionError("elapsed time is suspect: " + msec);
}
 
Example 19
Source File: T6358168.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
static void testAnnotationProcessing(JavacFileManager fm, JavaFileObject f) throws Throwable {
    Context context = new Context();
    fm.setContext(context);

    Main compilerMain = new Main("javac", new PrintWriter(System.err, true));
    compilerMain.setOptions(Options.instance(context));
    compilerMain.filenames = new LinkedHashSet<File>();
    compilerMain.processArgs(new String[] {
                                 "-XprintRounds",
                                 "-processorpath", testClasses,
                                 "-processor", self,
                                 "-d", "."});

    JavaCompiler compiler = JavaCompiler.instance(context);
    compiler.initProcessAnnotations(null);
    JavaCompiler compiler2 = compiler.processAnnotations(compiler.enterTrees(compiler.parseFiles(List.of(f))));
    try {
        compiler2.compile(List.of(f));
        throw new Error("Error: AssertionError not thrown after second call of compile");
    } catch (AssertionError e) {
        System.err.println("Exception from compiler (expected): " + e);
    }
}
 
Example 20
Source File: T6358168.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
static void testNoAnnotationProcessing(JavacFileManager fm, JavaFileObject f) throws Throwable {
    Context context = new Context();
    fm.setContext(context);

    Main compilerMain = new Main("javac", new PrintWriter(System.err, true));
    compilerMain.setOptions(Options.instance(context));
    compilerMain.filenames = new LinkedHashSet<File>();
    compilerMain.processArgs(new String[] { "-d", "." });

    JavaCompiler compiler = JavaCompiler.instance(context);
    compiler.compile(List.of(f));
    try {
        compiler.compile(List.of(f));
        throw new Error("Error: AssertionError not thrown after second call of compile");
    } catch (AssertionError e) {
        System.err.println("Exception from compiler (expected): " + e);
    }
}