Java Code Examples for javax.tools.JavaFileObject.Kind

The following are Jave code examples for showing how to use Kind of the javax.tools.JavaFileObject class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: incubator-netbeans   File: ModuleNamesTest.java   View Source Code Vote up 6 votes
@NonNull
private Iterable<JavaFileObject> listModuleContent(
        @NonNull final ModLoc modLoc,
        @NonNull final String packageName,
        @NonNull final Set<JavaFileObject.Kind> kinds) throws IOException {
    final CachingArchiveProvider cap = CachingArchiveProvider.getDefault();
    final Collection<JavaFileObject> res = new ArrayList<>();
    if (javaBaseModInfo != null && "java.base".equals(modLoc.getModuleName()) && packageName.isEmpty()) {
        final JavaFileObject jfo = new MemJFO("module-info");
        try(OutputStream out = jfo.openOutputStream()) {
            final byte[] data = javaBaseModInfo.get();
            out.write(data, 0, data.length);
        }
        res.add(jfo);
    }
    for (URL url : modLoc.getRoots()) {
        final Archive ca = cap.getArchive(url, false);
        if (ca != null) {
            StreamSupport.stream(
                    ca.getFiles(FileObjects.convertPackage2Folder(packageName), null, kinds, null, false).spliterator(),
                    false)
                    .forEach(res::add);
        }
    }
    return res;
}
 
Example 2
Project: manifold   File: JavacFileManagerBridge.java   View Source Code Vote up 5 votes
/**
 */
public JavaFileObject getJavaFileForInput( Location location,
                                           String className,
                                           JavaFileObject.Kind kind )
  throws IOException
{
  return fileManager.getJavaFileForInput( location, className, kind );
}
 
Example 3
Project: javaide   File: JavacFileManager.java   View Source Code Vote up 5 votes
public JavaFileObject getJavaFileForInput(Location location,
                                          String className,
                                          JavaFileObject.Kind kind)
        throws IOException {
    nullCheck(location);
    // validateClassName(className);
    nullCheck(className);
    nullCheck(kind);
    if (!sourceOrClass.contains(kind))
        throw new IllegalArgumentException("Invalid kind: " + kind);
    return getFileForInput(location, RelativeFile.forClass(className, kind));
}
 
Example 4
Project: OpenJSharp   File: JavacFileManager.java   View Source Code Vote up 5 votes
public JavaFileObject getFileForOutput(String classname,
                                       JavaFileObject.Kind kind,
                                       JavaFileObject sibling)
    throws IOException
{
    return getJavaFileForOutput(CLASS_OUTPUT, classname, kind, sibling);
}
 
Example 5
Project: javaide   File: JavacFileManager.java   View Source Code Vote up 5 votes
/**
 * Insert all files in subdirectory subdirectory of directory directory
 * which match fileKinds into resultList
 */
private void listDirectory(File directory,
                           RelativeDirectory subdirectory,
                           Set<JavaFileObject.Kind> fileKinds,
                           boolean recurse,
                           ListBuffer<JavaFileObject> resultList) {
    File d = subdirectory.getFile(directory);
    if (!caseMapCheck(d, subdirectory))
        return;

    File[] files = d.listFiles();
    if (files == null)
        return;

    if (sortFiles != null)
        Arrays.sort(files, sortFiles);

    for (File f : files) {
        String fname = f.getName();
        if (f.isDirectory()) {
            if (recurse && SourceVersion.isIdentifier(fname)) {
                listDirectory(directory,
                        new RelativeDirectory(subdirectory, fname),
                        fileKinds,
                        recurse,
                        resultList);
            }
        } else {
            if (isValidFile(fname, fileKinds)) {
                JavaFileObject fe =
                        new RegularFileObject(this, fname, new File(d, fname));
                resultList.append(fe);
            }
        }
    }
}
 
Example 6
Project: openjdk-jdk10   File: JavacFileManager.java   View Source Code Vote up 5 votes
/**
 * Insert all files in a subdirectory of the platform image
 * which match fileKinds into resultList.
 */
@Override
public void list(Path userPath,
                 RelativeDirectory subdirectory,
                 Set<JavaFileObject.Kind> fileKinds,
                 boolean recurse,
                 ListBuffer<JavaFileObject> resultList) throws IOException {
    try {
        JRTIndex.Entry e = getJRTIndex().getEntry(subdirectory);
        if (symbolFileEnabled && e.ctSym.hidden)
            return;
        for (Path file: e.files.values()) {
            if (fileKinds.contains(getKind(file))) {
                JavaFileObject fe
                        = PathFileObject.forJRTPath(JavacFileManager.this, file);
                resultList.append(fe);
            }
        }

        if (recurse) {
            for (RelativeDirectory rd: e.subdirs) {
                list(userPath, rd, fileKinds, recurse, resultList);
            }
        }
    } catch (IOException ex) {
        ex.printStackTrace(System.err);
        log.error(Errors.ErrorReadingFile(userPath, getMessage(ex)));
    }
}
 
Example 7
Project: incubator-netbeans   File: AptSourceFileManager.java   View Source Code Vote up 5 votes
@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();
}
 
Example 8
Project: incubator-netbeans   File: JavaSourceUtilImpl.java   View Source Code Vote up 5 votes
@Override
public JavaFileObject getJavaFileForOutput(Location location, String className, JavaFileObject.Kind kind, javax.tools.FileObject sibling) throws IOException {
    assertLocation(location, true);
    final String[] ncs = FileObjects.getPackageAndName(className);
    return new MemOutFileObject(
            ncs[0],
            String.format("%s%s", ncs[1], kind.extension));
}
 
Example 9
Project: OpenJSharp   File: RegularFileObject.java   View Source Code Vote up 5 votes
@Override
public boolean isNameCompatible(String cn, JavaFileObject.Kind kind) {
    cn.getClass();
    // null check
    if (kind == Kind.OTHER && getKind() != kind) {
        return false;
    }
    String n = cn + kind.extension;
    if (name.equals(n)) {
        return true;
    }
    if (isMacOS && Normalizer.isNormalized(name, Normalizer.Form.NFD)
        && Normalizer.isNormalized(n, Normalizer.Form.NFC)) {
        // On Mac OS X it is quite possible to file name and class
        // name normalized in a different way - in that case we have to normalize file name
        // to the Normal Form Compised (NFC)
        String normName = Normalizer.normalize(name, Normalizer.Form.NFC);
        if (normName.equals(n)) {
            this.name = normName;
            return true;
        }
    }

        if (name.equalsIgnoreCase(n)) {
        try {
            // allow for Windows
            return file.getCanonicalFile().getName().equals(n);
        } catch (IOException e) {
        }
    }
    return false;
}
 
Example 10
Project: openjdk-jdk10   File: JavacFileManager.java   View Source Code Vote up 5 votes
@Override @DefinedBy(Api.COMPILER)
public JavaFileObject getJavaFileForOutput(Location location,
                                           String className,
                                           JavaFileObject.Kind kind,
                                           FileObject sibling)
    throws IOException
{
    checkOutputLocation(location);
    // validateClassName(className);
    nullCheck(className);
    nullCheck(kind);
    if (!sourceOrClass.contains(kind))
        throw new IllegalArgumentException("Invalid kind: " + kind);
    return getFileForOutput(location, RelativeFile.forClass(className, kind), sibling);
}
 
Example 11
Project: openjdk-jdk10   File: PublicMethodsTest.java   View Source Code Vote up 5 votes
@Override
public JavaFileObject getJavaFileForInput(Location location,
                                          String className,
                                          JavaFileObject.Kind kind)
throws IOException {
    if (location == StandardLocation.SOURCE_PATH &&
        kind == JavaFileObject.Kind.SOURCE &&
        TEST_CLASS_NAME.equals(className)) {
        return new SourceFileObject(className, testSource);
    }
    return super.getJavaFileForInput(location, className, kind);
}
 
Example 12
Project: incubator-netbeans   File: JavaSourceUtilImpl.java   View Source Code Vote up 4 votes
@Override
public JavaFileObject getJavaFileForInput(Location location, String className, JavaFileObject.Kind kind) throws IOException {
    assertLocation(location, false);
    return readDelegate.getJavaFileForInput(location, className, kind);
}
 
Example 13
Project: incubator-netbeans   File: FileObjects.java   View Source Code Vote up 4 votes
@Override
public JavaFileObject.Kind getKind() {
    return this.kind;
}
 
Example 14
Project: javaide   File: ClassReader.java   View Source Code Vote up 4 votes
/**
 * specifies types of files to be read when filling in a package symbol
 */
protected EnumSet<JavaFileObject.Kind> getPackageFileKinds() {
    return EnumSet.of(JavaFileObject.Kind.CLASS, JavaFileObject.Kind.SOURCE);
}
 
Example 15
Project: javaide   File: JavacProcessingEnvironment.java   View Source Code Vote up 4 votes
private boolean isPkgInfo(JavaFileObject fo, JavaFileObject.Kind kind) {
    return fo.isNameCompatible("package-info", kind);
}
 
Example 16
Project: OpenJSharp   File: ClassReader.java   View Source Code Vote up 4 votes
@Override
public boolean isNameCompatible(String simpleName, JavaFileObject.Kind kind) {
    return true; // fail-safe mode
}
 
Example 17
Project: incubator-netbeans   File: AbstractSourceFileObject.java   View Source Code Vote up 4 votes
@Override
@NonNull
public final JavaFileObject.Kind getKind() {
    return this.kind;
}
 
Example 18
Project: incubator-netbeans   File: CachingFileManager.java   View Source Code Vote up 4 votes
@Override
public JavaFileObject getJavaFileForOutput( Location l, String className, JavaFileObject.Kind kind, javax.tools.FileObject sibling ) 
    throws IOException, UnsupportedOperationException, IllegalArgumentException {
    throw new UnsupportedOperationException ();
}
 
Example 19
Project: incubator-netbeans   File: PatchModuleFileManager.java   View Source Code Vote up 4 votes
@Override
public JavaFileObject getJavaFileForOutput(Location location, String className, JavaFileObject.Kind kind, FileObject sibling) throws IOException {
    throw new UnsupportedOperationException("Not supported by patch JavaFileManager.");
}
 
Example 20
Project: openjdk-jdk10   File: MemoryFileManager.java   View Source Code Vote up 4 votes
public MemoryJavaFileObject(String name, JavaFileObject.Kind kind) {
    super(URI.create("string:///" + name.replace('.', '/')
            + kind.extension), kind);
}