IPath[] scopeProjectsAndJars = isWorkspaceScope ? null : this.scope.enclosingProjectsAndJars();
int scopeLength = isWorkspaceScope ? 0 : scopeProjectsAndJars.length;
IJavaProject[] projects = JavaModelManager.getJavaModelManager().getJavaModel().getJavaProjects();
SimpleSet packages = new SimpleSet();
for (int i = 0, length = projects.length; i < length; i++) {
IJavaProject javaProject = projects[i];
// Verify that project belongs to the scope
if (!isWorkspaceScope) {
boolean found = false;
for (int j=0; j<scopeLength; j++) {
if (javaProject.getPath().equals(scopeProjectsAndJars[j])) {
found = true;
break;
}
}
if (!found) continue;
}
// Get all project package fragment names
this.nameLookup = ((JavaProject) projects[i]).newNameLookup(this.workingCopies);
IPackageFragment[] packageFragments = this.nameLookup.findPackageFragments(new String(pkgPattern.pkgName), false, true);
int pLength = packageFragments == null ? 0 : packageFragments.length;
// Report matches avoiding duplicate names
for (int p=0; p<pLength; p++) {
IPackageFragment fragment = packageFragments[p];
if (packages.addIfNotIncluded(fragment) == null) continue;
if (encloses(fragment)) {
IResource resource = fragment.getResource();
if (resource == null) // case of a file in an external jar
resource = javaProject.getProject();
try {
if (encloses(fragment)) {
SearchMatch match = new PackageDeclarationMatch(fragment, SearchMatch.A_ACCURATE, -1, -1, participant, resource);
report(match);
}