Java Code Examples for javax.tools.JavaFileObject#Kind

The following examples show how to use javax.tools.JavaFileObject#Kind . 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 File: JavacFileManager.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
public Iterable<JavaFileObject> list(Location location,
                                     String packageName,
                                     Set<JavaFileObject.Kind> kinds,
                                     boolean recurse)
    throws IOException
{
    // validatePackageName(packageName);
    nullCheck(packageName);
    nullCheck(kinds);

    Iterable<? extends File> path = getLocation(location);
    if (path == null)
        return List.nil();
    RelativeDirectory subdirectory = RelativeDirectory.forPackage(packageName);
    ListBuffer<JavaFileObject> results = new ListBuffer<JavaFileObject>();

    for (File directory : path)
        listContainer(directory, subdirectory, kinds, recurse, results);
    return results.toList();
}
 
Example 2
Source File: JavaInMemoryFileManager.java    From buck with Apache License 2.0 6 votes vote down vote up
@Override
public Iterable<JavaFileObject> list(
    Location location, String packageName, Set<JavaFileObject.Kind> kinds, boolean recurse)
    throws IOException {
  if (shouldDelegate(location)) {
    return delegate.list(location, packageName, kinds, recurse);
  }

  ArrayList<JavaFileObject> results = new ArrayList<>();
  for (JavaFileObject fromSuper : delegate.list(location, packageName, kinds, recurse)) {
    results.add(fromSuper);
  }

  String packageDirPath = getPath(packageName) + '/';
  for (String filepath : fileForOutputPaths.keySet()) {
    if (recurse && filepath.startsWith(packageDirPath)) {
      results.add(fileForOutputPaths.get(filepath));
    } else if (!recurse
        && filepath.startsWith(packageDirPath)
        && filepath.substring(packageDirPath.length()).indexOf('/') < 0) {
      results.add(fileForOutputPaths.get(filepath));
    }
  }

  return results;
}
 
Example 3
Source File: StaticCompiler.java    From Box with Apache License 2.0 5 votes vote down vote up
@Override
public JavaFileObject getJavaFileForOutput(Location location, String className, JavaFileObject.Kind kind, FileObject sibling) {
	if (kind == JavaFileObject.Kind.CLASS) {
		File file = new File(outDir, className.replace('.', '/') + ".class");
		files.add(file);
		return new ClassFileObject(file, kind);
	}
	throw new UnsupportedOperationException("Can't save location with kind: " + kind);
}
 
Example 4
Source File: ToolBox.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Constructs a memory file object.
 * @param name binary name of the class to be stored in this file object
 */
MemoryFileObject(Location location, String name, JavaFileObject.Kind kind) {
    super(URI.create("mfm:///" + name.replace('.','/') + kind.extension),
          Kind.CLASS);
    this.location = location;
    this.name = name;
}
 
Example 5
Source File: SimpleCompiler.java    From yGuard with MIT License 5 votes vote down vote up
public JavaFileObject getJavaFileForOutput(
        final Location location,
        final String className,
        final JavaFileObject.Kind kind,
        final FileObject sibling
) throws IOException {
  jos.putNextEntry(new JarEntry(className.replace('.', '/') + JavaFileObject.Kind.CLASS.extension));
  return new StreamFileObject(jos, super.getJavaFileForOutput(location, className, kind, sibling));
}
 
Example 6
Source File: JavacFileManager.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
/**
 * Insert all files in subdirectory subdirectory of archive archive
 * which match fileKinds into resultList
 */
private void listArchive(Archive archive,
                         RelativeDirectory subdirectory,
                         Set<JavaFileObject.Kind> fileKinds,
                         boolean recurse,
                         ListBuffer<JavaFileObject> resultList) {
    // Get the files directly in the subdir
    List<String> files = archive.getFiles(subdirectory);
    if (files != null) {
        for (; !files.isEmpty(); files = files.tail) {
            String file = files.head;
            if (isValidFile(file, fileKinds)) {
                resultList.append(archive.getFileObject(subdirectory, file));
            }
        }
    }
    if (recurse) {
        for (RelativeDirectory s : archive.getSubdirectories()) {
            if (subdirectory.contains(s)) {
                // Because the archive map is a flat list of directories,
                // the enclosing loop will pick up all child subdirectories.
                // Therefore, there is no need to recurse deeper.
                listArchive(archive, s, fileKinds, false, resultList);
            }
        }
    }
}
 
Example 7
Source File: JavacFiler.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
private JavaFileObject createSourceOrClassFile(boolean isSourceFile, String name) throws IOException {
    if (lint) {
        int periodIndex = name.lastIndexOf(".");
        if (periodIndex != -1) {
            String base = name.substring(periodIndex);
            String extn = (isSourceFile ? ".java" : ".class");
            if (base.equals(extn))
                log.warning("proc.suspicious.class.name", name, extn);
        }
    }
    checkNameAndExistence(name, isSourceFile);
    Location loc = (isSourceFile ? SOURCE_OUTPUT : CLASS_OUTPUT);
    JavaFileObject.Kind kind = (isSourceFile ?
                                JavaFileObject.Kind.SOURCE :
                                JavaFileObject.Kind.CLASS);

    JavaFileObject fileObject =
        fileManager.getJavaFileForOutput(loc, name, kind, null);
    checkFileReopening(fileObject, true);

    if (lastRound)
        log.warning("proc.file.create.last.round", name);

    if (isSourceFile)
        aggregateGeneratedSourceNames.add(name);
    else
        aggregateGeneratedClassNames.add(name);
    openTypeNames.add(name);

    return new FilerOutputJavaFileObject(name, fileObject);
}
 
Example 8
Source File: JavacFileManager.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
public JavaFileObject getFileForOutput(String classname,
                                       JavaFileObject.Kind kind,
                                       JavaFileObject sibling)
    throws IOException
{
    return getJavaFileForOutput(CLASS_OUTPUT, classname, kind, sibling);
}
 
Example 9
Source File: JavacFileManager.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Insert all files in subdirectory subdirectory of archive archive
 * which match fileKinds into resultList
 */
private void listArchive(Archive archive,
                           RelativeDirectory subdirectory,
                           Set<JavaFileObject.Kind> fileKinds,
                           boolean recurse,
                           ListBuffer<JavaFileObject> resultList) {
    // Get the files directly in the subdir
    List<String> files = archive.getFiles(subdirectory);
    if (files != null) {
        for (; !files.isEmpty(); files = files.tail) {
            String file = files.head;
            if (isValidFile(file, fileKinds)) {
                resultList.append(archive.getFileObject(subdirectory, file));
            }
        }
    }
    if (recurse) {
        for (RelativeDirectory s: archive.getSubdirectories()) {
            if (subdirectory.contains(s)) {
                // Because the archive map is a flat list of directories,
                // the enclosing loop will pick up all child subdirectories.
                // Therefore, there is no need to recurse deeper.
                listArchive(archive, s, fileKinds, false, resultList);
            }
        }
    }
}
 
Example 10
Source File: JavaInMemoryFileManager.java    From buck with Apache License 2.0 4 votes vote down vote up
private static String getPath(String className, JavaFileObject.Kind kind) {
  return className.replace('.', '/') + kind.extension;
}
 
Example 11
Source File: RegularFileObject.java    From javaide with GNU General Public License v3.0 4 votes vote down vote up
public JavaFileObject.Kind getKind() {
    return getKind(name);
}
 
Example 12
Source File: RegularFileObject.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
@Override
public JavaFileObject.Kind getKind() {
    return getKind(name);
}
 
Example 13
Source File: MemoryFileManager.java    From kalang with MIT License 4 votes vote down vote up
@Override
public JavaFileObject getJavaFileForInput(Location location, String className, JavaFileObject.Kind kind) throws IOException {
    return fm.getJavaFileForInput(location, className, kind);
}
 
Example 14
Source File: FakeStandardJavaFileManager.java    From buck with Apache License 2.0 4 votes vote down vote up
@Override
public boolean isNameCompatible(String simpleName, JavaFileObject.Kind kind) {
  throw new UnsupportedOperationException();
}
 
Example 15
Source File: JavadocClassReader.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Override getPackageFileKinds to include search for package.html
 */
@Override
protected EnumSet<JavaFileObject.Kind> getPackageFileKinds() {
    return docenv.docClasses ? noSource : all;
}
 
Example 16
Source File: JavacProcessingEnvironment.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
private boolean isPkgInfo(JavaFileObject fo, JavaFileObject.Kind kind) {
    return fo.isNameCompatible("package-info", kind);
}
 
Example 17
Source File: FileObjectArchive.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@NonNull
@Override
public Iterable<JavaFileObject> getFiles(
        @NonNull final String folderName,
        @NullAllowed final ClassPath.Entry entry,
        @NullAllowed final Set<JavaFileObject.Kind> kinds,
        @NullAllowed final JavaFileFilterImplementation filter,
        final boolean recursive) throws IOException {
    final FileObject folder = root.getFileObject(folderName);
    if (folder == null || !(entry == null || entry.includes(folder))) {
        return Collections.<JavaFileObject>emptySet();
    }
    final Enumeration<? extends FileObject> children;
    final List<JavaFileObject> result;
    if (recursive) {
        children = Enumerations.filter(
                folder.getChildren(recursive),
                (p,x)->{
                    return  !p.isFolder() && isInJavaPackage(folder,p) ?
                            p :
                            null;
                });
        result = new ArrayList<>(/*unknown size*/);
    } else {
        final FileObject[] chlds = folder.getChildren();
        children = Enumerations.array(chlds);
        result = new ArrayList<>(chlds.length);
    }
    while (children.hasMoreElements()) {
        final FileObject fo = children.nextElement();
        if (fo.isData() && (entry == null || entry.includes(fo))) {
            final Kind kind = FileObjects.getKind(fo.getExt());
            if (kinds == null || kinds.contains (kind)) {
                JavaFileObject file;
                if (kind == Kind.CLASS) {
                    file = FileObjects.fileObjectFileObject(fo, root, filter, null);
                } else {
                    file = FileObjects.sourceFileObject(fo, root, filter,false);
                }
                result.add(file);
            }
        }
    }
    return result;
}
 
Example 18
Source File: AsyncJavaSymbolDescriptor.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@Override
public JavaFileObject getJavaFileForInput(Location location, String className, JavaFileObject.Kind kind) throws IOException {
    return delegate.getJavaFileForInput(location, className, kind);
}
 
Example 19
Source File: JavadocClassReader.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Override getPackageFileKinds to include search for package.html
 */
@Override
protected EnumSet<JavaFileObject.Kind> getPackageFileKinds() {
    return docenv.docClasses ? noSource : all;
}
 
Example 20
Source File: JavadocClassReader.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Override getPackageFileKinds to include search for package.html
 */
@Override
protected EnumSet<JavaFileObject.Kind> getPackageFileKinds() {
    return docenv.docClasses ? noSource : all;
}