Java Code Examples for org.openide.filesystems.FileObject.getData()

The following are Jave code examples for showing how to use getData() of the org.openide.filesystems.FileObject 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: ApisupportAntUtils.java   View Source Code Vote up 6 votes
/**
 * Scan recursively through all folders in the given <code>dir</code> and
 * add every directory/package, which contains at least one file with the
 * given extension (probably class or java), into the given
 * <code>validPkgs</code> set. Added entries are in the form of regular java
 * package (x.y.z)
 */
private static void scanForPackages(final Set<FileObject> validPkgs, final FileObject dir, final String ext) {
    if (dir == null) {
        return;
    }
    for (Enumeration en1 = dir.getFolders(false); en1.hasMoreElements(); ) {
        FileObject subDir = (FileObject) en1.nextElement();
        if (VisibilityQuery.getDefault().isVisible(subDir)) {
            scanForPackages(validPkgs, subDir, ext);
        }
    }
    for (Enumeration en2 = dir.getData(false); en2.hasMoreElements(); ) {
        FileObject kid = (FileObject) en2.nextElement();
        if (kid.hasExt(ext) && Utilities.isJavaIdentifier(kid.getName())) {
            // at least one class inside directory -> valid package
            validPkgs.add(dir);
            break;
        }
    }
}
 
Example 2
Project: incubator-netbeans   File: JavaSourceHelper.java   View Source Code Vote up 6 votes
public static List<JavaSource> getJavaSources(Project project) {
    List<JavaSource> result = new ArrayList<JavaSource>();
    SourceGroup[] groups = SourceGroupSupport.getJavaSourceGroups(project);

    for (SourceGroup group : groups) {
        FileObject root = group.getRootFolder();
        Enumeration<? extends FileObject> files = root.getData(true);

        while (files.hasMoreElements()) {
            FileObject fobj = files.nextElement();

            if (fobj.getExt().equals(JAVA_EXT)) {
                JavaSource source = JavaSource.forFileObject(fobj);
                result.add(source);
            }
        }
    }

    return result;
}
 
Example 3
Project: incubator-netbeans   File: FileUtilities.java   View Source Code Vote up 5 votes
private static void processFolder(FileObject file, NameObtainer nameObtainer, SortedSet<String> result, boolean onlyRoots) {
    Enumeration<? extends FileObject> dataFiles = file.getData(false);
    Enumeration<? extends FileObject> folders = file.getFolders(false);

    if (dataFiles.hasMoreElements()) {
        while (dataFiles.hasMoreElements()) {
            FileObject kid = dataFiles.nextElement();
            if ((kid.hasExt("java") || kid.hasExt("class")) && Utilities.isJavaIdentifier(kid.getName())) {
                // at least one java or class inside directory -> valid package
                String packageName = nameObtainer.getPackageName(file);
                if (packageName == null) {
                    continue;
                }
                result.add(packageName);
                if (onlyRoots) {
                    // don't recurse into subfolders
                    return;
                } else {
                    // recurse inot subfolders
                    break;
                }
            }
        }
    }

    while (folders.hasMoreElements()) {
        processFolder(folders.nextElement(), nameObtainer, result, onlyRoots);
    }
}