Java Code Examples for javax.tools.StandardJavaFileManager#getJavaFileForOutput()
The following examples show how to use
javax.tools.StandardJavaFileManager#getJavaFileForOutput() .
These examples are extracted from open source projects.
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 Project: TencentKona-8 File: GenStubs.java License: 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 Project: jdk8u60 File: GenStubs.java License: 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 Project: openjdk-jdk8u File: GenStubs.java License: 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 Project: openjdk-jdk8u-backup File: GenStubs.java License: 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 Project: openjdk-jdk9 File: GenStubs.java License: 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 Project: hottub File: GenStubs.java License: 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 Project: openjdk-8-source File: GenStubs.java License: 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 Project: openjdk-8 File: GenStubs.java License: 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 Project: incubator-tez File: TestMRRJobsDAGApi.java License: 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 Project: tez File: TestMRRJobsDAGApi.java License: 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(); }