Java Code Examples for com.sun.source.util.JavacTask#setProcessors()
The following examples show how to use
com.sun.source.util.JavacTask#setProcessors() .
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: LVTHarness.java From openjdk-8-source with GNU General Public License v2.0 | 6 votes |
protected void check() throws Exception { JavacTask ct = (JavacTask) comp.getTask(null, fm, null, Arrays.asList("-g"), null, Arrays.asList(jfo)); System.err.println("compiling code " + jfo); ct.setProcessors(Collections.singleton(new AliveRangeFinder())); if (!ct.call()) { throw new AssertionError("Error during compilation"); } File javaFile = new File(jfo.getName()); File classFile = new File(javaFile.getName().replace(".java", ".class")); checkClassFile(classFile); //check all candidates have been used up for (Map.Entry<ElementKey, AliveRanges> entry : aliveRangeMap.entrySet()) { if (!seenAliveRanges.contains(entry.getKey())) { error("Redundant @AliveRanges annotation on method " + entry.getKey().elem); } } }
Example 2
Source File: LVTHarness.java From openjdk-8 with GNU General Public License v2.0 | 6 votes |
protected void check() throws Exception { JavacTask ct = (JavacTask) comp.getTask(null, fm, null, Arrays.asList("-g"), null, Arrays.asList(jfo)); System.err.println("compiling code " + jfo); ct.setProcessors(Collections.singleton(new AliveRangeFinder())); if (!ct.call()) { throw new AssertionError("Error during compilation"); } File javaFile = new File(jfo.getName()); File classFile = new File(javaFile.getName().replace(".java", ".class")); checkClassFile(classFile); //check all candidates have been used up for (Map.Entry<ElementKey, AliveRanges> entry : aliveRangeMap.entrySet()) { if (!seenAliveRanges.contains(entry.getKey())) { error("Redundant @AliveRanges annotation on method " + entry.getKey().elem); } } }
Example 3
Source File: LVTHarness.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
protected void check() throws Exception { JavacTask ct = (JavacTask) comp.getTask(null, fm, null, Arrays.asList("-g"), null, Arrays.asList(jfo)); System.err.println("compiling code " + jfo); ct.setProcessors(Collections.singleton(new AliveRangeFinder())); if (!ct.call()) { throw new AssertionError("Error during compilation"); } File javaFile = new File(jfo.getName()); File classFile = new File(javaFile.getName().replace(".java", ".class")); checkClassFile(classFile); //check all candidates have been used up for (Map.Entry<ElementKey, AliveRanges> entry : aliveRangeMap.entrySet()) { if (!seenAliveRanges.contains(entry.getKey())) { error("Redundant @AliveRanges annotation on method " + entry.getKey().elem + " with key " + entry.getKey()); } } }
Example 4
Source File: TestGetScope.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
public void run() { File srcDir = new File(System.getProperty("test.src")); File thisFile = new File(srcDir, getClass().getName() + ".java"); JavaCompiler c = ToolProvider.getSystemJavaCompiler(); StandardJavaFileManager fm = c.getStandardFileManager(null, null, null); List<String> opts = Arrays.asList("-proc:only", "-doe"); Iterable<? extends JavaFileObject> files = fm.getJavaFileObjects(thisFile); JavacTask t = (JavacTask) c.getTask(null, fm, null, opts, null, files); t.setProcessors(Collections.singleton(this)); boolean ok = t.call(); if (!ok) throw new Error("compilation failed"); }
Example 5
Source File: TestContainTypes.java From hottub with GNU General Public License v2.0 | 5 votes |
static void compileAndCheck(ParameterType ptA, ClassType ctA, ParameterType ptB, ClassType ctB) throws Exception { JavaSource source = new JavaSource(ptA.instantiate(ctA), ptB.instantiate(ctB)); final JavaCompiler tool = ToolProvider.getSystemJavaCompiler(); JavacTask ct = (JavacTask)tool.getTask(null, null, null, null, null, Arrays.asList(source)); ct.setProcessors(Arrays.asList(new ContainTypesTester(ParameterType.contains(ptA, ctA, ptB, ctB), source))); System.err.println("A = " + ptA +" / " + ptA.instantiate(ctA)); System.err.println("B = " + ptB +" / " + ptB.instantiate(ctB)); System.err.println("Source = " + source.source); ct.analyze(); }
Example 6
Source File: Test.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
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); }
Example 7
Source File: ResolveHarness.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
protected void check() throws Exception { String[] options = { "-XDshouldStopPolicy=ATTR", "-XDverboseResolution=success,failure,applicable,inapplicable,deferred-inference,predef" }; AbstractProcessor[] processors = { new ResolveCandidateFinder(), null }; @SuppressWarnings("unchecked") DiagnosticListener<? super JavaFileObject>[] diagListeners = new DiagnosticListener[] { new DiagnosticHandler(false), new DiagnosticHandler(true) }; for (int i = 0 ; i < options.length ; i ++) { JavacTask ct = (JavacTask)comp.getTask(null, fm, diagListeners[i], Arrays.asList(options[i]), null, Arrays.asList(jfo)); if (processors[i] != null) { ct.setProcessors(Collections.singleton(processors[i])); } ct.analyze(); } //check diags for (Diagnostic<? extends JavaFileObject> diag : diags) { for (DiagnosticProcessor proc : diagProcessors) { if (proc.matches(diag)) { proc.process(diag); break; } } } //check all candidates have been used up for (Map.Entry<ElementKey, Candidate> entry : candidatesMap.entrySet()) { if (!seenCandidates.contains(entry.getKey())) { error("Redundant @Candidate annotation on method " + entry.getKey().elem + " sig = " + entry.getKey().elem.asType()); } } }
Example 8
Source File: TestGetScope.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
public void run() { File srcDir = new File(System.getProperty("test.src")); File thisFile = new File(srcDir, getClass().getName() + ".java"); JavaCompiler c = ToolProvider.getSystemJavaCompiler(); StandardJavaFileManager fm = c.getStandardFileManager(null, null, null); List<String> opts = Arrays.asList("-proc:only", "-doe"); Iterable<? extends JavaFileObject> files = fm.getJavaFileObjects(thisFile); JavacTask t = (JavacTask) c.getTask(null, fm, null, opts, null, files); t.setProcessors(Collections.singleton(this)); boolean ok = t.call(); if (!ok) throw new Error("compilation failed"); }
Example 9
Source File: Test.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
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); }
Example 10
Source File: TestContainTypes.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
static void compileAndCheck(ParameterType ptA, ClassType ctA, ParameterType ptB, ClassType ctB) throws Exception { JavaSource source = new JavaSource(ptA.instantiate(ctA), ptB.instantiate(ctB)); final JavaCompiler tool = ToolProvider.getSystemJavaCompiler(); JavacTask ct = (JavacTask)tool.getTask(null, null, null, null, null, Arrays.asList(source)); ct.setProcessors(Arrays.asList(new ContainTypesTester(ParameterType.contains(ptA, ctA, ptB, ctB), source))); System.err.println("A = " + ptA +" / " + ptA.instantiate(ctA)); System.err.println("B = " + ptB +" / " + ptB.instantiate(ctB)); System.err.println("Source = " + source.source); ct.analyze(); }
Example 11
Source File: ResolveHarness.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
protected void check() throws Exception { String[] options = { "-XDshouldStopPolicy=ATTR", "-XDverboseResolution=success,failure,applicable,inapplicable,deferred-inference,predef" }; AbstractProcessor[] processors = { new ResolveCandidateFinder(), null }; @SuppressWarnings("unchecked") DiagnosticListener<? super JavaFileObject>[] diagListeners = new DiagnosticListener[] { new DiagnosticHandler(false), new DiagnosticHandler(true) }; for (int i = 0 ; i < options.length ; i ++) { JavacTask ct = (JavacTask)comp.getTask(null, fm, diagListeners[i], Arrays.asList(options[i]), null, Arrays.asList(jfo)); if (processors[i] != null) { ct.setProcessors(Collections.singleton(processors[i])); } ct.analyze(); } //check diags for (Diagnostic<? extends JavaFileObject> diag : diags) { for (DiagnosticProcessor proc : diagProcessors) { if (proc.matches(diag)) { proc.process(diag); break; } } } //check all candidates have been used up for (Map.Entry<ElementKey, Candidate> entry : candidatesMap.entrySet()) { if (!seenCandidates.contains(entry.getKey())) { error("Redundant @Candidate annotation on method " + entry.getKey().elem + " sig = " + entry.getKey().elem.asType()); } } }
Example 12
Source File: TestGetScope.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
public void run() { File srcDir = new File(System.getProperty("test.src")); File thisFile = new File(srcDir, getClass().getName() + ".java"); JavaCompiler c = ToolProvider.getSystemJavaCompiler(); StandardJavaFileManager fm = c.getStandardFileManager(null, null, null); List<String> opts = Arrays.asList("-proc:only", "-doe"); Iterable<? extends JavaFileObject> files = fm.getJavaFileObjects(thisFile); JavacTask t = (JavacTask) c.getTask(null, fm, null, opts, null, files); t.setProcessors(Collections.singleton(this)); boolean ok = t.call(); if (!ok) throw new Error("compilation failed"); }
Example 13
Source File: ResolveHarness.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
protected void check() throws Exception { String[] options = { "-XDshouldStopPolicy=ATTR", "-XDverboseResolution=success,failure,applicable,inapplicable,deferred-inference,predef" }; AbstractProcessor[] processors = { new ResolveCandidateFinder(), null }; @SuppressWarnings("unchecked") DiagnosticListener<? super JavaFileObject>[] diagListeners = new DiagnosticListener[] { new DiagnosticHandler(false), new DiagnosticHandler(true) }; for (int i = 0 ; i < options.length ; i ++) { JavacTask ct = (JavacTask)comp.getTask(null, fm, diagListeners[i], Arrays.asList(options[i]), null, Arrays.asList(jfo)); if (processors[i] != null) { ct.setProcessors(Collections.singleton(processors[i])); } ct.analyze(); } //check diags for (Diagnostic<? extends JavaFileObject> diag : diags) { for (DiagnosticProcessor proc : diagProcessors) { if (proc.matches(diag)) { proc.process(diag); break; } } } //check all candidates have been used up for (Map.Entry<ElementKey, Candidate> entry : candidatesMap.entrySet()) { if (!seenCandidates.contains(entry.getKey())) { error("Redundant @Candidate annotation on method " + entry.getKey().elem + " sig = " + entry.getKey().elem.asType()); } } }
Example 14
Source File: TestContainTypes.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
static void compileAndCheck(ParameterType ptA, ClassType ctA, ParameterType ptB, ClassType ctB) throws Exception { JavaSource source = new JavaSource(ptA.instantiate(ctA), ptB.instantiate(ctB)); final JavaCompiler tool = ToolProvider.getSystemJavaCompiler(); JavacTask ct = (JavacTask)tool.getTask(null, null, null, null, null, Arrays.asList(source)); ct.setProcessors(Arrays.asList(new ContainTypesTester(ParameterType.contains(ptA, ctA, ptB, ctB), source))); System.err.println("A = " + ptA +" / " + ptA.instantiate(ctA)); System.err.println("B = " + ptB +" / " + ptB.instantiate(ctB)); System.err.println("Source = " + source.source); ct.analyze(); }
Example 15
Source File: TestSuppression.java From openjdk-8-source with GNU General Public License v2.0 | 4 votes |
void test(String src, WarningKind wk, int gen) throws Exception { count++; System.err.println("Test " + count + ": wk:" + wk + " gen:" + gen + " src:" +src); File testDir = new File("test" + count); File srcDir = createDir(testDir, "src"); File gensrcDir = createDir(testDir, "gensrc"); File classesDir = createDir(testDir, "classes"); File x = writeFile(new File(srcDir, "X.java"), src); DiagListener dl = new DiagListener(); JavacTool tool = JavacTool.create(); StandardJavaFileManager fm = tool.getStandardFileManager(dl, null, null); fm.setLocation(StandardLocation.CLASS_PATH, Arrays.asList(classesDir, new File(System.getProperty("test.classes")))); fm.setLocation(StandardLocation.CLASS_OUTPUT, Collections.singleton(classesDir)); fm.setLocation(StandardLocation.SOURCE_OUTPUT, Collections.singleton(gensrcDir)); List<String> args = new ArrayList<String>(); // args.add("-XprintProcessorInfo"); args.add("-XprintRounds"); args.add("-Agen=" + gen); if (wk == WarningKind.YES) args.add("-Xlint:serial"); Iterable<? extends JavaFileObject> files = fm.getJavaFileObjects(x); StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); JavacTask task = tool.getTask(pw, fm, dl, args, null, files); task.setProcessors(Arrays.asList(new AnnoProc())); boolean ok = task.call(); pw.close(); System.err.println("ok:" + ok + " diags:" + dl.counts); if (sw.toString().length() > 0) { System.err.println("output:\n" + sw.toString()); } for (Diagnostic.Kind dk: Diagnostic.Kind.values()) { Integer v = dl.counts.get(dk); int found = (v == null) ? 0 : v; int expect = (dk == Diagnostic.Kind.WARNING && wk == WarningKind.YES) ? gen : 0; if (found != expect) { error("Unexpected value for " + dk + ": expected: " + expect + " found: " + found); } } System.err.println(); }
Example 16
Source File: TestSimpleAddRemove.java From openjdk-jdk8u with GNU General Public License v2.0 | 4 votes |
void test(CompileKind ck, AddKind ak, RemoveKind rk) throws IOException { System.err.println("Test: " + ck + " " + ak + " " + rk); File tmpDir = new File(ck + "-" + ak + "-" + rk); tmpDir.mkdirs(); fm.setLocation(StandardLocation.CLASS_OUTPUT, Arrays.asList(tmpDir)); List<String> options = new ArrayList<String>(); Iterable<? extends JavaFileObject> files = Arrays.asList(new TestSource()); StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); JavacTask task = tool.getTask(pw, fm, null, options, null, files); EventKindCounter ec = new EventKindCounter(); TaskListener listener = new TestListener(ec); boolean needProcessor = false; switch (ak) { case SET_IN_TASK: task.setTaskListener(listener); break; case ADD_IN_TASK: task.addTaskListener(listener); break; case ADD_IN_PROCESSOR: case ADD_IN_LISTENER: needProcessor = true; } switch (rk) { case REMOVE_IN_TASK: task.removeTaskListener(listener); break; case REMOVE_IN_PROCESSOR: case REMOVE_IN_LISTENER: needProcessor = true; } if (needProcessor) task.setProcessors(Arrays.asList(new TestProcessor(ak, rk, listener))); ck.run(task); System.err.println(ec); check(ck, ak, rk, ec); System.err.println(); }
Example 17
Source File: TestSuppression.java From hottub with GNU General Public License v2.0 | 4 votes |
void test(String src, WarningKind wk, int gen) throws Exception { count++; System.err.println("Test " + count + ": wk:" + wk + " gen:" + gen + " src:" +src); File testDir = new File("test" + count); File srcDir = createDir(testDir, "src"); File gensrcDir = createDir(testDir, "gensrc"); File classesDir = createDir(testDir, "classes"); File x = writeFile(new File(srcDir, "X.java"), src); DiagListener dl = new DiagListener(); JavacTool tool = JavacTool.create(); StandardJavaFileManager fm = tool.getStandardFileManager(dl, null, null); fm.setLocation(StandardLocation.CLASS_PATH, Arrays.asList(classesDir, new File(System.getProperty("test.classes")))); fm.setLocation(StandardLocation.CLASS_OUTPUT, Collections.singleton(classesDir)); fm.setLocation(StandardLocation.SOURCE_OUTPUT, Collections.singleton(gensrcDir)); List<String> args = new ArrayList<String>(); // args.add("-XprintProcessorInfo"); args.add("-XprintRounds"); args.add("-Agen=" + gen); if (wk == WarningKind.YES) args.add("-Xlint:serial"); Iterable<? extends JavaFileObject> files = fm.getJavaFileObjects(x); StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); JavacTask task = tool.getTask(pw, fm, dl, args, null, files); task.setProcessors(Arrays.asList(new AnnoProc())); boolean ok = task.call(); pw.close(); System.err.println("ok:" + ok + " diags:" + dl.counts); if (sw.toString().length() > 0) { System.err.println("output:\n" + sw.toString()); } for (Diagnostic.Kind dk: Diagnostic.Kind.values()) { Integer v = dl.counts.get(dk); int found = (v == null) ? 0 : v; int expect = (dk == Diagnostic.Kind.WARNING && wk == WarningKind.YES) ? gen : 0; if (found != expect) { error("Unexpected value for " + dk + ": expected: " + expect + " found: " + found); } } System.err.println(); }
Example 18
Source File: TestSimpleAddRemove.java From hottub with GNU General Public License v2.0 | 4 votes |
void test(CompileKind ck, AddKind ak, RemoveKind rk) throws IOException { System.err.println("Test: " + ck + " " + ak + " " + rk); File tmpDir = new File(ck + "-" + ak + "-" + rk); tmpDir.mkdirs(); fm.setLocation(StandardLocation.CLASS_OUTPUT, Arrays.asList(tmpDir)); List<String> options = new ArrayList<String>(); Iterable<? extends JavaFileObject> files = Arrays.asList(new TestSource()); StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); JavacTask task = tool.getTask(pw, fm, null, options, null, files); EventKindCounter ec = new EventKindCounter(); TaskListener listener = new TestListener(ec); boolean needProcessor = false; switch (ak) { case SET_IN_TASK: task.setTaskListener(listener); break; case ADD_IN_TASK: task.addTaskListener(listener); break; case ADD_IN_PROCESSOR: case ADD_IN_LISTENER: needProcessor = true; } switch (rk) { case REMOVE_IN_TASK: task.removeTaskListener(listener); break; case REMOVE_IN_PROCESSOR: case REMOVE_IN_LISTENER: needProcessor = true; } if (needProcessor) task.setProcessors(Arrays.asList(new TestProcessor(ak, rk, listener))); ck.run(task); System.err.println(ec); check(ck, ak, rk, ec); System.err.println(); }
Example 19
Source File: TestSuppression.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
void test(String src, WarningKind wk, int gen) throws Exception { count++; System.err.println("Test " + count + ": wk:" + wk + " gen:" + gen + " src:" +src); File testDir = new File("test" + count); File srcDir = createDir(testDir, "src"); File gensrcDir = createDir(testDir, "gensrc"); File classesDir = createDir(testDir, "classes"); File x = writeFile(new File(srcDir, "X.java"), src); DiagListener dl = new DiagListener(); JavacTool tool = JavacTool.create(); try (StandardJavaFileManager fm = tool.getStandardFileManager(dl, null, null)) { fm.setLocation(StandardLocation.CLASS_PATH, Arrays.asList(classesDir, new File(System.getProperty("test.classes")))); fm.setLocation(StandardLocation.CLASS_OUTPUT, Collections.singleton(classesDir)); fm.setLocation(StandardLocation.SOURCE_OUTPUT, Collections.singleton(gensrcDir)); List<String> args = new ArrayList<String>(); // args.add("-XprintProcessorInfo"); args.add("-XprintRounds"); args.add("-Agen=" + gen); if (wk == WarningKind.YES) args.add("-Xlint:serial"); Iterable<? extends JavaFileObject> files = fm.getJavaFileObjects(x); StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); JavacTask task = tool.getTask(pw, fm, dl, args, null, files); task.setProcessors(Arrays.asList(new AnnoProc())); boolean ok = task.call(); pw.close(); System.err.println("ok:" + ok + " diags:" + dl.counts); if (sw.toString().length() > 0) { System.err.println("output:\n" + sw.toString()); } for (Diagnostic.Kind dk: Diagnostic.Kind.values()) { Integer v = dl.counts.get(dk); int found = (v == null) ? 0 : v; int expect = (dk == Diagnostic.Kind.WARNING && wk == WarningKind.YES) ? gen : 0; if (found != expect) { error("Unexpected value for " + dk + ": expected: " + expect + " found: " + found); } } System.err.println(); } }
Example 20
Source File: TestSuppression.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 4 votes |
void test(String src, WarningKind wk, int gen) throws Exception { count++; System.err.println("Test " + count + ": wk:" + wk + " gen:" + gen + " src:" +src); File testDir = new File("test" + count); File srcDir = createDir(testDir, "src"); File gensrcDir = createDir(testDir, "gensrc"); File classesDir = createDir(testDir, "classes"); File x = writeFile(new File(srcDir, "X.java"), src); DiagListener dl = new DiagListener(); JavacTool tool = JavacTool.create(); StandardJavaFileManager fm = tool.getStandardFileManager(dl, null, null); fm.setLocation(StandardLocation.CLASS_PATH, Arrays.asList(classesDir, new File(System.getProperty("test.classes")))); fm.setLocation(StandardLocation.CLASS_OUTPUT, Collections.singleton(classesDir)); fm.setLocation(StandardLocation.SOURCE_OUTPUT, Collections.singleton(gensrcDir)); List<String> args = new ArrayList<String>(); // args.add("-XprintProcessorInfo"); args.add("-XprintRounds"); args.add("-Agen=" + gen); if (wk == WarningKind.YES) args.add("-Xlint:serial"); Iterable<? extends JavaFileObject> files = fm.getJavaFileObjects(x); StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); JavacTask task = tool.getTask(pw, fm, dl, args, null, files); task.setProcessors(Arrays.asList(new AnnoProc())); boolean ok = task.call(); pw.close(); System.err.println("ok:" + ok + " diags:" + dl.counts); if (sw.toString().length() > 0) { System.err.println("output:\n" + sw.toString()); } for (Diagnostic.Kind dk: Diagnostic.Kind.values()) { Integer v = dl.counts.get(dk); int found = (v == null) ? 0 : v; int expect = (dk == Diagnostic.Kind.WARNING && wk == WarningKind.YES) ? gen : 0; if (found != expect) { error("Unexpected value for " + dk + ": expected: " + expect + " found: " + found); } } System.err.println(); }