Lines 37-46
Link Here
|
37 |
static final IPackageFragmentRoot[] NO_ROOTS = new IPackageFragmentRoot[0]; |
37 |
static final IPackageFragmentRoot[] NO_ROOTS = new IPackageFragmentRoot[0]; |
38 |
|
38 |
|
39 |
static class ProjectCache { |
39 |
static class ProjectCache { |
40 |
ProjectCache(IPackageFragmentRoot[] allPkgFragmentRootsCache, HashtableOfArrayToObject allPkgFragmentsCache, Map rootToResolvedEntries) { |
40 |
ProjectCache(IPackageFragmentRoot[] allPkgFragmentRootsCache, Map rootToResolvedEntries, Map pkgFragmentsCaches) { |
41 |
this.allPkgFragmentRootsCache = allPkgFragmentRootsCache; |
41 |
this.allPkgFragmentRootsCache = allPkgFragmentRootsCache; |
42 |
this.allPkgFragmentsCache = allPkgFragmentsCache; |
|
|
43 |
this.rootToResolvedEntries = rootToResolvedEntries; |
42 |
this.rootToResolvedEntries = rootToResolvedEntries; |
|
|
43 |
this.pkgFragmentsCaches = pkgFragmentsCaches; |
44 |
} |
44 |
} |
45 |
|
45 |
|
46 |
/* |
46 |
/* |
Lines 50-59
Link Here
|
50 |
|
50 |
|
51 |
/* |
51 |
/* |
52 |
* A cache of all package fragments in this project. |
52 |
* A cache of all package fragments in this project. |
53 |
* (a map from String[] (the package name) to IPackageFragmentRoot[] (the package fragment roots that contain a package fragment with this name) |
53 |
* (a map from String[] (the package name) to IPackageFragmentRoot[] (the package fragment roots that contain a package fragment with this name)) |
54 |
*/ |
54 |
*/ |
55 |
public HashtableOfArrayToObject allPkgFragmentsCache; |
55 |
public HashtableOfArrayToObject allPkgFragmentsCache; |
56 |
|
56 |
|
|
|
57 |
/* |
58 |
* A cache of package fragments for each package fragment root of this project |
59 |
* (a map from IPackageFragmentRoot to |
60 |
* a map from String[] (the package name) to IPackageFragmentRoot[] (the package fragment roots that contain a package fragment with this name)) |
61 |
*/ |
62 |
public Map pkgFragmentsCaches; |
63 |
|
57 |
public Map rootToResolvedEntries; |
64 |
public Map rootToResolvedEntries; |
58 |
} |
65 |
} |
59 |
|
66 |
|
Lines 202-248
Link Here
|
202 |
reverseMap.clear(); |
209 |
reverseMap.clear(); |
203 |
} |
210 |
} |
204 |
|
211 |
|
205 |
HashMap otherRoots = JavaModelManager.getJavaModelManager().deltaState.otherRoots; |
212 |
HashMap rootInfos = JavaModelManager.getJavaModelManager().deltaState.roots; |
206 |
HashtableOfArrayToObject fragmentsCache = new HashtableOfArrayToObject(); |
213 |
HashMap pkgFragmentsCaches = new HashMap(); |
207 |
for (int i = 0, length = roots.length; i < length; i++) { |
214 |
int length = roots.length; |
|
|
215 |
for (int i = 0; i < length; i++) { |
208 |
IPackageFragmentRoot root = roots[i]; |
216 |
IPackageFragmentRoot root = roots[i]; |
209 |
IJavaElement[] frags = null; |
217 |
DeltaProcessor.RootInfo rootInfo = (DeltaProcessor.RootInfo) rootInfos.get(root.getPath()); |
210 |
try { |
218 |
if (rootInfo == null || rootInfo.project.equals(project)) { |
211 |
if (root.isArchive() |
219 |
// compute fragment cache |
212 |
&& !root.isOpen() |
220 |
HashtableOfArrayToObject fragmentsCache = new HashtableOfArrayToObject(); |
213 |
&& otherRoots.get(((JarPackageFragmentRoot) root).jarPath) == null/*only if jar belongs to 1 project (https://bugs.eclipse.org/bugs/show_bug.cgi?id=161175)*/) { |
221 |
initializePackageNames(root, fragmentsCache); |
214 |
JarPackageFragmentRootInfo info = new JarPackageFragmentRootInfo(); |
222 |
pkgFragmentsCaches.put(root, fragmentsCache); |
215 |
((JarPackageFragmentRoot) root).computeChildren(info, new HashMap()); |
|
|
216 |
frags = info.children; |
217 |
} else |
218 |
frags = root.getChildren(); |
219 |
} catch (JavaModelException e) { |
220 |
// root doesn't exist: ignore |
221 |
continue; |
222 |
} |
223 |
for (int j = 0, length2 = frags.length; j < length2; j++) { |
224 |
PackageFragment fragment= (PackageFragment) frags[j]; |
225 |
String[] pkgName = fragment.names; |
226 |
Object existing = fragmentsCache.get(pkgName); |
227 |
if (existing == null || existing == NO_ROOTS) { |
228 |
fragmentsCache.put(pkgName, root); |
229 |
// ensure super packages (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=119161) |
230 |
// are also in the map |
231 |
addSuperPackageNames(pkgName, fragmentsCache); |
232 |
} else { |
233 |
if (existing instanceof PackageFragmentRoot) { |
234 |
fragmentsCache.put(pkgName, new IPackageFragmentRoot[] {(PackageFragmentRoot) existing, root}); |
235 |
} else { |
236 |
IPackageFragmentRoot[] entry= (IPackageFragmentRoot[]) existing; |
237 |
IPackageFragmentRoot[] copy= new IPackageFragmentRoot[entry.length + 1]; |
238 |
System.arraycopy(entry, 0, copy, 0, entry.length); |
239 |
copy[entry.length]= root; |
240 |
fragmentsCache.put(pkgName, copy); |
241 |
} |
242 |
} |
243 |
} |
223 |
} |
244 |
} |
224 |
} |
245 |
cache = new ProjectCache(roots, fragmentsCache, reverseMap); |
225 |
|
|
|
226 |
cache = new ProjectCache(roots, reverseMap, pkgFragmentsCaches); |
246 |
this.projectCache = cache; |
227 |
this.projectCache = cache; |
247 |
} |
228 |
} |
248 |
return cache; |
229 |
return cache; |
Lines 258-263
Link Here
|
258 |
} |
239 |
} |
259 |
return this.nonJavaResources; |
240 |
return this.nonJavaResources; |
260 |
} |
241 |
} |
|
|
242 |
|
243 |
private void initializePackageNames(IPackageFragmentRoot root, HashtableOfArrayToObject fragmentsCache) { |
244 |
IJavaElement[] frags = null; |
245 |
try { |
246 |
if (!root.isOpen()) { |
247 |
PackageFragmentRootInfo info = root.isArchive() ? new JarPackageFragmentRootInfo() : new PackageFragmentRootInfo(); |
248 |
((PackageFragmentRoot) root).computeChildren(info, new HashMap()); |
249 |
frags = info.children; |
250 |
} else |
251 |
frags = root.getChildren(); |
252 |
} catch (JavaModelException e) { |
253 |
// root doesn't exist: ignore |
254 |
return; |
255 |
} |
256 |
for (int j = 0, length2 = frags.length; j < length2; j++) { |
257 |
PackageFragment fragment= (PackageFragment) frags[j]; |
258 |
String[] pkgName = fragment.names; |
259 |
Object existing = fragmentsCache.get(pkgName); |
260 |
if (existing == null || existing == NO_ROOTS) { |
261 |
fragmentsCache.put(pkgName, root); |
262 |
// ensure super packages (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=119161) |
263 |
// are also in the map |
264 |
addSuperPackageNames(pkgName, fragmentsCache); |
265 |
} else { |
266 |
if (existing instanceof PackageFragmentRoot) { |
267 |
fragmentsCache.put(pkgName, new IPackageFragmentRoot[] {(PackageFragmentRoot) existing, root}); |
268 |
} else { |
269 |
IPackageFragmentRoot[] entry= (IPackageFragmentRoot[]) existing; |
270 |
IPackageFragmentRoot[] copy= new IPackageFragmentRoot[entry.length + 1]; |
271 |
System.arraycopy(entry, 0, copy, 0, entry.length); |
272 |
copy[entry.length]= root; |
273 |
fragmentsCache.put(pkgName, copy); |
274 |
} |
275 |
} |
276 |
} |
277 |
} |
261 |
|
278 |
|
262 |
/* |
279 |
/* |
263 |
* Returns whether the given path is a classpath entry or an output location. |
280 |
* Returns whether the given path is a classpath entry or an output location. |
Lines 284-289
Link Here
|
284 |
*/ |
301 |
*/ |
285 |
NameLookup newNameLookup(JavaProject project, ICompilationUnit[] workingCopies) { |
302 |
NameLookup newNameLookup(JavaProject project, ICompilationUnit[] workingCopies) { |
286 |
ProjectCache cache = getProjectCache(project); |
303 |
ProjectCache cache = getProjectCache(project); |
|
|
304 |
HashtableOfArrayToObject allPkgFragmentsCache = cache.allPkgFragmentsCache; |
305 |
if (allPkgFragmentsCache == null) { |
306 |
HashMap rootInfos = JavaModelManager.getJavaModelManager().deltaState.roots; |
307 |
IPackageFragmentRoot[] allRoots = cache.allPkgFragmentRootsCache; |
308 |
int length = allRoots.length; |
309 |
allPkgFragmentsCache = new HashtableOfArrayToObject(); |
310 |
for (int i = 0; i < length; i++) { |
311 |
IPackageFragmentRoot root = allRoots[i]; |
312 |
DeltaProcessor.RootInfo rootInfo = (DeltaProcessor.RootInfo) rootInfos.get(root.getPath()); |
313 |
JavaProject rootProject = rootInfo == null ? project : rootInfo.project; |
314 |
HashtableOfArrayToObject fragmentsCache; |
315 |
if (rootProject.equals(project)) { |
316 |
fragmentsCache = (HashtableOfArrayToObject) cache.pkgFragmentsCaches.get(root); |
317 |
} else { |
318 |
// retrieve fragment cache from root project |
319 |
ProjectCache rootProjectCache; |
320 |
try { |
321 |
rootProjectCache = rootProject.getProjectCache(); |
322 |
} catch (JavaModelException e) { |
323 |
// project doesn't exit |
324 |
continue; |
325 |
} |
326 |
fragmentsCache = (HashtableOfArrayToObject) rootProjectCache.pkgFragmentsCaches.get(root); |
327 |
} |
328 |
Object[][] keyTable = fragmentsCache.keyTable; |
329 |
for (int j = 0, length2 = keyTable.length; j < length2; j++) { |
330 |
String[] pkgName = (String[]) fragmentsCache.keyTable[j]; |
331 |
if (pkgName == null) |
332 |
continue; |
333 |
Object existing = allPkgFragmentsCache.get(pkgName); |
334 |
if (existing == null || existing == NO_ROOTS) { |
335 |
allPkgFragmentsCache.put(pkgName, root); |
336 |
// ensure super packages (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=119161) |
337 |
// are also in the map |
338 |
JavaProjectElementInfo.addSuperPackageNames(pkgName, allPkgFragmentsCache); |
339 |
} else { |
340 |
if (existing instanceof PackageFragmentRoot) { |
341 |
allPkgFragmentsCache.put(pkgName, new IPackageFragmentRoot[] {(PackageFragmentRoot) existing, root}); |
342 |
} else { |
343 |
IPackageFragmentRoot[] roots = (IPackageFragmentRoot[]) existing; |
344 |
int rootLength = roots.length; |
345 |
System.arraycopy(roots, 0, roots = new IPackageFragmentRoot[rootLength+1], 0, rootLength); |
346 |
roots[rootLength] = root; |
347 |
allPkgFragmentsCache.put(pkgName, roots); |
348 |
} |
349 |
} |
350 |
} |
351 |
} |
352 |
cache.allPkgFragmentsCache = allPkgFragmentsCache; |
353 |
} |
287 |
return new NameLookup(cache.allPkgFragmentRootsCache, cache.allPkgFragmentsCache, workingCopies, cache.rootToResolvedEntries); |
354 |
return new NameLookup(cache.allPkgFragmentRootsCache, cache.allPkgFragmentsCache, workingCopies, cache.rootToResolvedEntries); |
288 |
} |
355 |
} |
289 |
|
356 |
|