Search in sources :

Example 1 with IndexLocation

use of org.eclipse.jdt.internal.core.index.IndexLocation in project che by eclipse.

the class IndexManager method writeParticipantsIndexNamesFile.

private void writeParticipantsIndexNamesFile() {
    BufferedWriter writer = null;
    try {
        writer = new BufferedWriter(new FileWriter(this.participantIndexNamesFile));
        writer.write(DiskIndex.SIGNATURE);
        writer.write('\n');
        Object[] indexFiles = this.participantsContainers.keyTable;
        Object[] containers = this.participantsContainers.valueTable;
        for (int i = 0, l = indexFiles.length; i < l; i++) {
            IndexLocation indexFile = (IndexLocation) indexFiles[i];
            if (indexFile != null) {
                writer.write(indexFile.getIndexFile().getPath());
                writer.write('\n');
                writer.write(((IPath) containers[i]).toOSString());
                writer.write('\n');
            }
        }
    } catch (IOException ignored) {
        if (JobManager.VERBOSE)
            //$NON-NLS-1$
            Util.verbose("Failed to write participant index file names", System.err);
    } finally {
        if (writer != null) {
            try {
                writer.close();
            } catch (IOException e) {
            // ignore
            }
        }
    }
}
Also used : FileWriter(java.io.FileWriter) FileIndexLocation(org.eclipse.jdt.internal.core.index.FileIndexLocation) IndexLocation(org.eclipse.jdt.internal.core.index.IndexLocation) IOException(java.io.IOException) BufferedWriter(java.io.BufferedWriter)

Example 2 with IndexLocation

use of org.eclipse.jdt.internal.core.index.IndexLocation in project che by eclipse.

the class IndexManager method readIndexMap.

private void readIndexMap() {
    try {
        char[] indexMaps = org.eclipse.jdt.internal.compiler.util.Util.getFileCharContent(this.indexNamesMapFile, null);
        char[][] names = CharOperation.splitOn('\n', indexMaps);
        if (names.length >= 3) {
            // First line is DiskIndex signature (see writeIndexMapFile())
            String savedSignature = DiskIndex.SIGNATURE;
            if (savedSignature.equals(new String(names[0]))) {
                for (int i = 1, l = names.length - 1; i < l; i += 2) {
                    IndexLocation indexPath = IndexLocation.createIndexLocation(new URL(new String(names[i])));
                    if (indexPath == null)
                        continue;
                    this.indexLocations.put(new Path(new String(names[i + 1])), indexPath);
                    this.indexStates.put(indexPath, REUSE_STATE);
                }
            }
        }
    } catch (IOException ignored) {
        if (JobManager.VERBOSE)
            //$NON-NLS-1$
            Util.verbose("Failed to read saved index file names");
    }
    return;
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) FileIndexLocation(org.eclipse.jdt.internal.core.index.FileIndexLocation) IndexLocation(org.eclipse.jdt.internal.core.index.IndexLocation) IOException(java.io.IOException) URL(java.net.URL)

Example 3 with IndexLocation

use of org.eclipse.jdt.internal.core.index.IndexLocation in project che by eclipse.

the class IndexManager method writeIndexMapFile.

private void writeIndexMapFile() {
    BufferedWriter writer = null;
    try {
        writer = new BufferedWriter(new FileWriter(this.indexNamesMapFile));
        writer.write(DiskIndex.SIGNATURE);
        writer.write('\n');
        Object[] keys = this.indexStates.keyTable;
        Object[] states = this.indexStates.valueTable;
        for (int i = 0, l = states.length; i < l; i++) {
            IndexLocation location = (IndexLocation) keys[i];
            if (location != null && states[i] == REUSE_STATE) {
                IPath container = (IPath) this.indexLocations.keyForValue(location);
                if (container != null) {
                    writer.write(location.toString());
                    writer.write('\n');
                    writer.write(container.toOSString());
                    writer.write('\n');
                }
            }
        }
    } catch (IOException ignored) {
        if (JobManager.VERBOSE)
            //$NON-NLS-1$
            Util.verbose("Failed to write saved index file names", System.err);
    } finally {
        if (writer != null) {
            try {
                writer.close();
            } catch (IOException e) {
            // ignore
            }
        }
    }
}
Also used : IPath(org.eclipse.core.runtime.IPath) FileWriter(java.io.FileWriter) FileIndexLocation(org.eclipse.jdt.internal.core.index.FileIndexLocation) IndexLocation(org.eclipse.jdt.internal.core.index.IndexLocation) IOException(java.io.IOException) BufferedWriter(java.io.BufferedWriter)

Example 4 with IndexLocation

use of org.eclipse.jdt.internal.core.index.IndexLocation in project che by eclipse.

the class IndexManager method addSource.

/**
     * Trigger addition of a resource to an index
     * Note: the actual operation is performed in background
     */
public void addSource(IFile resource, IPath containerPath, SourceElementParser parser) {
    //        if (JavaCore.getPlugin() == null) return;
    SearchParticipant participant = SearchEngine.getDefaultSearchParticipant();
    SearchDocument document = participant.getDocument(resource.getFullPath().toString());
    document.setParser(parser);
    IndexLocation indexLocation = computeIndexLocation(containerPath);
    scheduleDocumentIndexing(document, containerPath, indexLocation, participant);
}
Also used : FileIndexLocation(org.eclipse.jdt.internal.core.index.FileIndexLocation) IndexLocation(org.eclipse.jdt.internal.core.index.IndexLocation) SearchParticipant(org.eclipse.jdt.core.search.SearchParticipant) SearchDocument(org.eclipse.jdt.core.search.SearchDocument)

Example 5 with IndexLocation

use of org.eclipse.jdt.internal.core.index.IndexLocation 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)

Aggregations

IndexLocation (org.eclipse.jdt.internal.core.index.IndexLocation)22 FileIndexLocation (org.eclipse.jdt.internal.core.index.FileIndexLocation)21 IOException (java.io.IOException)8 DiskIndex (org.eclipse.jdt.internal.core.index.DiskIndex)7 Index (org.eclipse.jdt.internal.core.index.Index)7 IPath (org.eclipse.core.runtime.IPath)6 File (java.io.File)5 IFile (org.eclipse.core.resources.IFile)5 BufferedWriter (java.io.BufferedWriter)3 FileWriter (java.io.FileWriter)3 Path (org.eclipse.core.runtime.Path)3 URL (java.net.URL)2 SearchDocument (org.eclipse.jdt.core.search.SearchDocument)2 SearchParticipant (org.eclipse.jdt.core.search.SearchParticipant)2 SimpleLookupTable (org.eclipse.jdt.internal.compiler.util.SimpleLookupTable)2 SimpleSet (org.eclipse.jdt.internal.compiler.util.SimpleSet)2 LinkedHashSet (java.util.LinkedHashSet)1 CRC32 (java.util.zip.CRC32)1 IFolder (org.eclipse.core.resources.IFolder)1 OperationCanceledException (org.eclipse.core.runtime.OperationCanceledException)1