Search in sources :

Example 1 with SimpleSet

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

the class IndexSelector method getFocusedElementsAndTypes.

/*
 * Create the list of focused jars or projects.
 */
private static IJavaElement[] getFocusedElementsAndTypes(SearchPattern pattern, IJavaElement focusElement, ObjectVector superTypes) throws JavaModelException {
    if (pattern instanceof MethodPattern) {
        // For method pattern, it needs to walk along the focus type super hierarchy
        // and add jars/projects of all the encountered types.
        IType type = (IType) pattern.focus.getAncestor(IJavaElement.TYPE);
        MethodPattern methodPattern = (MethodPattern) pattern;
        String selector = new String(methodPattern.selector);
        int parameterCount = methodPattern.parameterCount;
        ITypeHierarchy superHierarchy = type.newSupertypeHierarchy(null);
        IType[] allTypes = superHierarchy.getAllSupertypes(type);
        int length = allTypes.length;
        SimpleSet focusSet = new SimpleSet(length + 1);
        if (focusElement != null)
            focusSet.add(focusElement);
        for (int i = 0; i < length; i++) {
            IMethod[] methods = allTypes[i].getMethods();
            int mLength = methods.length;
            for (int m = 0; m < mLength; m++) {
                if (parameterCount == methods[m].getNumberOfParameters() && methods[m].getElementName().equals(selector)) {
                    IPackageFragmentRoot root = (IPackageFragmentRoot) allTypes[i].getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT);
                    IJavaElement element = root.isArchive() ? root : root.getParent();
                    focusSet.add(element);
                    if (superTypes != null)
                        superTypes.add(allTypes[i]);
                    break;
                }
            }
        }
        // Rebuilt a contiguous array
        IJavaElement[] focuses = new IJavaElement[focusSet.elementSize];
        Object[] values = focusSet.values;
        int count = 0;
        for (int i = values.length; --i >= 0; ) {
            if (values[i] != null) {
                focuses[count++] = (IJavaElement) values[i];
            }
        }
        return focuses;
    }
    if (focusElement == null)
        return new IJavaElement[0];
    return new IJavaElement[] { focusElement };
}
Also used : IJavaElement(org.eclipse.jdt.core.IJavaElement) SimpleSet(org.eclipse.jdt.internal.compiler.util.SimpleSet) MethodPattern(org.eclipse.jdt.internal.core.search.matching.MethodPattern) IType(org.eclipse.jdt.core.IType) IPackageFragmentRoot(org.eclipse.jdt.core.IPackageFragmentRoot) ITypeHierarchy(org.eclipse.jdt.core.ITypeHierarchy) IMethod(org.eclipse.jdt.core.IMethod)

Example 2 with SimpleSet

use of org.eclipse.jdt.internal.compiler.util.SimpleSet 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 3 with SimpleSet

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

the class IndexManager method cleanUpIndexes.

/*
     * Removes unused indexes from disk.
     */
public void cleanUpIndexes() {
    SimpleSet knownPaths = new SimpleSet();
    IJavaSearchScope scope = BasicSearchEngine.createWorkspaceScope();
    PatternSearchJob job = new PatternSearchJob(null, SearchEngine.getDefaultSearchParticipant(), scope, null);
    Index[] selectedIndexes = job.getIndexes(null);
    for (int i = 0, l = selectedIndexes.length; i < l; i++) {
        IndexLocation IndexLocation = selectedIndexes[i].getIndexLocation();
        knownPaths.add(IndexLocation);
    }
    if (this.indexStates != null) {
        Object[] keys = this.indexStates.keyTable;
        IndexLocation[] locations = new IndexLocation[this.indexStates.elementSize];
        int count = 0;
        for (int i = 0, l = keys.length; i < l; i++) {
            IndexLocation key = (IndexLocation) keys[i];
            if (key != null && !knownPaths.includes(key))
                locations[count++] = key;
        }
        if (count > 0)
            removeIndexesState(locations);
    }
    deleteIndexFiles(knownPaths);
}
Also used : SimpleSet(org.eclipse.jdt.internal.compiler.util.SimpleSet) IJavaSearchScope(org.eclipse.jdt.core.search.IJavaSearchScope) PatternSearchJob(org.eclipse.jdt.internal.core.search.PatternSearchJob) FileIndexLocation(org.eclipse.jdt.internal.core.index.FileIndexLocation) IndexLocation(org.eclipse.jdt.internal.core.index.IndexLocation) DiskIndex(org.eclipse.jdt.internal.core.index.DiskIndex) Index(org.eclipse.jdt.internal.core.index.Index)

Example 4 with SimpleSet

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

the class ClasspathJar method readPackages.

private SimpleSet readPackages() {
    try {
        if (this.zipFile == null) {
            if (org.eclipse.jdt.internal.core.JavaModelManager.ZIP_ACCESS_VERBOSE) {
                System.out.println("(" + Thread.currentThread() + ") [ClasspathJar.isPackage(String)] Creating ZipFile on " + this.zipFilename);
            //$NON-NLS-1$	//$NON-NLS-2$
            }
            this.zipFile = new ZipFile(this.zipFilename);
            this.closeZipFileAtEnd = true;
        }
        return findPackageSet(this);
    } catch (Exception e) {
        // assume for this build the zipFile is empty
        return new SimpleSet();
    }
}
Also used : SimpleSet(org.eclipse.jdt.internal.compiler.util.SimpleSet) ZipFile(java.util.zip.ZipFile) ClassFormatException(org.eclipse.jdt.internal.compiler.classfmt.ClassFormatException) CoreException(org.eclipse.core.runtime.CoreException) IOException(java.io.IOException)

Example 5 with SimpleSet

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

the class ClasspathJar method getKnownPackages.

private SimpleSet getKnownPackages() {
    SimpleSet packageNames = knownPackageNames;
    if (packageNames == null) {
        synchronized (this) {
            packageNames = knownPackageNames;
            if (packageNames == null) {
                packageNames = readPackages();
                knownPackageNames = packageNames;
            }
        }
    }
    return packageNames;
}
Also used : SimpleSet(org.eclipse.jdt.internal.compiler.util.SimpleSet)

Aggregations

SimpleSet (org.eclipse.jdt.internal.compiler.util.SimpleSet)7 IJavaElement (org.eclipse.jdt.core.IJavaElement)2 IndexLocation (org.eclipse.jdt.internal.core.index.IndexLocation)2 IOException (java.io.IOException)1 Enumeration (java.util.Enumeration)1 LinkedHashSet (java.util.LinkedHashSet)1 ZipFile (java.util.zip.ZipFile)1 IFolder (org.eclipse.core.resources.IFolder)1 CoreException (org.eclipse.core.runtime.CoreException)1 IPath (org.eclipse.core.runtime.IPath)1 IClasspathEntry (org.eclipse.jdt.core.IClasspathEntry)1 IJavaModel (org.eclipse.jdt.core.IJavaModel)1 IJavaProject (org.eclipse.jdt.core.IJavaProject)1 IMethod (org.eclipse.jdt.core.IMethod)1 IPackageFragmentRoot (org.eclipse.jdt.core.IPackageFragmentRoot)1 IType (org.eclipse.jdt.core.IType)1 ITypeHierarchy (org.eclipse.jdt.core.ITypeHierarchy)1 JavaModelException (org.eclipse.jdt.core.JavaModelException)1 IJavaSearchScope (org.eclipse.jdt.core.search.IJavaSearchScope)1 ClassFormatException (org.eclipse.jdt.internal.compiler.classfmt.ClassFormatException)1