Index: search/org/eclipse/jdt/internal/core/search/IndexSelector.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/IndexSelector.java,v retrieving revision 1.48.2.1 diff -u -r1.48.2.1 IndexSelector.java --- search/org/eclipse/jdt/internal/core/search/IndexSelector.java 28 Jun 2010 06:57:23 -0000 1.48.2.1 +++ search/org/eclipse/jdt/internal/core/search/IndexSelector.java 21 Jun 2011 05:57:57 -0000 @@ -7,9 +7,12 @@ * * Contributors: * IBM Corporation - initial API and implementation + * Nikolay Botev - Bug 348507 *******************************************************************************/ package org.eclipse.jdt.internal.core.search; +import java.util.LinkedHashSet; + import org.eclipse.core.resources.IFolder; import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.IPath; @@ -180,7 +183,8 @@ private void initializeIndexLocations() { IPath[] projectsAndJars = this.searchScope.enclosingProjectsAndJars(); IndexManager manager = JavaModelManager.getIndexManager(); - SimpleSet locations = new SimpleSet(); + // 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++) { @@ -263,12 +267,8 @@ } } - this.indexLocations = new IPath[locations.elementSize]; - Object[] values = locations.values; - int count = 0; - for (int i = values.length; --i >= 0;) - if (values[i] != null) - this.indexLocations[count++] = (IPath) values[i]; + locations.remove(null); // Ensure no nulls + this.indexLocations = (IPath[]) locations.toArray(new IPath[locations.size()]); } public IPath[] getIndexLocations() { Index: search/org/eclipse/jdt/internal/core/search/JavaWorkspaceScope.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/JavaWorkspaceScope.java,v retrieving revision 1.36 diff -u -r1.36 JavaWorkspaceScope.java --- search/org/eclipse/jdt/internal/core/search/JavaWorkspaceScope.java 27 Jun 2008 16:04:09 -0000 1.36 +++ search/org/eclipse/jdt/internal/core/search/JavaWorkspaceScope.java 21 Jun 2011 05:57:57 -0000 @@ -7,11 +7,12 @@ * * Contributors: * IBM Corporation - initial API and implementation + * Nikolay Botev - Bug 348507 *******************************************************************************/ package org.eclipse.jdt.internal.core.search; import java.util.HashMap; -import java.util.HashSet; +import java.util.LinkedHashSet; import java.util.Set; import org.eclipse.core.resources.IFolder; @@ -72,13 +73,22 @@ long start = BasicSearchEngine.VERBOSE ? System.currentTimeMillis() : -1; try { IJavaProject[] projects = JavaModelManager.getJavaModelManager().getJavaModel().getJavaProjects(); - Set paths = new HashSet(projects.length * 2); + // use a linked set to preserve the order during search: see bug 348507 + Set paths = new LinkedHashSet(projects.length * 2); for (int i = 0, length = projects.length; i < length; i++) { JavaProject javaProject = (JavaProject) projects[i]; // Add project full path IPath projectPath = javaProject.getProject().getFullPath(); paths.add(projectPath); + } + + // add the project source paths first in a separate loop above + // to ensure source files always get higher precedence during search. + // see bug 348507 + + for (int i = 0, length = projects.length; i < length; i++) { + JavaProject javaProject = (JavaProject) projects[i]; // Add project libraries paths IClasspathEntry[] entries = javaProject.getResolvedClasspath();