Search in sources :

Example 1 with ObjectVector

use of org.eclipse.jdt.internal.compiler.util.ObjectVector in project che by eclipse.

the class IndexSelector method initializeIndexLocations.

/*
 *  Compute the list of paths which are keying index files.
 */
private void initializeIndexLocations() {
    IPath[] projectsAndJars = this.searchScope.enclosingProjectsAndJars();
    IndexManager manager = JavaModelManager.getIndexManager();
    // use a linked set to preserve the order during search: see bug 348507
    LinkedHashSet locations = new LinkedHashSet();
    IJavaElement focus = MatchLocator.projectOrJarFocus(this.pattern);
    if (focus == null) {
        for (int i = 0; i < projectsAndJars.length; i++) {
            IPath path = projectsAndJars[i];
            Object target = JavaModel.getTarget(path, false);
            if (// case of an external folder
            target instanceof IFolder)
                path = ((IFolder) target).getFullPath();
            locations.add(manager.computeIndexLocation(path));
        }
    } else {
        try {
            // See whether the state builder might be used to reduce the number of index locations
            // find the projects from projectsAndJars that see the focus then walk those projects looking for the jars from projectsAndJars
            int length = projectsAndJars.length;
            JavaProject[] projectsCanSeeFocus = new JavaProject[length];
            SimpleSet visitedProjects = new SimpleSet(length);
            int projectIndex = 0;
            SimpleSet externalLibsToCheck = new SimpleSet(length);
            ObjectVector superTypes = new ObjectVector();
            IJavaElement[] focuses = getFocusedElementsAndTypes(this.pattern, focus, superTypes);
            char[][][] focusQualifiedNames = null;
            boolean isAutoBuilding = ResourcesPlugin.getWorkspace().getDescription().isAutoBuilding();
            if (isAutoBuilding && focus instanceof IJavaProject) {
                focusQualifiedNames = getQualifiedNames(superTypes);
            }
            IJavaModel model = JavaModelManager.getJavaModelManager().getJavaModel();
            for (int i = 0; i < length; i++) {
                IPath path = projectsAndJars[i];
                JavaProject project = (JavaProject) getJavaProject(path, model);
                if (project != null) {
                    visitedProjects.add(project);
                    /*We are adding all modules to the locations for searching in each one.
					Now the location contains not only current module and Jars on which depends, but also all modules from the workspace.*/
                    locations.add(manager.computeIndexLocation(path));
                /*int canSeeFocus = canSeeFocus(focuses, project, focusQualifiedNames);
					if (canSeeFocus == PROJECT_CAN_SEE_FOCUS) {
						locations.add(manager.computeIndexLocation(path));
					}
					if (canSeeFocus != PROJECT_CAN_NOT_SEE_FOCUS) {
						projectsCanSeeFocus[projectIndex++] = project;
					}*/
                } else {
                    externalLibsToCheck.add(path);
                }
            }
            for (int i = 0; i < projectIndex && externalLibsToCheck.elementSize > 0; i++) {
                IClasspathEntry[] entries = projectsCanSeeFocus[i].getResolvedClasspath();
                for (int j = entries.length; --j >= 0; ) {
                    IClasspathEntry entry = entries[j];
                    if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
                        IPath path = entry.getPath();
                        if (externalLibsToCheck.remove(path) != null) {
                            Object target = JavaModel.getTarget(path, false);
                            if (// case of an external folder
                            target instanceof IFolder)
                                path = ((IFolder) target).getFullPath();
                            locations.add(manager.computeIndexLocation(path));
                        }
                    }
                }
            }
            // jar files can be included in the search scope without including one of the projects that references them, so scan all projects that have not been visited
            if (externalLibsToCheck.elementSize > 0) {
                IJavaProject[] allProjects = model.getJavaProjects();
                for (int i = 0, l = allProjects.length; i < l && externalLibsToCheck.elementSize > 0; i++) {
                    JavaProject project = (JavaProject) allProjects[i];
                    if (!visitedProjects.includes(project)) {
                        IClasspathEntry[] entries = project.getResolvedClasspath();
                        for (int j = entries.length; --j >= 0; ) {
                            IClasspathEntry entry = entries[j];
                            if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
                                IPath path = entry.getPath();
                                if (externalLibsToCheck.remove(path) != null) {
                                    Object target = JavaModel.getTarget(path, false);
                                    if (// case of an external folder
                                    target instanceof IFolder)
                                        path = ((IFolder) target).getFullPath();
                                    locations.add(manager.computeIndexLocation(path));
                                }
                            }
                        }
                    }
                }
            }
        } catch (JavaModelException e) {
        // ignored
        }
    }
    // Ensure no nulls
    locations.remove(null);
    this.indexLocations = (IndexLocation[]) locations.toArray(new IndexLocation[locations.size()]);
}
Also used : LinkedHashSet(java.util.LinkedHashSet) IJavaElement(org.eclipse.jdt.core.IJavaElement) JavaProject(org.eclipse.jdt.internal.core.JavaProject) IJavaProject(org.eclipse.jdt.core.IJavaProject) SimpleSet(org.eclipse.jdt.internal.compiler.util.SimpleSet) JavaModelException(org.eclipse.jdt.core.JavaModelException) IPath(org.eclipse.core.runtime.IPath) IClasspathEntry(org.eclipse.jdt.core.IClasspathEntry) ObjectVector(org.eclipse.jdt.internal.compiler.util.ObjectVector) IndexManager(org.eclipse.jdt.internal.core.search.indexing.IndexManager) IJavaProject(org.eclipse.jdt.core.IJavaProject) IndexLocation(org.eclipse.jdt.internal.core.index.IndexLocation) IFolder(org.eclipse.core.resources.IFolder) IJavaModel(org.eclipse.jdt.core.IJavaModel)

Example 2 with ObjectVector

use of org.eclipse.jdt.internal.compiler.util.ObjectVector in project che by eclipse.

the class JavaProject method computePackageFragmentRoots.

/**
     * Returns (local/all) the package fragment roots identified by the given project's classpath.
     * Note: this follows project classpath references to find required project contributions,
     * eliminating duplicates silently.
     * Only works with resolved entries
     *
     * @param resolvedClasspath
     *         IClasspathEntry[]
     * @param retrieveExportedRoots
     *         boolean
     * @return IPackageFragmentRoot[]
     * @throws JavaModelException
     */
public IPackageFragmentRoot[] computePackageFragmentRoots(IClasspathEntry[] resolvedClasspath, boolean retrieveExportedRoots, Map rootToResolvedEntries) throws JavaModelException {
    ObjectVector accumulatedRoots = new ObjectVector();
    computePackageFragmentRoots(resolvedClasspath, accumulatedRoots, // rootIDs
    new HashSet(5), // inside original project
    null, retrieveExportedRoots, rootToResolvedEntries);
    IPackageFragmentRoot[] rootArray = new IPackageFragmentRoot[accumulatedRoots.size()];
    accumulatedRoots.copyInto(rootArray);
    return rootArray;
}
Also used : ObjectVector(org.eclipse.jdt.internal.compiler.util.ObjectVector) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) IPackageFragmentRoot(org.eclipse.jdt.core.IPackageFragmentRoot)

Example 3 with ObjectVector

use of org.eclipse.jdt.internal.compiler.util.ObjectVector in project xtext-eclipse by eclipse.

the class JdtTypeProvider method getSourceFolders.

private IPackageFragmentRoot[] getSourceFolders(JavaProject javaProject) throws JavaModelException {
    /*
		 * IJavaProject#getAllPackageFragmentRoots will open all references archives to read the JDK version from
		 * the first class file it finds. This isn't necessary for our case thus we try to avoid this by copying a lot of 
		 * code. 
		 */
    ObjectVector result = new ObjectVector();
    collectSourcePackageFragmentRoots(javaProject, Sets.<String>newHashSet(), null, result);
    IPackageFragmentRoot[] rootArray = new IPackageFragmentRoot[result.size()];
    result.copyInto(rootArray);
    return rootArray;
}
Also used : ObjectVector(org.eclipse.jdt.internal.compiler.util.ObjectVector) IPackageFragmentRoot(org.eclipse.jdt.core.IPackageFragmentRoot)

Aggregations

ObjectVector (org.eclipse.jdt.internal.compiler.util.ObjectVector)3 LinkedHashSet (java.util.LinkedHashSet)2 IPackageFragmentRoot (org.eclipse.jdt.core.IPackageFragmentRoot)2 HashSet (java.util.HashSet)1 IFolder (org.eclipse.core.resources.IFolder)1 IPath (org.eclipse.core.runtime.IPath)1 IClasspathEntry (org.eclipse.jdt.core.IClasspathEntry)1 IJavaElement (org.eclipse.jdt.core.IJavaElement)1 IJavaModel (org.eclipse.jdt.core.IJavaModel)1 IJavaProject (org.eclipse.jdt.core.IJavaProject)1 JavaModelException (org.eclipse.jdt.core.JavaModelException)1 SimpleSet (org.eclipse.jdt.internal.compiler.util.SimpleSet)1 JavaProject (org.eclipse.jdt.internal.core.JavaProject)1 IndexLocation (org.eclipse.jdt.internal.core.index.IndexLocation)1 IndexManager (org.eclipse.jdt.internal.core.search.indexing.IndexManager)1