Lines 11-16
Link Here
|
11 |
package org.eclipse.jdt.internal.core.search; |
11 |
package org.eclipse.jdt.internal.core.search; |
12 |
|
12 |
|
13 |
import org.eclipse.core.resources.IFolder; |
13 |
import org.eclipse.core.resources.IFolder; |
|
|
14 |
import org.eclipse.core.resources.IProject; |
15 |
import org.eclipse.core.resources.IResource; |
14 |
import org.eclipse.core.runtime.IPath; |
16 |
import org.eclipse.core.runtime.IPath; |
15 |
import org.eclipse.jdt.core.*; |
17 |
import org.eclipse.jdt.core.*; |
16 |
import org.eclipse.jdt.core.search.IJavaSearchScope; |
18 |
import org.eclipse.jdt.core.search.IJavaSearchScope; |
Lines 20-25
Link Here
|
20 |
import org.eclipse.jdt.internal.core.JavaModel; |
22 |
import org.eclipse.jdt.internal.core.JavaModel; |
21 |
import org.eclipse.jdt.internal.core.JavaModelManager; |
23 |
import org.eclipse.jdt.internal.core.JavaModelManager; |
22 |
import org.eclipse.jdt.internal.core.JavaProject; |
24 |
import org.eclipse.jdt.internal.core.JavaProject; |
|
|
25 |
import org.eclipse.jdt.internal.core.Region; |
23 |
import org.eclipse.jdt.internal.core.search.indexing.IndexManager; |
26 |
import org.eclipse.jdt.internal.core.search.indexing.IndexManager; |
24 |
import org.eclipse.jdt.internal.core.search.matching.MatchLocator; |
27 |
import org.eclipse.jdt.internal.core.search.matching.MatchLocator; |
25 |
import org.eclipse.jdt.internal.core.search.matching.MethodPattern; |
28 |
import org.eclipse.jdt.internal.core.search.matching.MethodPattern; |
Lines 168-234
Link Here
|
168 |
locations.add(manager.computeIndexLocation(path)); |
171 |
locations.add(manager.computeIndexLocation(path)); |
169 |
} |
172 |
} |
170 |
} else { |
173 |
} else { |
171 |
try { |
174 |
IJavaElement cu = null; |
172 |
// find the projects from projectsAndJars that see the focus then walk those projects looking for the jars from projectsAndJars |
175 |
boolean canUseBuilderState = false; |
173 |
int length = projectsAndJars.length; |
176 |
JavaModelManager modelManager = JavaModelManager.getJavaModelManager(); |
174 |
JavaProject[] projectsCanSeeFocus = new JavaProject[length]; |
177 |
if (focus instanceof IJavaProject) { |
|
|
178 |
cu = this.pattern.focus; |
179 |
while (cu != null && !(cu instanceof ICompilationUnit) && !(cu instanceof IClassFile)) { |
180 |
cu = cu.getParent(); |
181 |
} |
182 |
final long start = System.currentTimeMillis(); |
183 |
canUseBuilderState = cu != null && focus.getJavaProject().hasBuildState(); |
184 |
final long time = System.currentTimeMillis()-start; |
185 |
System.out.println("Build state for "+focus.getElementName()+" found in "+time+"ms"); |
186 |
if (canUseBuilderState) { |
187 |
boolean isBuildNeeded = modelManager.isBuildNeeded(focus.getJavaProject().getProject()); |
188 |
System.out.println(" -> Delta processor says that a build is "+(isBuildNeeded?"":"not ")+"needed"); |
189 |
canUseBuilderState = !isBuildNeeded; |
190 |
} |
191 |
} |
192 |
if (canUseBuilderState) { |
193 |
Region region = new Region(); |
194 |
region.add(cu); |
195 |
final long start = System.currentTimeMillis(); |
196 |
IResource[] generatedResources = JavaCore.getGeneratedResources(region, false); |
197 |
final long time = System.currentTimeMillis()-start; |
198 |
System.out.println(" -> "+generatedResources.length+" generated resources (found in "+time+"ms)"); |
199 |
int length = generatedResources.length; |
175 |
SimpleSet visitedProjects = new SimpleSet(length); |
200 |
SimpleSet visitedProjects = new SimpleSet(length); |
176 |
int projectIndex = 0; |
201 |
for (int i=0; i<length; i++) { |
177 |
SimpleSet externalLibsToCheck = new SimpleSet(length); |
202 |
IProject project = generatedResources[i].getProject(); |
178 |
IJavaElement[] focuses = getFocusedElements(this.pattern, focus); |
203 |
if (!visitedProjects.includes(project)) { |
179 |
IJavaModel model = JavaModelManager.getJavaModelManager().getJavaModel(); |
204 |
locations.add(manager.computeIndexLocation(project.getFullPath())); |
180 |
for (int i = 0; i < length; i++) { |
|
|
181 |
IPath path = projectsAndJars[i]; |
182 |
JavaProject project = (JavaProject) getJavaProject(path, model); |
183 |
if (project != null) { |
184 |
visitedProjects.add(project); |
205 |
visitedProjects.add(project); |
185 |
if (canSeeFocus(focuses, project)) { |
|
|
186 |
locations.add(manager.computeIndexLocation(path)); |
187 |
projectsCanSeeFocus[projectIndex++] = project; |
188 |
} |
189 |
} else { |
190 |
externalLibsToCheck.add(path); |
191 |
} |
206 |
} |
192 |
} |
207 |
} |
193 |
for (int i = 0; i < projectIndex && externalLibsToCheck.elementSize > 0; i++) { |
208 |
} else { |
194 |
IClasspathEntry[] entries = projectsCanSeeFocus[i].getResolvedClasspath(); |
209 |
try { |
195 |
for (int j = entries.length; --j >= 0;) { |
210 |
// find the projects from projectsAndJars that see the focus then walk those projects looking for the jars from projectsAndJars |
196 |
IClasspathEntry entry = entries[j]; |
211 |
int length = projectsAndJars.length; |
197 |
if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) { |
212 |
JavaProject[] projectsCanSeeFocus = new JavaProject[length]; |
198 |
IPath path = entry.getPath(); |
213 |
SimpleSet visitedProjects = new SimpleSet(length); |
199 |
if (externalLibsToCheck.remove(path) != null) { |
214 |
int projectIndex = 0; |
200 |
Object target = JavaModel.getTarget(path, false/*don't check existence*/); |
215 |
SimpleSet externalLibsToCheck = new SimpleSet(length); |
201 |
if (target instanceof IFolder) // case of an external folder |
216 |
IJavaElement[] focuses = getFocusedElements(this.pattern, focus); |
202 |
path = ((IFolder) target).getFullPath(); |
217 |
IJavaModel model = modelManager.getJavaModel(); |
|
|
218 |
for (int i = 0; i < length; i++) { |
219 |
IPath path = projectsAndJars[i]; |
220 |
JavaProject project = (JavaProject) getJavaProject(path, model); |
221 |
if (project != null) { |
222 |
visitedProjects.add(project); |
223 |
if (canSeeFocus(focuses, project)) { |
203 |
locations.add(manager.computeIndexLocation(path)); |
224 |
locations.add(manager.computeIndexLocation(path)); |
|
|
225 |
projectsCanSeeFocus[projectIndex++] = project; |
204 |
} |
226 |
} |
|
|
227 |
} else { |
228 |
externalLibsToCheck.add(path); |
205 |
} |
229 |
} |
206 |
} |
230 |
} |
207 |
} |
231 |
for (int i = 0; i < projectIndex && externalLibsToCheck.elementSize > 0; i++) { |
208 |
// 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 |
232 |
IClasspathEntry[] entries = projectsCanSeeFocus[i].getResolvedClasspath(); |
209 |
if (externalLibsToCheck.elementSize > 0) { |
233 |
for (int j = entries.length; --j >= 0;) { |
210 |
IJavaProject[] allProjects = model.getJavaProjects(); |
234 |
IClasspathEntry entry = entries[j]; |
211 |
for (int i = 0, l = allProjects.length; i < l && externalLibsToCheck.elementSize > 0; i++) { |
235 |
if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) { |
212 |
JavaProject project = (JavaProject) allProjects[i]; |
236 |
IPath path = entry.getPath(); |
213 |
if (!visitedProjects.includes(project)) { |
237 |
if (externalLibsToCheck.remove(path) != null) { |
214 |
IClasspathEntry[] entries = project.getResolvedClasspath(); |
238 |
Object target = JavaModel.getTarget(path, false/*don't check existence*/); |
215 |
for (int j = entries.length; --j >= 0;) { |
239 |
if (target instanceof IFolder) // case of an external folder |
216 |
IClasspathEntry entry = entries[j]; |
240 |
path = ((IFolder) target).getFullPath(); |
217 |
if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) { |
241 |
locations.add(manager.computeIndexLocation(path)); |
218 |
IPath path = entry.getPath(); |
242 |
} |
219 |
if (externalLibsToCheck.remove(path) != null) { |
243 |
} |
220 |
Object target = JavaModel.getTarget(path, false/*don't check existence*/); |
244 |
} |
221 |
if (target instanceof IFolder) // case of an external folder |
245 |
} |
222 |
path = ((IFolder) target).getFullPath(); |
246 |
// 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 |
223 |
locations.add(manager.computeIndexLocation(path)); |
247 |
if (externalLibsToCheck.elementSize > 0) { |
|
|
248 |
IJavaProject[] allProjects = model.getJavaProjects(); |
249 |
for (int i = 0, l = allProjects.length; i < l && externalLibsToCheck.elementSize > 0; i++) { |
250 |
JavaProject project = (JavaProject) allProjects[i]; |
251 |
if (!visitedProjects.includes(project)) { |
252 |
IClasspathEntry[] entries = project.getResolvedClasspath(); |
253 |
for (int j = entries.length; --j >= 0;) { |
254 |
IClasspathEntry entry = entries[j]; |
255 |
if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) { |
256 |
IPath path = entry.getPath(); |
257 |
if (externalLibsToCheck.remove(path) != null) { |
258 |
Object target = JavaModel.getTarget(path, false/*don't check existence*/); |
259 |
if (target instanceof IFolder) // case of an external folder |
260 |
path = ((IFolder) target).getFullPath(); |
261 |
locations.add(manager.computeIndexLocation(path)); |
262 |
} |
224 |
} |
263 |
} |
225 |
} |
264 |
} |
226 |
} |
265 |
} |
227 |
} |
266 |
} |
228 |
} |
267 |
} |
|
|
268 |
} catch (JavaModelException e) { |
269 |
// ignored |
229 |
} |
270 |
} |
230 |
} catch (JavaModelException e) { |
|
|
231 |
// ignored |
232 |
} |
271 |
} |
233 |
} |
272 |
} |
234 |
|
273 |
|