javax.tools.StandardJavaFileManager#inferBinaryName ( )源码实例Demo

下面列出了javax.tools.StandardJavaFileManager#inferBinaryName ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: TencentKona-8   文件: DetectMutableStaticFields.java
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()));
        }
    }
}
 
源代码2 项目: jdk8u60   文件: DetectMutableStaticFields.java
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()));
        }
    }
}
 
源代码3 项目: openjdk-jdk8u   文件: DetectMutableStaticFields.java
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()));
        }
    }
}
 
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()));
        }
    }
}
 
源代码5 项目: openjdk-jdk9   文件: DetectMutableStaticFields.java
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()));
        }
    }
}
 
源代码6 项目: hottub   文件: DetectMutableStaticFields.java
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()));
        }
    }
}
 
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()));
        }
    }
}
 
源代码8 项目: openjdk-8   文件: DetectMutableStaticFields.java
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()));
        }
    }
}
 
源代码9 项目: TencentKona-8   文件: GenStubs.java
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();
    }
}
 
源代码10 项目: jdk8u60   文件: GenStubs.java
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();
    }
}
 
源代码11 项目: openjdk-jdk8u   文件: GenStubs.java
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();
    }
}
 
源代码12 项目: openjdk-jdk8u-backup   文件: GenStubs.java
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();
    }
}
 
源代码13 项目: openjdk-jdk9   文件: GenStubs.java
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();
    }
}
 
源代码14 项目: hottub   文件: GenStubs.java
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();
    }
}
 
源代码15 项目: openjdk-8-source   文件: GenStubs.java
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();
    }
}
 
源代码16 项目: openjdk-8   文件: GenStubs.java
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();
    }
}
 
源代码17 项目: bazel   文件: DumpPlatformClassPath.java
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;
}