Java Code Examples for com.sun.tools.javac.api.JavacTool#getStandardFileManager()
The following examples show how to use
com.sun.tools.javac.api.JavacTool#getStandardFileManager() .
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: DocTreePathScannerTest.java From openjdk-8 with GNU General Public License v2.0 | 6 votes |
void run() throws Exception { List<File> files = new ArrayList<File>(); File testSrc = new File(System.getProperty("test.src")); for (File f: testSrc.listFiles()) { if (f.isFile() && f.getName().endsWith(".java")) files.add(f); } JavacTool javac = JavacTool.create(); StandardJavaFileManager fm = javac.getStandardFileManager(null, null, null); Iterable<? extends JavaFileObject> fos = fm.getJavaFileObjectsFromFiles(files); JavacTask t = javac.getTask(null, fm, null, null, null, fos); DocTrees trees = DocTrees.instance(t); Iterable<? extends CompilationUnitTree> units = t.parse(); DeclScanner ds = new DeclScanner(trees); for (CompilationUnitTree unit: units) { ds.scan(unit, null); } if (errors > 0) throw new Exception(errors + " errors occurred"); }
Example 2
Source File: T6410706.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 6 votes |
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: TestDocComments.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 6 votes |
/** * method-run. */ void run() throws Exception { File testSrc = new File(System.getProperty("test.src")); File file = new File(testSrc, "TestDocComments.java"); JavacTool tool = JavacTool.create(); StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null); StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); Iterable<? extends JavaFileObject> fileObjects = fm.getJavaFileObjects(file); JavacTask task = tool.getTask(pw, fm, null, null, null, fileObjects); Iterable<? extends CompilationUnitTree> units = task.parse(); Trees trees = Trees.instance(task); CommentScanner s = new CommentScanner(); int n = s.scan(units, trees); if (n != 12) error("Unexpected number of doc comments found: " + n); if (errors > 0) throw new Exception(errors + " errors occurred"); }
Example 4
Source File: AnnotatedArrayOrder.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 6 votes |
public static void main(String[] args) throws Exception { PrintWriter out = new PrintWriter(System.out, true); JavacTool tool = JavacTool.create(); StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null); File testSrc = new File(System.getProperty("test.src")); Iterable<? extends JavaFileObject> f = fm.getJavaFileObjectsFromFiles(Arrays.asList(new File(testSrc, "AnnotatedArrayOrder.java"))); JavacTask task = tool.getTask(out, fm, null, null, null, f); Iterable<? extends CompilationUnitTree> trees = task.parse(); out.flush(); Scanner s = new Scanner(); for (CompilationUnitTree t: trees) s.scan(t, null); }
Example 5
Source File: T6993305.java From jdk8u60 with GNU General Public License v2.0 | 6 votes |
void run() throws Exception { File testSrc = new File(System.getProperty("test.src")); JavacTool tool = JavacTool.create(); StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null); File f = new File(testSrc, T6993305.class.getSimpleName() + ".java"); Iterable<? extends JavaFileObject> fos = fm.getJavaFileObjects(f); JavacTask task = tool.getTask(null, fm, null, null, null, fos); Iterable<? extends CompilationUnitTree> cus = task.parse(); TestScanner s = new TestScanner(); s.scan(cus, task); if (errors > 0) throw new Exception(errors + " errors occurred"); }
Example 6
Source File: T6993305.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
void run() throws Exception { File testSrc = new File(System.getProperty("test.src")); JavacTool tool = JavacTool.create(); StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null); File f = new File(testSrc, T6993305.class.getSimpleName() + ".java"); Iterable<? extends JavaFileObject> fos = fm.getJavaFileObjects(f); JavacTask task = tool.getTask(null, fm, null, null, null, fos); Iterable<? extends CompilationUnitTree> cus = task.parse(); TestScanner s = new TestScanner(); s.scan(cus, task); if (errors > 0) throw new Exception(errors + " errors occurred"); }
Example 7
Source File: T6410706.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
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"); } }
Example 8
Source File: AnnotatedArrayOrder.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
public static void main(String[] args) throws Exception { PrintWriter out = new PrintWriter(System.out, true); JavacTool tool = JavacTool.create(); StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null); File testSrc = new File(System.getProperty("test.src")); Iterable<? extends JavaFileObject> f = fm.getJavaFileObjectsFromFiles(Arrays.asList(new File(testSrc, "AnnotatedArrayOrder.java"))); JavacTask task = tool.getTask(out, fm, null, null, null, f); Iterable<? extends CompilationUnitTree> trees = task.parse(); out.flush(); Scanner s = new Scanner(); for (CompilationUnitTree t: trees) s.scan(t, null); }
Example 9
Source File: T6993305.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 6 votes |
void run() throws Exception { File testSrc = new File(System.getProperty("test.src")); JavacTool tool = JavacTool.create(); StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null); File f = new File(testSrc, T6993305.class.getSimpleName() + ".java"); Iterable<? extends JavaFileObject> fos = fm.getJavaFileObjects(f); JavacTask task = tool.getTask(null, fm, null, null, null, fos); Iterable<? extends CompilationUnitTree> cus = task.parse(); TestScanner s = new TestScanner(); s.scan(cus, task); if (errors > 0) throw new Exception(errors + " errors occurred"); }
Example 10
Source File: T6410706.java From jdk8u60 with GNU General Public License v2.0 | 6 votes |
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: ArrayCreationTree.java From openjdk-8 with GNU General Public License v2.0 | 6 votes |
public static void main(String[] args) throws Exception { PrintWriter out = new PrintWriter(System.out, true); JavacTool tool = JavacTool.create(); StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null); File testSrc = new File(System.getProperty("test.src")); Iterable<? extends JavaFileObject> f = fm.getJavaFileObjectsFromFiles(Arrays.asList(new File(testSrc, "ArrayCreationTree.java"))); JavacTask task = tool.getTask(out, fm, null, null, null, f); Iterable<? extends CompilationUnitTree> trees = task.parse(); out.flush(); Scanner s = new Scanner(); for (CompilationUnitTree t: trees) s.scan(t, null); }
Example 12
Source File: DocTreePathScannerTest.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 6 votes |
void run() throws Exception { List<File> files = new ArrayList<File>(); File testSrc = new File(System.getProperty("test.src")); for (File f: testSrc.listFiles()) { if (f.isFile() && f.getName().endsWith(".java")) files.add(f); } JavacTool javac = JavacTool.create(); StandardJavaFileManager fm = javac.getStandardFileManager(null, null, null); Iterable<? extends JavaFileObject> fos = fm.getJavaFileObjectsFromFiles(files); JavacTask t = javac.getTask(null, fm, null, null, null, fos); DocTrees trees = DocTrees.instance(t); Iterable<? extends CompilationUnitTree> units = t.parse(); DeclScanner ds = new DeclScanner(trees); for (CompilationUnitTree unit: units) { ds.scan(unit, null); } if (errors > 0) throw new Exception(errors + " errors occurred"); }
Example 13
Source File: TestTrees.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
void run() throws IOException { JavacTool tool = JavacTool.create(); DiagnosticListener<JavaFileObject> dl = new DiagnosticListener<JavaFileObject>() { public void report(Diagnostic d) { error(d.toString()); } }; StandardJavaFileManager fm = tool.getStandardFileManager(dl, null, null); Iterable<? extends JavaFileObject> files = fm.getJavaFileObjectsFromFiles(Arrays.asList(new File(testSrcDir, self + ".java"))); Iterable<String> opts = Arrays.asList("-d", "."); System.err.println("simple compilation, no processing"); JavacTask task = tool.getTask(out, fm, dl, opts, null, files); task.setTaskListener(new MyTaskListener(task)); if (!task.call()) throw new AssertionError("compilation failed"); opts = Arrays.asList("-d", ".", "-processorpath", testClassDir, "-processor", self); System.err.println(); System.err.println("compilation with processing"); task = tool.getTask(out, fm, dl,opts, null, files); if (!task.call()) throw new AssertionError("compilation failed"); if (errors > 0) throw new AssertionError(errors + " errors occurred"); }
Example 14
Source File: T6397044.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
public static void main(String[] args) throws Exception { String srcDir = System.getProperty("test.src", "."); String self = T6397044.class.getName(); JavacTool tool = JavacTool.create(); StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null); Iterable<? extends JavaFileObject> files = fm.getJavaFileObjectsFromFiles(Arrays.asList(new File(srcDir, self + ".java"))); JavacTask task = tool.getTask(null, fm, null, null, null, files); Iterable<? extends CompilationUnitTree> trees = task.parse(); Checker checker = new Checker(); for (CompilationUnitTree tree: trees) checker.check(tree); }
Example 15
Source File: GenStubs.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
public boolean run(String sourcepath, File outdir, List<String> classes) { //System.err.println("run: sourcepath:" + sourcepath + " outdir:" + outdir + " classes:" + classes); if (sourcepath == null) throw new IllegalArgumentException("sourcepath not set"); if (outdir == null) throw new IllegalArgumentException("source output dir not set"); JavacTool tool = JavacTool.create(); StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null); try { fm.setLocation(StandardLocation.SOURCE_OUTPUT, Collections.singleton(outdir)); fm.setLocation(StandardLocation.SOURCE_PATH, splitPath(sourcepath)); List<JavaFileObject> files = new ArrayList<JavaFileObject>(); for (String c: classes) { JavaFileObject fo = fm.getJavaFileForInput( StandardLocation.SOURCE_PATH, c, JavaFileObject.Kind.SOURCE); if (fo == null) error("class not found: " + c); else files.add(fo); } JavacTask t = tool.getTask(null, fm, null, null, null, files); Iterable<? extends CompilationUnitTree> trees = t.parse(); for (CompilationUnitTree tree: trees) { makeStub(fm, tree); } } catch (IOException e) { error("IO error " + e, e); } return (errors == 0); }
Example 16
Source File: PrettyPrintingForLoopsTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
public void testForLoop() throws IOException { List files = Arrays.asList(new JavaSource("")); JavacTool tool = JavacTool.create(); try (StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null)) { JavacTask task = tool.getTask(null, fm, null, null, null, files); Iterable trees = task.parse(); CompilationUnitTree thisTree = (CompilationUnitTree)trees.iterator().next(); String thisSrc = prettyPrint((JCTree) thisTree); Assert.check(thisSrc.equals(JavaSource.source)); } }
Example 17
Source File: TestTrees.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
void run() throws IOException { JavacTool tool = JavacTool.create(); DiagnosticListener<JavaFileObject> dl = new DiagnosticListener<JavaFileObject>() { public void report(Diagnostic d) { error(d.toString()); } }; StandardJavaFileManager fm = tool.getStandardFileManager(dl, null, null); Iterable<? extends JavaFileObject> files = fm.getJavaFileObjectsFromFiles(Arrays.asList(new File(testSrcDir, self + ".java"))); Iterable<String> opts = Arrays.asList("-d", "."); System.err.println("simple compilation, no processing"); JavacTask task = tool.getTask(out, fm, dl, opts, null, files); task.setTaskListener(new MyTaskListener(task)); if (!task.call()) throw new AssertionError("compilation failed"); opts = Arrays.asList("-d", ".", "-processorpath", testClassDir, "-processor", self); System.err.println(); System.err.println("compilation with processing"); task = tool.getTask(out, fm, dl,opts, null, files); if (!task.call()) throw new AssertionError("compilation failed"); if (errors > 0) throw new AssertionError(errors + " errors occurred"); }
Example 18
Source File: Test.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
/** Doc comment: run */ void run() throws Exception { File testSrc = new File(System.getProperty("test.src")); File thisFile = new File(testSrc, getClass().getName() + ".java"); JavacTool javac = JavacTool.create(); StandardJavaFileManager fm = javac.getStandardFileManager(null, null, null); fm.setLocation(StandardLocation.CLASS_OUTPUT, Arrays.asList(new File("."))); Iterable<? extends JavaFileObject> fos = fm.getJavaFileObjects(thisFile); testAnnoProcessor(javac, fm, fos, out, EXPECT_DOC_COMMENTS); testTaskListener(javac, fm, fos, out, EXPECT_DOC_COMMENTS); if (errors > 0) throw new Exception(errors + " errors occurred"); }
Example 19
Source File: TestSuppression.java From openjdk-jdk8u 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 20
Source File: T6348193.java From openjdk-8-source with GNU General Public License v2.0 | 4 votes |
public static void test(NoYes secMgr, NoGoodBad config, NoYes proc) throws IOException { if (verbose) System.err.println("secMgr:" + secMgr + " config:" + config + " proc:" + proc); if (secMgr == NoYes.YES && System.getSecurityManager() == null) System.setSecurityManager(new NoLoaderSecurityManager()); installConfigFile(config); processed.delete(); List<String> args = new ArrayList<String>(); //args.add("-XprintRounds"); if (proc == NoYes.YES) { args.add("-processor"); args.add(myName); } args.add("-processorpath"); args.add(System.getProperty("java.class.path")); args.add("-d"); args.add("."); JavacTool t = JavacTool.create(); // avoid using class loader MyDiagListener dl = new MyDiagListener(); PrintWriter out = new PrintWriter(System.err, true); StandardJavaFileManager fm = t.getStandardFileManager(dl, null, null); File file = new File(System.getProperty("test.src"), myName+".java"); Iterable<? extends JavaFileObject> files = fm.getJavaFileObjectsFromFiles(Arrays.asList(file)); boolean ok = t.getTask(out, null, dl, args, null, files).call(); if (config == NoGoodBad.GOOD || proc == NoYes.YES) { if (secMgr == NoYes.YES) { if (dl.last == null) throw new AssertionError("Security manager installed, and processors present, " + " but no diagnostic received"); } else { if (!processed.exists()) throw new AssertionError("No security manager installed, and processors present, " + " but no processing occurred"); } } else if (config == NoGoodBad.BAD) { // TODO: should verify that no compiler crash occurred // needs revised JSR199 spec } else { if (processed.exists()) throw new AssertionError("No processors present, but processing occurred!"); } if (verbose) System.err.println("OK"); }