* Compute the list of paths which are keying index files.
*/
private void initializeIndexLocations() {
IPath[] projectsAndJars = this.searchScope.enclosingProjectsAndJars();
IndexManager manager = JavaModelManager.getJavaModelManager().getIndexManager();
SimpleSet locations = new SimpleSet();
IJavaElement focus = MatchLocator.projectOrJarFocus(this.pattern);
if (focus == null) {
for (int i = 0; i < projectsAndJars.length; i++)
locations.add(manager.computeIndexLocation(projectsAndJars[i]));
} else {
try {
// 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 jarsToCheck = new SimpleSet(length);
IClasspathEntry[] focusEntries = null;
if (this.pattern instanceof MethodPattern) { // should consider polymorphic search for method patterns
JavaProject focusProject = focus instanceof JarPackageFragmentRoot ? (JavaProject) focus.getParent() : (JavaProject) focus;
focusEntries = focusProject.getExpandedClasspath();
}
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);
if (canSeeFocus(focus, project, focusEntries)) {
locations.add(manager.computeIndexLocation(path));
projectsCanSeeFocus[projectIndex++] = project;
}
} else {
jarsToCheck.add(path);
}
}
for (int i = 0; i < projectIndex && jarsToCheck.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 (jarsToCheck.includes(path)) {
locations.add(manager.computeIndexLocation(entry.getPath()));
jarsToCheck.remove(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 (jarsToCheck.elementSize > 0) {
IJavaProject[] allProjects = model.getJavaProjects();
for (int i = 0, l = allProjects.length; i < l && jarsToCheck.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 (jarsToCheck.includes(path)) {
locations.add(manager.computeIndexLocation(entry.getPath()));
jarsToCheck.remove(path);
}
}
}
}
}