Lines 12-22
Link Here
|
12 |
|
12 |
|
13 |
import org.eclipse.core.resources.IFolder; |
13 |
import org.eclipse.core.resources.IFolder; |
14 |
import org.eclipse.core.runtime.IPath; |
14 |
import org.eclipse.core.runtime.IPath; |
15 |
import org.eclipse.jdt.core.IClasspathEntry; |
15 |
import org.eclipse.jdt.core.*; |
16 |
import org.eclipse.jdt.core.IJavaElement; |
|
|
17 |
import org.eclipse.jdt.core.IJavaModel; |
18 |
import org.eclipse.jdt.core.IJavaProject; |
19 |
import org.eclipse.jdt.core.JavaModelException; |
20 |
import org.eclipse.jdt.core.search.IJavaSearchScope; |
16 |
import org.eclipse.jdt.core.search.IJavaSearchScope; |
21 |
import org.eclipse.jdt.core.search.SearchPattern; |
17 |
import org.eclipse.jdt.core.search.SearchPattern; |
22 |
import org.eclipse.jdt.internal.compiler.util.SimpleSet; |
18 |
import org.eclipse.jdt.internal.compiler.util.SimpleSet; |
Lines 49-65
Link Here
|
49 |
* a JarPackageFragmentRot) either because the focus is part of the project or the jar, or because it is |
45 |
* a JarPackageFragmentRot) either because the focus is part of the project or the jar, or because it is |
50 |
* accessible throught the project's classpath |
46 |
* accessible throught the project's classpath |
51 |
*/ |
47 |
*/ |
52 |
public static boolean canSeeFocus(IJavaElement focus, boolean isPolymorphicSearch, IPath projectOrJarPath) { |
48 |
public static boolean canSeeFocus(SearchPattern pattern, IPath projectOrJarPath) { |
53 |
try { |
49 |
try { |
54 |
IClasspathEntry[] focusEntries = null; |
50 |
IJavaModel model = JavaModelManager.getJavaModelManager().getJavaModel(); |
55 |
if (isPolymorphicSearch) { |
|
|
56 |
JavaProject focusProject = focus instanceof JarPackageFragmentRoot ? (JavaProject) focus.getParent() : (JavaProject) focus; |
57 |
focusEntries = focusProject.getExpandedClasspath(); |
58 |
} |
59 |
IJavaModel model = focus.getJavaModel(); |
60 |
IJavaProject project = getJavaProject(projectOrJarPath, model); |
51 |
IJavaProject project = getJavaProject(projectOrJarPath, model); |
61 |
if (project != null) |
52 |
IJavaElement[] focuses = getFocusedElements(pattern, project); |
62 |
return canSeeFocus(focus, (JavaProject) project, focusEntries); |
53 |
if (project != null) { |
|
|
54 |
return canSeeFocus(focuses, (JavaProject) project); |
55 |
} |
63 |
|
56 |
|
64 |
// projectOrJarPath is a jar |
57 |
// projectOrJarPath is a jar |
65 |
// it can see the focus only if it is on the classpath of a project that can see the focus |
58 |
// it can see the focus only if it is on the classpath of a project that can see the focus |
Lines 67-96
Link Here
|
67 |
for (int i = 0, length = allProjects.length; i < length; i++) { |
60 |
for (int i = 0, length = allProjects.length; i < length; i++) { |
68 |
JavaProject otherProject = (JavaProject) allProjects[i]; |
61 |
JavaProject otherProject = (JavaProject) allProjects[i]; |
69 |
IClasspathEntry entry = otherProject.getClasspathEntryFor(projectOrJarPath); |
62 |
IClasspathEntry entry = otherProject.getClasspathEntryFor(projectOrJarPath); |
70 |
if (entry != null |
63 |
if (entry != null && entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) { |
71 |
&& entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY |
64 |
if (canSeeFocus(focuses, otherProject)) { |
72 |
&& canSeeFocus(focus, otherProject, focusEntries)) |
65 |
return true; |
73 |
return true; |
66 |
} |
|
|
67 |
} |
74 |
} |
68 |
} |
75 |
return false; |
69 |
return false; |
76 |
} catch (JavaModelException e) { |
70 |
} catch (JavaModelException e) { |
77 |
return false; |
71 |
return false; |
78 |
} |
72 |
} |
79 |
} |
73 |
} |
80 |
public static boolean canSeeFocus(IJavaElement focus, JavaProject javaProject, IClasspathEntry[] focusEntriesForPolymorphicSearch) { |
74 |
private static boolean canSeeFocus(IJavaElement[] focuses, JavaProject javaProject) { |
|
|
75 |
int length = focuses.length; |
76 |
for (int i=0; i<length; i++) { |
77 |
if (canSeeFocus(focuses[i], javaProject)) return true; |
78 |
} |
79 |
return false; |
80 |
} |
81 |
private static boolean canSeeFocus(IJavaElement focus, JavaProject javaProject) { |
81 |
try { |
82 |
try { |
82 |
if (focus.equals(javaProject)) |
83 |
if (focus == null) return false; |
83 |
return true; |
84 |
if (focus.equals(javaProject)) return true; |
84 |
|
85 |
|
85 |
if (focusEntriesForPolymorphicSearch != null) { |
|
|
86 |
// look for refering project |
87 |
IPath projectPath = javaProject.getProject().getFullPath(); |
88 |
for (int i = 0, length = focusEntriesForPolymorphicSearch.length; i < length; i++) { |
89 |
IClasspathEntry entry = focusEntriesForPolymorphicSearch[i]; |
90 |
if (entry.getEntryKind() == IClasspathEntry.CPE_PROJECT && entry.getPath().equals(projectPath)) |
91 |
return true; |
92 |
} |
93 |
} |
94 |
if (focus instanceof JarPackageFragmentRoot) { |
86 |
if (focus instanceof JarPackageFragmentRoot) { |
95 |
// focus is part of a jar |
87 |
// focus is part of a jar |
96 |
IPath focusPath = focus.getPath(); |
88 |
IPath focusPath = focus.getPath(); |
Lines 115-120
Link Here
|
115 |
return false; |
107 |
return false; |
116 |
} |
108 |
} |
117 |
} |
109 |
} |
|
|
110 |
|
111 |
/* |
112 |
* Create the list of focused jars or projects. |
113 |
*/ |
114 |
private static IJavaElement[] getFocusedElements(SearchPattern pattern, IJavaElement focusElement) throws JavaModelException { |
115 |
if (pattern instanceof MethodPattern) { |
116 |
// For method pattern, it needs to walk along the focus type super hierarchy |
117 |
// and add jars/projects of all the encountered types. |
118 |
IType type = (IType) pattern.focus.getAncestor(IJavaElement.TYPE); |
119 |
MethodPattern methodPattern = (MethodPattern) pattern; |
120 |
String selector = new String(methodPattern.selector); |
121 |
int parameterCount = methodPattern.parameterCount; |
122 |
ITypeHierarchy superHierarchy = type.newSupertypeHierarchy(null); |
123 |
IType[] allTypes = superHierarchy.getAllSupertypes(type); |
124 |
int length = allTypes.length; |
125 |
SimpleSet focusSet = new SimpleSet(length+1); |
126 |
focusSet.add(focusElement); |
127 |
for (int i=0; i<length; i++) { |
128 |
IMethod[] methods = allTypes[i].getMethods(); |
129 |
int mLength = methods.length; |
130 |
for (int m=0; m<mLength; m++) { |
131 |
if (parameterCount == methods[m].getNumberOfParameters() && methods[m].getElementName().equals(selector)) { |
132 |
IPackageFragmentRoot root = (IPackageFragmentRoot) allTypes[i].getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT); |
133 |
IJavaElement element = root.isArchive() ? root : root.getParent(); |
134 |
focusSet.add(element); |
135 |
} |
136 |
} |
137 |
} |
138 |
// Rebuilt a contiguous array |
139 |
IJavaElement[] focuses = new IJavaElement[focusSet.elementSize]; |
140 |
Object[] values = focusSet.values; |
141 |
int count = 0; |
142 |
for (int i = values.length; --i >= 0;) { |
143 |
if (values[i] != null) { |
144 |
focuses[count++] = (IJavaElement) values[i]; |
145 |
} |
146 |
} |
147 |
return focuses; |
148 |
} |
149 |
return new IJavaElement[] { focusElement }; |
150 |
} |
151 |
|
118 |
/* |
152 |
/* |
119 |
* Compute the list of paths which are keying index files. |
153 |
* Compute the list of paths which are keying index files. |
120 |
*/ |
154 |
*/ |
Lines 139-156
Link Here
|
139 |
SimpleSet visitedProjects = new SimpleSet(length); |
173 |
SimpleSet visitedProjects = new SimpleSet(length); |
140 |
int projectIndex = 0; |
174 |
int projectIndex = 0; |
141 |
SimpleSet externalLibsToCheck = new SimpleSet(length); |
175 |
SimpleSet externalLibsToCheck = new SimpleSet(length); |
142 |
IClasspathEntry[] focusEntries = null; |
176 |
IJavaElement[] focuses = getFocusedElements(this.pattern, focus); |
143 |
if (this.pattern instanceof MethodPattern) { // should consider polymorphic search for method patterns |
|
|
144 |
JavaProject focusProject = focus instanceof JarPackageFragmentRoot ? (JavaProject) focus.getParent() : (JavaProject) focus; |
145 |
focusEntries = focusProject.getExpandedClasspath(); |
146 |
} |
147 |
IJavaModel model = JavaModelManager.getJavaModelManager().getJavaModel(); |
177 |
IJavaModel model = JavaModelManager.getJavaModelManager().getJavaModel(); |
148 |
for (int i = 0; i < length; i++) { |
178 |
for (int i = 0; i < length; i++) { |
149 |
IPath path = projectsAndJars[i]; |
179 |
IPath path = projectsAndJars[i]; |
150 |
JavaProject project = (JavaProject) getJavaProject(path, model); |
180 |
JavaProject project = (JavaProject) getJavaProject(path, model); |
151 |
if (project != null) { |
181 |
if (project != null) { |
152 |
visitedProjects.add(project); |
182 |
visitedProjects.add(project); |
153 |
if (canSeeFocus(focus, project, focusEntries)) { |
183 |
if (canSeeFocus(focuses, project)) { |
154 |
locations.add(manager.computeIndexLocation(path)); |
184 |
locations.add(manager.computeIndexLocation(path)); |
155 |
projectsCanSeeFocus[projectIndex++] = project; |
185 |
projectsCanSeeFocus[projectIndex++] = project; |
156 |
} |
186 |
} |
Lines 207-212
Link Here
|
207 |
if (values[i] != null) |
237 |
if (values[i] != null) |
208 |
this.indexLocations[count++] = (IPath) values[i]; |
238 |
this.indexLocations[count++] = (IPath) values[i]; |
209 |
} |
239 |
} |
|
|
240 |
|
210 |
public IPath[] getIndexLocations() { |
241 |
public IPath[] getIndexLocations() { |
211 |
if (this.indexLocations == null) { |
242 |
if (this.indexLocations == null) { |
212 |
initializeIndexLocations(); |
243 |
initializeIndexLocations(); |