Java Code Examples for org.netbeans.api.java.classpath.ClassPath#contains()

The following examples show how to use org.netbeans.api.java.classpath.ClassPath#contains() . 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: CustomIconEditor.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private void importButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_importButtonActionPerformed
    File[] files = selectedExternalFile != null ?
        files = new File[] { selectedExternalFile } : null;
    FileObject srcFile = propertyEditor.getSourceFile();
    ImportImageWizard.lastDirectoryUsed = getFileChooserDir();
    FileObject[] imported = new ImportImageWizard(files, selectedPackage, srcFile).show();
    lastDirectoryUsed = ImportImageWizard.lastDirectoryUsed;
    FileObject fo = imported != null && imported.length > 0 ?  imported[0] : null;
    if (fo != null) {
        ClassPath cp = ClassPath.getClassPath(srcFile, ClassPath.SOURCE);
        if (cp.contains(fo)) {
            setPackageRoot(cp.findOwnerRoot(fo));
            selectedPackage = null; // to be sure it is refreshed
            setPackage(fo.getParent());
            setPackageFile(fo);
            classPathRadio.setSelected(true);
            updateValue();
        }
    }
}
 
Example 2
Source File: JavaWhereUsedQueryPlugin.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private static Collection<FileObject> getImplementorsRecursive(ClassIndex idx, ClasspathInfo cpInfo, TypeElement el, AtomicBoolean cancel) {
    Set<?> implementorsAsHandles = RefactoringUtils.getImplementorsAsHandles(idx, cpInfo, el, cancel);

    if(cancel != null && cancel.get()) {
        return Collections.<FileObject>emptySet();
    }
    @SuppressWarnings("unchecked")
    Collection<FileObject> set = SourceUtilsEx.getFiles((Collection<ElementHandle<? extends Element>>) implementorsAsHandles, cpInfo, cancel);

    // filter out files that are not on source path
    ClassPath source = cpInfo.getClassPath(ClasspathInfo.PathKind.SOURCE);
    Collection<FileObject> set2 = new ArrayList<>(set.size());
    for (FileObject fo : set) {
        if (source.contains(fo)) {
            set2.add(fo);
        }
        if(cancel != null && cancel.get()) {
            return Collections.<FileObject>emptySet();
        }
    }
    return set2;
}
 
Example 3
Source File: FormI18nStringEditor.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/** Overrides superclass method.
 * @return <code>ResourceBundlePanel</code> fed with <code>FormI18nString</code> value. */
public Component getCustomEditor() {
    FormI18nString formI18nString;
    Object value = getValue();
    if (value instanceof FormI18nString) {
        formI18nString = new FormI18nString((FormI18nString)value);
    }
    else {
        formI18nString = createFormI18nString();
        if (value instanceof String)
            formI18nString.setValue((String)value);
        DataObject lastResource = I18nUtil.getOptions().getLastResource2(sourceDataObject);
        if (lastResource != null) {
            FileObject sourceFile = sourceDataObject.getPrimaryFile();
            FileObject bundleFile = lastResource.getPrimaryFile();
            ClassPath sourceClassPath = ClassPath.getClassPath(
                                            sourceFile, ClassPath.SOURCE);
            if (sourceClassPath.contains(bundleFile)) {
                formI18nString.getSupport().getResourceHolder().setResource(
                        lastResource);
            }
        }
    }
    return new CustomEditor(formI18nString, getProject(), sourceDataObject.getPrimaryFile());
}
 
Example 4
Source File: ManagerUtil.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/**
 * Check if a project has a library reference to the named library qualified by the type parameter.
 * @param project Target project
 * @param library Library object
 * @param type Determines whether the library is to be referenced from the design-time classpath or deploy
 * time classpath
 * @return Returns true if the library is already referenced by the project, false otherwise
 */
public static boolean hasLibraryReference(Project project, Library library, String type) {
    List lst = library.getContent("classpath");
    if (lst.isEmpty()) {
        return false;
    }

    URL url = (URL) lst.get(0);
    FileObject obj = URLMapper.findFileObject(url);
    if (obj == null) {
        return false;
    }

    // XXX NetBeans API not finished yet
    type = ClassPath.COMPILE;
    ClassPath cp = ClassPath.getClassPath(getSourceRoot(project), type);

    if ( cp== null){
        return false;
    }
    return cp.contains(obj);
}
 
Example 5
Source File: ManagerUtil.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/**
 * Check if a project has an root reference to the named root qualified by the type parameter.
 * @param project Target project
 * @param rootFile file object of the root
 * @param type Determines whether the root is to be referenced from the design-time classpath or deploy
 * time classpath
 * @return Returns true if the root is already referenced by the project, false otherwise
 */
public static boolean hasRootReference(Project project, URL rootFile, String type) {
    FileObject obj = URLMapper.findFileObject(rootFile);
    if (obj == null) {
        return false;
    }

    // XXX NetBeans API not finished yet
    type = ClassPath.COMPILE;
    ClassPath cp = ClassPath.getClassPath(getSourceRoot(project), type);

    if ( cp==null){
        return false;
    }
    return cp.contains(obj);
}
 
Example 6
Source File: CustomIconEditor.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * Tries to find given file on classpath and set it as selected classpath file.
 * @return true if the file is on classpath
 */
private boolean setExternalAsCPFile(File file) {
    FileObject fo = FileUtil.toFileObject(file);
    if (fo != null) {
        ClassPath cp = ClassPath.getClassPath(propertyEditor.getSourceFile(), ClassPath.SOURCE);
        if (cp.contains(fo)) {
            setPackageRoot(cp.findOwnerRoot(fo));
            setPackage(fo.getParent());
            setPackageFile(fo);
            return true;
        }
    }
    return false;
}
 
Example 7
Source File: FormRefactoringUpdate.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void packageRename(FileObject originalPkgFile) {
    FormEditorSupport fes = getFormEditorSupport();
    if (fes.isOpened()) {
        fes.closeFormEditor();
    }
    String oldName = refInfo.getOldName(originalPkgFile);
    String newName = refInfo.getNewName();
    if (refInfo.getChangeType() == RefactoringInfo.ChangeType.FOLDER_RENAME) {
        // determine full package name for renamed folder
        ClassPath cp = ClassPath.getClassPath(originalPkgFile, ClassPath.SOURCE);
        FileObject parent = originalPkgFile.getParent();
        if (cp != null && cp.contains(parent)) {
            String parentPkgName = cp.getResourceName(parent, '.', false);
            if (parentPkgName != null && parentPkgName.length() > 0) {
                oldName = parentPkgName + "." + oldName; // NOI18N
                newName = parentPkgName + "." + newName; // NOI18N
            }
        }
    }
    if (replaceClassOrPkgName(new String[] { oldName },
                              new String[] { newName },
                              true)
            && !isGuardedCodeChanging()) {
        // some package references in resource were changed in the form file
        // (not class names since no change in guarded code came from java
        // refactoring) and because no component has changed we can load the
        // form and regenerate to get the new resource names into code
        updateForm(true);
    }
}
 
Example 8
Source File: J2SEModularProjectUtil.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public static boolean hasModuleInfo(@NonNull final SourceRoots roots) {
    ClassPath scp = null;
    for (FileObject root : roots.getRoots()) {
        FileObject mInfo = J2SEModularProjectUtil.getModuleInfo(root);
        if (mInfo != null) {
            if (scp == null) {
                scp = ClassPath.getClassPath(root, ClassPath.SOURCE);
            }
            if (scp.contains(mInfo)) {
                return true;
            }
        }
    }
    return false;
}
 
Example 9
Source File: J2SEProjectUtil.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public static boolean hasModuleInfo(@NonNull final SourceRoots roots) {
    ClassPath scp = null;
    for (FileObject root : roots.getRoots()) {
        FileObject mInfo = J2SEProjectUtil.getModuleInfo(root);
        if (mInfo != null) {
            if (scp == null) {
                scp = ClassPath.getClassPath(root, ClassPath.SOURCE);
            }
            if (scp.contains(mInfo)) {
                return true;
            }
        }
    }
    return false;
}
 
Example 10
Source File: LibrariesHelper.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public static void addArchivesToProject(Project project, FileObject targetSource,
        List<FileObject> jars, String classPathType) {
    if (targetSource == null) {
        targetSource = getSourceRoot(project);
    }
    ClassPath classPath = ClassPath.getClassPath(targetSource, classPathType);
    if (classPath != null) {  //hack for PHP
        try {
            FileObject wsClientsSubDir = getWebServiceClientLibraryDir(project);
            ArrayList<URL> archiveJars = new ArrayList<URL>();
            for (FileObject jarFO : jars) {
                try {
                    FileObject destJar = wsClientsSubDir.getFileObject(jarFO.getNameExt());
                    if (destJar == null) {
                        destJar = FileUtil.copyFile(jarFO, wsClientsSubDir, jarFO.getName());
                    }
                    if (classPath.contains(destJar)) {
                        continue;
                    }
                    archiveJars.add(new URL(destJar.toURL().toExternalForm() + "/")); // NOI18N

                } catch (IOException ex) {
                    Exceptions.printStackTrace(ex);
                }
                URL[] archiveURLs = archiveJars.toArray(new URL[archiveJars.size()]);
                ProjectClassPathModifier.addRoots(archiveURLs, targetSource, classPathType);
            }

        } catch (IOException ioe) {
            Exceptions.printStackTrace(ioe);
        }
    }
}
 
Example 11
Source File: PhpSourcePath.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private static FileType getFileTypeFromIncludeClassPath(FileObject file) {
    // now, check include path of opened projects
    ClassPath classPath = IncludePathClassPathProvider.findProjectIncludePath(file);
    if (classPath != null && classPath.contains(file)) {
        // internal?
        if (org.netbeans.modules.php.project.util.PhpProjectUtils.isInternalFile(file)) {
            return FileType.INTERNAL;
        }
        // include
        return FileType.INCLUDE;
    }
    return null;
}
 
Example 12
Source File: IncludePathClassPathProvider.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public static ClassPath findProjectIncludePath(FileObject file) {
    PROJECT_INCLUDES_LOCK.readLock().lock();
    try {
        for (ClassPath classPath : PROJECT_INCLUDES) {
            if (classPath.contains(file)) {
                return classPath;
            }
        }
    } finally {
        PROJECT_INCLUDES_LOCK.readLock().unlock();
    }
    return null;
}
 
Example 13
Source File: GlobalFormatAction.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private static void addRecursivelly(FileObject top, List<FileObject> into, Set<String> sourceIds, ClassPath sourceCP, SourceGroup sg, AtomicBoolean cancel) {
    List<FileObject> todo = new LinkedList<FileObject>();
    Iterator<String> sIDIter = sourceIds.iterator();
    
    while (sourceCP == null && sIDIter.hasNext()) {
        if (cancel.get()) return;
        sourceCP = ClassPath.getClassPath(top, sIDIter.next());
    }

    todo.add(top);

    while (!todo.isEmpty()) {
        if (cancel.get()) return;
        
        FileObject current = todo.remove(0);

        if (!VisibilityQuery.getDefault().isVisible(current)) continue;
        if (sourceCP != null && !sourceCP.contains(current)) continue;
        if (sg != null && !sg.contains(current)) continue;

        if (current.isData()) {
            into.add(current);
        }

        todo.addAll(Arrays.asList(current.getChildren()));
    }
}
 
Example 14
Source File: I18nPanel.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public void setDefaultResource(DataObject dataObject) {
        if (dataObject != null) {
            // look for peer Bundle.properties
            FileObject fo = dataObject.getPrimaryFile();
            ClassPath cp = ClassPath.getClassPath(fo, ClassPath.SOURCE);

            if (cp != null) {
                FileObject folder = cp.findResource(cp.getResourceName(fo.getParent()));

                while (folder != null && cp.contains(folder)) {
                
                    String rn = cp.getResourceName(folder) + "/Bundle.properties"; // NOI18N
                
                    FileObject peer = cp.findResource(rn);
                    if (peer == null) {
                        //Try to find any properties file
                        Enumeration<? extends FileObject> data = Enumerations.filter(folder.getData(false), new Enumerations.Processor(){
                            public Object process(Object obj, Collection alwaysNull) {
                                if (obj instanceof FileObject &&
                                        "properties".equals( ((FileObject)obj).getExt())){ //NOI18N
                                    return obj;
                                } else {
                                    return null;
                                }
                            }
                        });
                        if (data.hasMoreElements()) {
                            peer = data.nextElement();
                        }
                    }
                    if (peer != null) {
                        try {
                            DataObject peerDataObject = DataObject.find(peer);
//                          ((ResourcePanel)resourcePanel).setResource(peerDataObject);
                            propertyPanel.setResource(peerDataObject);
                            return;
                        } catch (IOException ex) {
                            // no default resource
                        }
                    }
                    folder = folder.getParent();
                }
            }
        }
    }