}
int copiesLength = copies.size();
this.workingCopies = new org.eclipse.jdt.core.ICompilationUnit[copiesLength];
copies.toArray(this.workingCopies);
JavaModelManager manager = JavaModelManager.getJavaModelManager();
this.bindings = new SimpleLookupTable();
try {
// optimize access to zip files during search operation
manager.cacheZipFiles(this);
// initialize handle factory (used as a cache of handles so as to optimize space)
if (this.handleFactory == null)
this.handleFactory = new HandleFactory();
if (this.progressMonitor != null) {
this.progressMonitor.beginTask("", searchDocuments.length); //$NON-NLS-1$
}
// initialize pattern for polymorphic search (i.e. method reference pattern)
this.patternLocator.initializePolymorphicSearch(this);
JavaProject previousJavaProject = null;
PossibleMatchSet matchSet = new PossibleMatchSet();
Util.sort(searchDocuments, new Util.Comparer() {
public int compare(Object a, Object b) {
return ((SearchDocument)a).getPath().compareTo(((SearchDocument)b).getPath());
}
});
int displayed = 0; // progress worked displayed
String previousPath = null;
SearchParticipant searchParticipant = null;
for (int i = 0; i < docsLength; i++) {
if (this.progressMonitor != null && this.progressMonitor.isCanceled()) {
throw new OperationCanceledException();
}
// skip duplicate paths
SearchDocument searchDocument = searchDocuments[i];
if (searchParticipant == null) {
searchParticipant = searchDocument.getParticipant();
}
searchDocuments[i] = null; // free current document
String pathString = searchDocument.getPath();
if (i > 0 && pathString.equals(previousPath)) {
if (this.progressMonitor != null) {
this.progressWorked++;
if ((this.progressWorked%this.progressStep)==0) this.progressMonitor.worked(this.progressStep);
}
displayed++;
continue;
}
previousPath = pathString;
Openable openable;
org.eclipse.jdt.core.ICompilationUnit workingCopy = null;
if (searchDocument instanceof WorkingCopyDocument) {
workingCopy = ((WorkingCopyDocument)searchDocument).workingCopy;
openable = (Openable) workingCopy;
} else {
openable = this.handleFactory.createOpenable(pathString, this.scope);
}
if (openable == null) {
if (this.progressMonitor != null) {
this.progressWorked++;
if ((this.progressWorked%this.progressStep)==0) this.progressMonitor.worked(this.progressStep);
}
displayed++;
continue; // match is outside classpath
}
// create new parser and lookup environment if this is a new project
IResource resource = null;
JavaProject javaProject = (JavaProject) openable.getJavaProject();
resource = workingCopy != null ? workingCopy.getResource() : openable.getResource();
if (resource == null)
resource = javaProject.getProject(); // case of a file in an external jar or external folder
if (!javaProject.equals(previousJavaProject)) {
// locate matches in previous project
if (previousJavaProject != null) {
try {
locateMatches(previousJavaProject, matchSet, i-displayed);
displayed = i;
} catch (JavaModelException e) {
// problem with classpath in this project -> skip it
}
matchSet.reset();
}
previousJavaProject = javaProject;
}
matchSet.add(new PossibleMatch(this, resource, openable, searchDocument,this.pattern.mustResolve));
}
// last project
if (previousJavaProject != null) {
try {
locateMatches(previousJavaProject, matchSet, docsLength-displayed);
} catch (JavaModelException e) {
// problem with classpath in last project -> ignore
}
}
if (this.searchPackageDeclaration) {
locatePackageDeclarations(searchParticipant, javaModelProjects);
}
} finally {
if (this.progressMonitor != null)
this.progressMonitor.done();
if (this.nameEnvironment != null)
this.nameEnvironment.cleanup();
manager.flushZipFiles(this);
this.bindings = null;
}
}