Java 类javax.tools.JavaFileObject.Kind 实例源码

项目:openjdk-jdk10    文件:SmartFileManager.java   
@Override @DefinedBy(Api.COMPILER)
public Iterable<JavaFileObject> list(Location location,
                                     String packageName,
                                     Set<Kind> kinds,
                                     boolean recurse) throws IOException {
    // TODO: Do this lazily by returning an iterable with a filtering Iterator
    // Acquire the list of files.
    Iterable<JavaFileObject> files = super.list(location, packageName, kinds, recurse);
    if (visibleSources.isEmpty()) {
        return locWrapMany(files, location);
    }
    // Now filter!
    ListBuffer<JavaFileObject> filteredFiles = new ListBuffer<>();
    for (JavaFileObject f : files) {
        URI uri = f.toUri();
        String t = uri.toString();
        if (t.startsWith("jar:")
            || t.endsWith(".class")
            || visibleSources.contains(uri)) {
            filteredFiles.add(f);
        }
    }

    return locWrapMany(filteredFiles, location);
}
项目:incubator-netbeans    文件:OutputFileManager.java   
@Override
public JavaFileObject getJavaFileForInput(Location l, String className, Kind kind) {
    if (kind == JavaFileObject.Kind.CLASS) {
        int dot = className.lastIndexOf('.');
        String dir = dot == -1 ? "" : FileObjects.convertPackage2Folder(className.substring(0, dot));
        javax.tools.FileObject fo = tx.readFileObject(l, dir, className.substring(dot + 1));
        if (fo != null) {
            return (JavaFileObject)fo;
        }
    }
    if (!ModuleLocation.isInstance(l)) {
        //File in output
        return super.getJavaFileForInput(l, className, kind);
    } else {
        //File in module
        return getJavaFileForInputImpl(
                ModuleLocation.WithExcludes.cast(l).getModuleEntries(),
                className,
                kind
        );
    }
}
项目:OpenJSharp    文件:JavacPathFileManager.java   
@Override
public Iterable<JavaFileObject> list(Location location,
        String packageName, Set<Kind> kinds, boolean recurse)
        throws IOException {
    // validatePackageName(packageName);
    nullCheck(packageName);
    nullCheck(kinds);

    Iterable<? extends Path> paths = getLocation(location);
    if (paths == null)
        return List.nil();
    ListBuffer<JavaFileObject> results = new ListBuffer<JavaFileObject>();

    for (Path path : paths)
        list(path, packageName, kinds, recurse, results);

    return results.toList();
}
项目:OpenJSharp    文件:SmartFileManager.java   
@Override
public JavaFileObject getJavaFileForInput(Location location,
                                          String className,
                                          Kind kind)
    throws IOException
{
    JavaFileObject file = super.getJavaFileForInput(location, className, kind);
    if (file == null || visibleSources.isEmpty()) {
        return file;
    }

    if (visibleSources.contains(file.toUri())) {
        return file;
    }
    return null;
}
项目:OpenJSharp    文件:SmartFileManager.java   
@Override
public JavaFileObject getJavaFileForOutput(Location location,
                                           String className,
                                           Kind kind,
                                           FileObject sibling)
    throws IOException
{
    JavaFileObject file = super.getJavaFileForOutput(location, className, kind, sibling);
    if (file == null) return file;
    int dp = className.lastIndexOf('.');
    String pkg_name = "";
    if (dp != -1) {
        pkg_name = className.substring(0, dp);
    }
    // When modules are in use, then the mod_name might be something like "jdk_base"
    String mod_name = "";
    addArtifact(mod_name+":"+pkg_name, file.toUri());
    return file;
}
项目:Avatar    文件:InMemoryJavaFileManager.java   
@Override
public JavaFileObject getJavaFileForOutput(
        final Location location,
        final String className,
        final Kind kind,
        final FileObject sibling)
        throws IOException {

    final URI uri = createUri(location, className, kind);

    if (!files.containsKey(uri)) {
        files.put(uri, new InMemoryJavaFileObject(uri));
    }

    return files.get(uri);
}
项目:openjdk-jdk10    文件:ModuleFinder.java   
public ModuleSymbol findSingleModule() {
    try {
        JavaFileObject src_fo = getModuleInfoFromLocation(StandardLocation.SOURCE_PATH, Kind.SOURCE);
        JavaFileObject class_fo = getModuleInfoFromLocation(StandardLocation.CLASS_OUTPUT, Kind.CLASS);
        JavaFileObject fo = (src_fo == null) ? class_fo
                : (class_fo == null) ? src_fo
                        : classFinder.preferredFileObject(src_fo, class_fo);

        ModuleSymbol msym;
        if (fo == null) {
            msym = syms.unnamedModule;
        } else {
            msym = readModule(fo);
        }

        if (msym.patchLocation == null) {
            msym.classLocation = StandardLocation.CLASS_OUTPUT;
        } else {
            msym.patchOutputLocation = StandardLocation.CLASS_OUTPUT;
        }
        return msym;

    } catch (IOException e) {
        throw new Error(e); // FIXME
    }
}
项目:openjdk-jdk10    文件:ElementStructureTest.java   
@Override
public Iterable<JavaFileObject> list(Location location, String packageName, Set<Kind> kinds, boolean recurse) throws IOException {
    if (location != StandardLocation.PLATFORM_CLASS_PATH || !kinds.contains(Kind.CLASS))
        return Collections.emptyList();

    if (!packageName.isEmpty())
        packageName += ".";

    List<JavaFileObject> result = new ArrayList<>();

    for (Entry<String, JavaFileObject> e : className2File.entrySet()) {
        String currentPackage = e.getKey().substring(0, e.getKey().lastIndexOf(".") + 1);
        if (recurse ? currentPackage.startsWith(packageName) : packageName.equals(currentPackage))
            result.add(e.getValue());
    }

    return result;
}
项目:openjdk-jdk10    文件:JavacProcessingEnvironment.java   
public void visitTopLevel(JCCompilationUnit node) {
    if (node.packge != null) {
        if (node.packge.package_info != null) {
            node.packge.package_info.reset();
        }
        node.packge.reset();
    }
    boolean isModuleInfo = node.sourcefile.isNameCompatible("module-info", Kind.SOURCE);
    if (isModuleInfo) {
        node.modle.reset();
        node.modle.completer = sym -> modules.enter(List.of(node), node.modle.module_info);
        node.modle.module_info.reset();
        node.modle.module_info.members_field = WriteableScope.create(node.modle.module_info);
    }
    node.packge = null;
    topLevel = node;
    try {
        super.visitTopLevel(node);
    } finally {
        topLevel = null;
    }
}
项目:openjdk-jdk10    文件:ModuleAndPackageLocations.java   
@Test
public void testRejects(Path outerBase) throws Exception {
    doRunTest(outerBase, (base, fm) -> {
        assertRefused(() -> fm.getClassLoader(StandardLocation.MODULE_SOURCE_PATH));
        assertRefused(() -> fm.getFileForInput(StandardLocation.MODULE_SOURCE_PATH, "", ""));
        assertRefused(() -> fm.getFileForOutput(StandardLocation.MODULE_SOURCE_PATH, "", "", null));
        assertRefused(() -> fm.getJavaFileForInput(StandardLocation.MODULE_SOURCE_PATH, "", Kind.SOURCE));
        assertRefused(() -> fm.getJavaFileForOutput(StandardLocation.MODULE_SOURCE_PATH, "", Kind.SOURCE, null));
        assertRefused(() -> fm.getLocationForModule(StandardLocation.SOURCE_PATH, "test"));
        JavaFileObject out = fm.getJavaFileForInput(StandardLocation.CLASS_OUTPUT, "test.Test", Kind.CLASS);
        assertRefused(() -> fm.inferBinaryName(StandardLocation.MODULE_PATH, out));
        assertRefused(() -> fm.inferModuleName(StandardLocation.MODULE_SOURCE_PATH));
        assertRefused(() -> fm.list(StandardLocation.MODULE_SOURCE_PATH, "test", EnumSet.allOf(Kind.class), false));
        assertRefused(() -> fm.listLocationsForModules(StandardLocation.SOURCE_PATH));
    });
}
项目:incubator-netbeans    文件:OutputFileManager.java   
@Override
public Iterable<JavaFileObject> list(Location l, String packageName, Set<Kind> kinds, boolean recursive) {
    final Iterable<JavaFileObject> sr;
    if (!ModuleLocation.isInstance(l)) {
        //List output
        sr =  super.list(l, packageName, kinds, recursive);
    } else {
        //List module
        final ModuleLocation.WithExcludes ml = ModuleLocation.WithExcludes.cast(l);
        sr = listImpl(l, ml.getModuleEntries(), packageName, kinds, recursive);
    }
    return tx.filter(l, packageName, sr);
}
项目:openjdk-jdk10    文件:BaseClassesNotReRead.java   
@Override
public Iterable<JavaFileObject> list(Location location, String packageName, Set<Kind> kinds,
        boolean recurse) throws IOException {
    List<JavaFileObject> result = new ArrayList<>();
    for (JavaFileObject jfo : super.list(location, packageName, kinds, recurse)) {
        result.add(new OnlyOneReadJavaFileObject(jfo));
    }
    return result;
}
项目:incubator-netbeans    文件:AptSourceFileManager.java   
@Override
public JavaFileObject getJavaFileForOutput (Location l, String className, JavaFileObject.Kind kind, javax.tools.FileObject sibling)
    throws IOException, UnsupportedOperationException, IllegalArgumentException {
    URL aptRoot = getAptRoot(sibling);
    if (ModuleLocation.isInstance(l)) {
        ModuleLocation mloc = ModuleLocation.cast(l);
        l = mloc.getBaseLocation();
        if (aptRoot == null) {
            final Iterator<? extends URL> it = mloc.getModuleRoots().iterator();
            aptRoot = it.hasNext() ? it.next() : null;
        } else if (!mloc.getModuleRoots().contains(aptRoot)) {
            throw new UnsupportedOperationException("ModuleLocation's APT root differs from the sibling's APT root");
        }
    }
    final Location location = l;
    if (StandardLocation.SOURCE_OUTPUT != location) {
        throw new UnsupportedOperationException("Only apt output is supported."); // NOI18N
    }
    if (aptRoot == null) {
        throw new UnsupportedOperationException(noAptRootDebug(sibling));
    }
    final String nameStr = className.replace('.', File.separatorChar) + kind.extension;    //NOI18N
    //Always on master fs -> file is save.
    return Optional.ofNullable(URLMapper.findFileObject(aptRoot))
            .map(fo -> {
                File f = FileUtil.toFile(fo);
                return fileTx.createFileObject(location, new File(f, nameStr), f, null, null);
            }).get();
}
项目:openjdk-jdk10    文件:BaseClassesNotReRead.java   
private void generateSource(String name, String code) {
    Filer filer = processingEnv.getFiler();
    try (Writer out = filer.createSourceFile(name).openWriter()) {
        out.write(code);
        out.close();
    } catch (IOException e) {
        processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, e.toString());
    }
}
项目:openjdk-jdk10    文件:GetTask_FileManagerTest.java   
/**
 * Verify that exceptions from a bad file manager are thrown as expected.
 */
@Test
public void testBadFileManager() throws Exception {
    JavaFileObject srcFile = createSimpleJavaFileObject();
    DocumentationTool tool = ToolProvider.getSystemDocumentationTool();
    StandardJavaFileManager fm = new TestFileManager() {
        @Override
        public Iterable<JavaFileObject> list(Location location,
                String packageName,
                Set<Kind> kinds,
                boolean recurse)
                throws IOException {
            throw new UnexpectedError();
        }
    };
    fm.setLocation(DocumentationTool.Location.DOCUMENTATION_OUTPUT, Arrays.asList(getOutDir()));
    Iterable<? extends JavaFileObject> files = Arrays.asList(srcFile);
    DocumentationTask t = tool.getTask(null, fm, null, null, null, files);
    try {
        t.call();
        error("call completed without exception");
    } catch (RuntimeException e) {
        Throwable c = e.getCause();
        if (c.getClass() == UnexpectedError.class)
            System.err.println("exception caught as expected: " + c);
        else
            throw e;
    }
}
项目:EatDubbo    文件:JdkCompiler.java   
@Override
public JavaFileObject getJavaFileForOutput(Location location, String qualifiedName, Kind kind, FileObject outputFile)
        throws IOException {
    JavaFileObject file = new JavaFileObjectImpl(qualifiedName, kind);
    classLoader.add(qualifiedName, file);
    return file;
}
项目:Moenagade    文件:ByteJavaFileManager.java   
@Override
public JavaFileObject getJavaFileForOutput(Location location, String className, Kind kind, FileObject sibling) throws IOException
{
  try
  {
    JavaFileObject jfo = new ByteArrayJFO(className, kind);
    store.put(className, jfo);
    return jfo;
  }
  catch(Exception e)
  {
      System.out.println(e);
      return null;
  }
}
项目:dubbo2    文件:JdkCompiler.java   
@Override
public JavaFileObject getJavaFileForOutput(Location location, String qualifiedName, Kind kind, FileObject outputFile)
        throws IOException {
    JavaFileObject file = new JavaFileObjectImpl(qualifiedName, kind);
    classLoader.add(qualifiedName, file);
    return file;
}
项目:javaide    文件:WrappingJavaFileManager.java   
/**
 * @throws IllegalStateException {@inheritDoc}
 */
public Iterable<JavaFileObject> list(Location location,
                                     String packageName,
                                     Set<Kind> kinds,
                                     boolean recurse)
    throws IOException
{
    return wrap(super.list(location, packageName, kinds, recurse));
}
项目:javaide    文件:WrappingJavaFileManager.java   
/**
 * @throws IllegalArgumentException {@inheritDoc}
 * @throws UnsupportedOperationException {@inheritDoc}
 * @throws IllegalStateException {@inheritDoc}
 */
public JavaFileObject getJavaFileForInput(Location location,
                                          String className,
                                          Kind kind)
    throws IOException
{
    return wrap(super.getJavaFileForInput(location, className, kind));
}
项目:javaide    文件:WrappingJavaFileManager.java   
/**
 * @throws IllegalArgumentException {@inheritDoc}
 * @throws UnsupportedOperationException {@inheritDoc}
 * @throws IllegalStateException {@inheritDoc}
 */
public JavaFileObject getJavaFileForOutput(Location location,
                                           String className,
                                           Kind kind,
                                           FileObject sibling)
    throws IOException
{
    return wrap(super.getJavaFileForOutput(location, className, kind, unwrap(sibling)));
}
项目:javaide    文件:BaseFileManager.java   
public static Kind getKind(String name) {
    if (name.endsWith(Kind.CLASS.extension))
        return Kind.CLASS;
    else if (name.endsWith(Kind.SOURCE.extension))
        return Kind.SOURCE;
    else if (name.endsWith(Kind.HTML.extension))
        return Kind.HTML;
    else
        return Kind.OTHER;
}
项目:javaide    文件:ForwardingJavaFileManager.java   
/**
 * @throws IllegalArgumentException {@inheritDoc}
 * @throws IllegalStateException {@inheritDoc}
 */
public JavaFileObject getJavaFileForInput(Location location,
                                          String className,
                                          Kind kind)
    throws IOException
{
    return fileManager.getJavaFileForInput(location, className, kind);
}
项目:javaide    文件:ForwardingJavaFileManager.java   
/**
 * @throws IllegalArgumentException {@inheritDoc}
 * @throws IllegalStateException {@inheritDoc}
 */
public JavaFileObject getJavaFileForOutput(Location location,
                                           String className,
                                           Kind kind,
                                           FileObject sibling)
    throws IOException
{
    return fileManager.getJavaFileForOutput(location, className, kind, sibling);
}
项目:openjdk-jdk10    文件:ElementStructureTest.java   
@Override
public JavaFileObject getJavaFileForInput(Location location, String className, Kind kind) throws IOException {
    if (location != StandardLocation.PLATFORM_CLASS_PATH || kind != Kind.CLASS)
        return null;

    return className2File.get(className);
}
项目:openjdk-jdk10    文件:ClassFinder.java   
/**
 * Scans platform class path for files in given package.
 */
private void scanPlatformPath(PackageSymbol p) throws IOException {
    fillIn(p, PLATFORM_CLASS_PATH,
           list(PLATFORM_CLASS_PATH,
                p,
                p.fullname.toString(),
                allowSigFiles ? EnumSet.of(JavaFileObject.Kind.CLASS,
                                           JavaFileObject.Kind.OTHER)
                              : EnumSet.of(JavaFileObject.Kind.CLASS)));
}
项目:openjdk-jdk10    文件:SmartFileManager.java   
@Override @DefinedBy(Api.COMPILER)
public JavaFileObject getJavaFileForInput(Location location,
                                          String className,
                                          Kind kind) throws IOException {
    JavaFileObject file = super.getJavaFileForInput(location, className, kind);
    file = locWrap(file, location);
    if (file == null || visibleSources.isEmpty()) {
        return file;
    }

    if (visibleSources.contains(file.toUri()) || isModuleInfo(file)) {
        return file;
    }
    return null;
}
项目:otter-G    文件:JavaFileManagerImpl.java   
@Override
public JavaFileObject getJavaFileForOutput(Location location, String qualifiedName, Kind kind, FileObject outputFile)
                                                                                                                     throws IOException {
    JavaFileObject file = new JavaFileObjectImpl(qualifiedName, kind);
    classLoader.add(qualifiedName, file);
    return file;
}
项目:openjdk-jdk10    文件:ModuleAndPackageLocations.java   
@Test
public void testGetModuleForPath(Path outerBase) throws Exception {
    doRunTest(outerBase, (base, fm) -> {
        Location cOutput = fm.getLocationForModule(StandardLocation.SOURCE_OUTPUT, "c");
        JavaFileObject testFO = fm.getJavaFileForOutput(cOutput, "test.Test", Kind.CLASS, null);
        testFO.openOutputStream().close();
        Location cOutput2 = fm.getLocationForModule(StandardLocation.SOURCE_OUTPUT, testFO);

        if (cOutput != cOutput2) {
            throw new AssertionError("Unexpected location: " + cOutput2 + ", expected: " +cOutput);
        }
    });
}
项目:OpenJSharp    文件:WrappingJavaFileManager.java   
/**
 * @throws IllegalArgumentException {@inheritDoc}
 * @throws UnsupportedOperationException {@inheritDoc}
 * @throws IllegalStateException {@inheritDoc}
 */
public JavaFileObject getJavaFileForInput(Location location,
                                          String className,
                                          Kind kind)
    throws IOException
{
    return wrap(super.getJavaFileForInput(location, className, kind));
}
项目:OpenJSharp    文件:WrappingJavaFileManager.java   
/**
 * @throws IllegalArgumentException {@inheritDoc}
 * @throws UnsupportedOperationException {@inheritDoc}
 * @throws IllegalStateException {@inheritDoc}
 */
public JavaFileObject getJavaFileForOutput(Location location,
                                           String className,
                                           Kind kind,
                                           FileObject sibling)
    throws IOException
{
    return wrap(super.getJavaFileForOutput(location, className, kind, unwrap(sibling)));
}
项目:OpenJSharp    文件:BaseFileManager.java   
public static Kind getKind(String name) {
    if (name.endsWith(Kind.CLASS.extension))
        return Kind.CLASS;
    else if (name.endsWith(Kind.SOURCE.extension))
        return Kind.SOURCE;
    else if (name.endsWith(Kind.HTML.extension))
        return Kind.HTML;
    else
        return Kind.OTHER;
}
项目:openjdk-jdk10    文件:Modules.java   
@Override
public void complete(Symbol sym) throws CompletionFailure {
    ModuleSymbol msym = moduleFinder.findModule((ModuleSymbol) sym);

    if (msym.kind == ERR) {
        //make sure the module is initialized:
        msym.directives = List.nil();
        msym.exports = List.nil();
        msym.provides = List.nil();
        msym.requires = List.nil();
        msym.uses = List.nil();
    } else if ((msym.flags_field & Flags.AUTOMATIC_MODULE) != 0) {
        setupAutomaticModule(msym);
    } else {
        msym.module_info.complete();
    }

    // If module-info comes from a .java file, the underlying
    // call of classFinder.fillIn will have called through the
    // source completer, to Enter, and then to Modules.enter,
    // which will call completeModule.
    // But, if module-info comes from a .class file, the underlying
    // call of classFinder.fillIn will just call ClassReader to read
    // the .class file, and so we call completeModule here.
    if (msym.module_info.classfile == null || msym.module_info.classfile.getKind() == Kind.CLASS) {
        completeModule(msym);
    }
}
项目:OpenJSharp    文件:ForwardingJavaFileManager.java   
/**
 * @throws IOException {@inheritDoc}
 * @throws IllegalStateException {@inheritDoc}
 */
public Iterable<JavaFileObject> list(Location location,
                                     String packageName,
                                     Set<Kind> kinds,
                                     boolean recurse)
    throws IOException
{
    return fileManager.list(location, packageName, kinds, recurse);
}
项目:dubbocloud    文件:JdkCompiler.java   
@Override
public JavaFileObject getJavaFileForOutput(Location location, String qualifiedName, Kind kind, FileObject outputFile)
        throws IOException {
    JavaFileObject file = new JavaFileObjectImpl(qualifiedName, kind);
    classLoader.add(qualifiedName, file);
    return file;
}
项目:dubbox-hystrix    文件:JdkCompiler.java   
@Override
public JavaFileObject getJavaFileForOutput(Location location, String qualifiedName, Kind kind, FileObject outputFile)
        throws IOException {
    JavaFileObject file = new JavaFileObjectImpl(qualifiedName, kind);
    classLoader.add(qualifiedName, file);
    return file;
}
项目:jdk8u-jdk    文件:MemoryClassLoader.java   
@Override
public Output getJavaFileForOutput(Location location, String name, Kind kind, FileObject source) {
    Output mc = this.map.get(name);
    if (mc == null) {
        mc = new Output(name);
        this.map.put(name, mc);
    }
    return mc;
}
项目:openjdk-jdk10    文件:Modules.java   
private void setupAutomaticModule(ModuleSymbol msym) throws CompletionFailure {
    try {
        ListBuffer<Directive> directives = new ListBuffer<>();
        ListBuffer<ExportsDirective> exports = new ListBuffer<>();
        Set<String> seenPackages = new HashSet<>();

        for (JavaFileObject clazz : fileManager.list(msym.classLocation, "", EnumSet.of(Kind.CLASS), true)) {
            String binName = fileManager.inferBinaryName(msym.classLocation, clazz);
            String pack = binName.lastIndexOf('.') != (-1) ? binName.substring(0, binName.lastIndexOf('.')) : ""; //unnamed package????
            if (seenPackages.add(pack)) {
                ExportsDirective d = new ExportsDirective(syms.enterPackage(msym, names.fromString(pack)), null);
                //TODO: opens?
                directives.add(d);
                exports.add(d);
            }
        }

        msym.exports = exports.toList();
        msym.provides = List.nil();
        msym.requires = List.nil();
        msym.uses = List.nil();
        msym.directives = directives.toList();
        msym.flags_field |= Flags.ACYCLIC;
    } catch (IOException ex) {
        throw new IllegalStateException(ex);
    }
}
项目:openjdk-jdk10    文件:ToolBox.java   
@Override
public JavaFileObject getJavaFileForOutput(Location location,
                                           String name,
                                           JavaFileObject.Kind kind,
                                           FileObject sibling)
{
    return new MemoryFileObject(location, name, kind);
}
项目:openjdk-jdk10    文件:ForwardingJavaFileManager.java   
/**
 * @throws IOException {@inheritDoc}
 * @throws IllegalStateException {@inheritDoc}
 */
public Iterable<JavaFileObject> list(Location location,
                                     String packageName,
                                     Set<Kind> kinds,
                                     boolean recurse)
    throws IOException
{
    return fileManager.list(location, packageName, kinds, recurse);
}