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
}
}
}
}
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;
}
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
}
}
}
}
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);
}
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()]);
}
Aggregations