Java Code Examples for javax.tools.StandardJavaFileManager#getJavaFileForOutput()
The following examples show how to use
javax.tools.StandardJavaFileManager#getJavaFileForOutput() .
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: GenStubs.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
void makeStub(StandardJavaFileManager fm, CompilationUnitTree tree) throws IOException { CompilationUnitTree tree2 = new StubMaker().translate(tree); CompilationUnitTree tree3 = new ImportCleaner(fm).removeRedundantImports(tree2); String className = fm.inferBinaryName(StandardLocation.SOURCE_PATH, tree.getSourceFile()); JavaFileObject fo = fm.getJavaFileForOutput(StandardLocation.SOURCE_OUTPUT, className, JavaFileObject.Kind.SOURCE, null); // System.err.println("Writing " + className + " to " + fo.getName()); Writer out = fo.openWriter(); try { new Pretty(out, true).printExpr((JCTree) tree3); } finally { out.close(); } }
Example 2
Source File: GenStubs.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
void makeStub(StandardJavaFileManager fm, CompilationUnitTree tree) throws IOException { CompilationUnitTree tree2 = new StubMaker().translate(tree); CompilationUnitTree tree3 = new ImportCleaner(fm).removeRedundantImports(tree2); String className = fm.inferBinaryName(StandardLocation.SOURCE_PATH, tree.getSourceFile()); JavaFileObject fo = fm.getJavaFileForOutput(StandardLocation.SOURCE_OUTPUT, className, JavaFileObject.Kind.SOURCE, null); // System.err.println("Writing " + className + " to " + fo.getName()); Writer out = fo.openWriter(); try { new Pretty(out, true).printExpr((JCTree) tree3); } finally { out.close(); } }
Example 3
Source File: GenStubs.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
void makeStub(StandardJavaFileManager fm, CompilationUnitTree tree) throws IOException { CompilationUnitTree tree2 = new StubMaker().translate(tree); CompilationUnitTree tree3 = new ImportCleaner(fm).removeRedundantImports(tree2); String className = fm.inferBinaryName(StandardLocation.SOURCE_PATH, tree.getSourceFile()); JavaFileObject fo = fm.getJavaFileForOutput(StandardLocation.SOURCE_OUTPUT, className, JavaFileObject.Kind.SOURCE, null); // System.err.println("Writing " + className + " to " + fo.getName()); Writer out = fo.openWriter(); try { new Pretty(out, true).printExpr((JCTree) tree3); } finally { out.close(); } }
Example 4
Source File: GenStubs.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
void makeStub(StandardJavaFileManager fm, CompilationUnitTree tree) throws IOException { CompilationUnitTree tree2 = new StubMaker().translate(tree); CompilationUnitTree tree3 = new ImportCleaner(fm).removeRedundantImports(tree2); String className = fm.inferBinaryName(StandardLocation.SOURCE_PATH, tree.getSourceFile()); JavaFileObject fo = fm.getJavaFileForOutput(StandardLocation.SOURCE_OUTPUT, className, JavaFileObject.Kind.SOURCE, null); // System.err.println("Writing " + className + " to " + fo.getName()); Writer out = fo.openWriter(); try { new Pretty(out, true).printExpr((JCTree) tree3); } finally { out.close(); } }
Example 5
Source File: GenStubs.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
void makeStub(StandardJavaFileManager fm, CompilationUnitTree tree) throws IOException { CompilationUnitTree tree2 = new StubMaker().translate(tree); CompilationUnitTree tree3 = new ImportCleaner(fm).removeRedundantImports(tree2); String className = fm.inferBinaryName(StandardLocation.SOURCE_PATH, tree.getSourceFile()); JavaFileObject fo = fm.getJavaFileForOutput(StandardLocation.SOURCE_OUTPUT, className, JavaFileObject.Kind.SOURCE, null); // System.err.println("Writing " + className + " to " + fo.getName()); Writer out = fo.openWriter(); try { new Pretty(out, true).printExpr((JCTree) tree3); } finally { out.close(); } }
Example 6
Source File: GenStubs.java From hottub with GNU General Public License v2.0 | 5 votes |
void makeStub(StandardJavaFileManager fm, CompilationUnitTree tree) throws IOException { CompilationUnitTree tree2 = new StubMaker().translate(tree); CompilationUnitTree tree3 = new ImportCleaner(fm).removeRedundantImports(tree2); String className = fm.inferBinaryName(StandardLocation.SOURCE_PATH, tree.getSourceFile()); JavaFileObject fo = fm.getJavaFileForOutput(StandardLocation.SOURCE_OUTPUT, className, JavaFileObject.Kind.SOURCE, null); // System.err.println("Writing " + className + " to " + fo.getName()); Writer out = fo.openWriter(); try { new Pretty(out, true).printExpr((JCTree) tree3); } finally { out.close(); } }
Example 7
Source File: GenStubs.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
void makeStub(StandardJavaFileManager fm, CompilationUnitTree tree) throws IOException { CompilationUnitTree tree2 = new StubMaker().translate(tree); CompilationUnitTree tree3 = new ImportCleaner(fm).removeRedundantImports(tree2); String className = fm.inferBinaryName(StandardLocation.SOURCE_PATH, tree.getSourceFile()); JavaFileObject fo = fm.getJavaFileForOutput(StandardLocation.SOURCE_OUTPUT, className, JavaFileObject.Kind.SOURCE, null); // System.err.println("Writing " + className + " to " + fo.getName()); Writer out = fo.openWriter(); try { new Pretty(out, true).printExpr((JCTree) tree3); } finally { out.close(); } }
Example 8
Source File: GenStubs.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
void makeStub(StandardJavaFileManager fm, CompilationUnitTree tree) throws IOException { CompilationUnitTree tree2 = new StubMaker().translate(tree); CompilationUnitTree tree3 = new ImportCleaner(fm).removeRedundantImports(tree2); String className = fm.inferBinaryName(StandardLocation.SOURCE_PATH, tree.getSourceFile()); JavaFileObject fo = fm.getJavaFileForOutput(StandardLocation.SOURCE_OUTPUT, className, JavaFileObject.Kind.SOURCE, null); // System.err.println("Writing " + className + " to " + fo.getName()); Writer out = fo.openWriter(); try { new Pretty(out, true).printExpr((JCTree) tree3); } finally { out.close(); } }
Example 9
Source File: TestMRRJobsDAGApi.java From incubator-tez with Apache License 2.0 | 5 votes |
private static void createTestJar(OutputStream outStream, String dummyClassName) throws URISyntaxException, IOException { JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); JavaFileObject srcFileObject = new SimpleJavaFileObjectImpl( URI.create("string:///" + dummyClassName + Kind.SOURCE.extension), Kind.SOURCE); StandardJavaFileManager fileManager = compiler.getStandardFileManager(null, null, null); compiler.getTask(null, fileManager, null, null, null, Collections.singletonList(srcFileObject)) .call(); JavaFileObject javaFileObject = fileManager.getJavaFileForOutput(StandardLocation.CLASS_OUTPUT, dummyClassName, Kind.CLASS, null); File classFile = new File(dummyClassName + Kind.CLASS.extension); JarOutputStream jarOutputStream = new JarOutputStream(outStream); JarEntry jarEntry = new JarEntry(classFile.getName()); jarEntry.setTime(classFile.lastModified()); jarOutputStream.putNextEntry(jarEntry); InputStream in = javaFileObject.openInputStream(); byte buffer[] = new byte[4096]; while (true) { int nRead = in.read(buffer, 0, buffer.length); if (nRead <= 0) break; jarOutputStream.write(buffer, 0, nRead); } in.close(); jarOutputStream.close(); javaFileObject.delete(); }
Example 10
Source File: TestMRRJobsDAGApi.java From tez with Apache License 2.0 | 5 votes |
private static void createTestJar(OutputStream outStream, String dummyClassName) throws URISyntaxException, IOException { JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); JavaFileObject srcFileObject = new SimpleJavaFileObjectImpl( URI.create("string:///" + dummyClassName + Kind.SOURCE.extension), Kind.SOURCE); StandardJavaFileManager fileManager = compiler.getStandardFileManager(null, null, null); compiler.getTask(null, fileManager, null, null, null, Collections.singletonList(srcFileObject)) .call(); JavaFileObject javaFileObject = fileManager.getJavaFileForOutput(StandardLocation.CLASS_OUTPUT, dummyClassName, Kind.CLASS, null); File classFile = new File(dummyClassName + Kind.CLASS.extension); JarOutputStream jarOutputStream = new JarOutputStream(outStream); JarEntry jarEntry = new JarEntry(classFile.getName()); jarEntry.setTime(classFile.lastModified()); jarOutputStream.putNextEntry(jarEntry); InputStream in = javaFileObject.openInputStream(); byte buffer[] = new byte[4096]; while (true) { int nRead = in.read(buffer, 0, buffer.length); if (nRead <= 0) break; jarOutputStream.write(buffer, 0, nRead); } in.close(); jarOutputStream.close(); javaFileObject.delete(); }