Java Code Examples for javax.tools.StandardJavaFileManager#inferBinaryName()
The following examples show how to use
javax.tools.StandardJavaFileManager#inferBinaryName() .
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: DetectMutableStaticFields.java License: GNU General Public License v2.0 | 6 votes |
void analyzeResource(URI resource) throws IOException, ConstantPoolException, InvalidDescriptor { JavaCompiler tool = ToolProvider.getSystemJavaCompiler(); StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null); JavaFileManager.Location location = StandardLocation.locationFor(resource.getPath()); fm.setLocation(location, com.sun.tools.javac.util.List.of( new File(resource.getPath()))); for (JavaFileObject file : fm.list(location, "", EnumSet.of(CLASS), true)) { String className = fm.inferBinaryName(location, file); int index = className.lastIndexOf('.'); String pckName = index == -1 ? "" : className.substring(0, index); if (shouldAnalyzePackage(pckName)) { analyzeClassFile(ClassFile.read(file.openInputStream())); } } }
Example 2
Source Project: jdk8u60 File: DetectMutableStaticFields.java License: GNU General Public License v2.0 | 6 votes |
void analyzeResource(URI resource) throws IOException, ConstantPoolException, InvalidDescriptor { JavaCompiler tool = ToolProvider.getSystemJavaCompiler(); StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null); JavaFileManager.Location location = StandardLocation.locationFor(resource.getPath()); fm.setLocation(location, com.sun.tools.javac.util.List.of( new File(resource.getPath()))); for (JavaFileObject file : fm.list(location, "", EnumSet.of(CLASS), true)) { String className = fm.inferBinaryName(location, file); int index = className.lastIndexOf('.'); String pckName = index == -1 ? "" : className.substring(0, index); if (shouldAnalyzePackage(pckName)) { analyzeClassFile(ClassFile.read(file.openInputStream())); } } }
Example 3
Source Project: openjdk-jdk8u File: DetectMutableStaticFields.java License: GNU General Public License v2.0 | 6 votes |
void analyzeResource(URI resource) throws IOException, ConstantPoolException, InvalidDescriptor { JavaCompiler tool = ToolProvider.getSystemJavaCompiler(); StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null); JavaFileManager.Location location = StandardLocation.locationFor(resource.getPath()); fm.setLocation(location, com.sun.tools.javac.util.List.of( new File(resource.getPath()))); for (JavaFileObject file : fm.list(location, "", EnumSet.of(CLASS), true)) { String className = fm.inferBinaryName(location, file); int index = className.lastIndexOf('.'); String pckName = index == -1 ? "" : className.substring(0, index); if (shouldAnalyzePackage(pckName)) { analyzeClassFile(ClassFile.read(file.openInputStream())); } } }
Example 4
Source Project: openjdk-jdk8u-backup File: DetectMutableStaticFields.java License: GNU General Public License v2.0 | 6 votes |
void analyzeResource(URI resource) throws IOException, ConstantPoolException, InvalidDescriptor { JavaCompiler tool = ToolProvider.getSystemJavaCompiler(); StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null); JavaFileManager.Location location = StandardLocation.locationFor(resource.getPath()); fm.setLocation(location, com.sun.tools.javac.util.List.of( new File(resource.getPath()))); for (JavaFileObject file : fm.list(location, "", EnumSet.of(CLASS), true)) { String className = fm.inferBinaryName(location, file); int index = className.lastIndexOf('.'); String pckName = index == -1 ? "" : className.substring(0, index); if (shouldAnalyzePackage(pckName)) { analyzeClassFile(ClassFile.read(file.openInputStream())); } } }
Example 5
Source Project: openjdk-jdk9 File: DetectMutableStaticFields.java License: GNU General Public License v2.0 | 6 votes |
void analyzeModule(StandardJavaFileManager fm, String moduleName) throws IOException, ConstantPoolException, InvalidDescriptor { JavaFileManager.Location location = fm.getLocationForModule(StandardLocation.SYSTEM_MODULES, moduleName); if (location == null) throw new AssertionError("can't find module " + moduleName); for (JavaFileObject file : fm.list(location, "", EnumSet.of(CLASS), true)) { String className = fm.inferBinaryName(location, file); int index = className.lastIndexOf('.'); String pckName = index == -1 ? "" : className.substring(0, index); if (shouldAnalyzePackage(pckName)) { analyzeClassFile(ClassFile.read(file.openInputStream())); } } }
Example 6
Source Project: hottub File: DetectMutableStaticFields.java License: GNU General Public License v2.0 | 6 votes |
void analyzeResource(URI resource) throws IOException, ConstantPoolException, InvalidDescriptor { JavaCompiler tool = ToolProvider.getSystemJavaCompiler(); StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null); JavaFileManager.Location location = StandardLocation.locationFor(resource.getPath()); fm.setLocation(location, com.sun.tools.javac.util.List.of( new File(resource.getPath()))); for (JavaFileObject file : fm.list(location, "", EnumSet.of(CLASS), true)) { String className = fm.inferBinaryName(location, file); int index = className.lastIndexOf('.'); String pckName = index == -1 ? "" : className.substring(0, index); if (shouldAnalyzePackage(pckName)) { analyzeClassFile(ClassFile.read(file.openInputStream())); } } }
Example 7
Source Project: openjdk-8-source File: DetectMutableStaticFields.java License: GNU General Public License v2.0 | 6 votes |
void analyzeResource(URI resource) throws IOException, ConstantPoolException, InvalidDescriptor { JavaCompiler tool = ToolProvider.getSystemJavaCompiler(); StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null); JavaFileManager.Location location = StandardLocation.locationFor(resource.getPath()); fm.setLocation(location, com.sun.tools.javac.util.List.of( new File(resource.getPath()))); for (JavaFileObject file : fm.list(location, "", EnumSet.of(CLASS), true)) { String className = fm.inferBinaryName(location, file); int index = className.lastIndexOf('.'); String pckName = index == -1 ? "" : className.substring(0, index); if (shouldAnalyzePackage(pckName)) { analyzeClassFile(ClassFile.read(file.openInputStream())); } } }
Example 8
Source Project: openjdk-8 File: DetectMutableStaticFields.java License: GNU General Public License v2.0 | 6 votes |
void analyzeResource(URI resource) throws IOException, ConstantPoolException, InvalidDescriptor { JavaCompiler tool = ToolProvider.getSystemJavaCompiler(); StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null); JavaFileManager.Location location = StandardLocation.locationFor(resource.getPath()); fm.setLocation(location, com.sun.tools.javac.util.List.of( new File(resource.getPath()))); for (JavaFileObject file : fm.list(location, "", EnumSet.of(CLASS), true)) { String className = fm.inferBinaryName(location, file); int index = className.lastIndexOf('.'); String pckName = index == -1 ? "" : className.substring(0, index); if (shouldAnalyzePackage(pckName)) { analyzeClassFile(ClassFile.read(file.openInputStream())); } } }
Example 9
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 10
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 11
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 12
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 13
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 14
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 15
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 16
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 17
Source Project: bazel File: DumpPlatformClassPath.java License: Apache License 2.0 | 4 votes |
static boolean dumpJDK9AndNewerBootClassPath( int hostMajorVersion, Path output, Path targetJavabase) throws IOException { // JDK 9 and newer support cross-compiling to older platform versions using the --system // and --release flags. // * --system takes the path to a JDK root for JDK 9 and up, and causes the compilation // to target the APIs from that JDK. // * --release takes a language level (e.g. '9') and uses the API information baked in to // the host JDK (in lib/ct.sym). // Since --system only supports JDK >= 9, first check of the target JDK defines a JDK 8 // bootclasspath. List<Path> bootClassPathJars = getBootClassPathJars(targetJavabase); if (!bootClassPathJars.isEmpty()) { writeClassPathJars(output, bootClassPathJars); return true; } // Initialize a FileManager to process the --system argument, and then read the // initialized bootclasspath data back out. Context context = new Context(); JavacTool.create() .getTask( /* out = */ null, /* fileManager = */ null, /* diagnosticListener = */ null, /* options = */ Arrays.asList("--system", String.valueOf(targetJavabase)), /* classes = */ null, /* compilationUnits = */ null, context); StandardJavaFileManager fileManager = (StandardJavaFileManager) context.get(JavaFileManager.class); SortedMap<String, InputStream> entries = new TreeMap<>(); for (JavaFileObject fileObject : fileManager.list( StandardLocation.PLATFORM_CLASS_PATH, "", EnumSet.of(Kind.CLASS), /* recurse= */ true)) { String binaryName = fileManager.inferBinaryName(StandardLocation.PLATFORM_CLASS_PATH, fileObject); entries.put(binaryName.replace('.', '/') + ".class", fileObject.openInputStream()); } writeEntries(output, entries); return true; }