Lines 18-23
Link Here
|
18 |
import org.eclipse.core.runtime.CoreException; |
18 |
import org.eclipse.core.runtime.CoreException; |
19 |
import org.eclipse.core.runtime.IPath; |
19 |
import org.eclipse.core.runtime.IPath; |
20 |
import org.eclipse.jdt.core.*; |
20 |
import org.eclipse.jdt.core.*; |
|
|
21 |
import org.eclipse.jdt.internal.core.util.HashSetOfArray; |
21 |
import org.eclipse.jdt.internal.core.util.Util; |
22 |
import org.eclipse.jdt.internal.core.util.Util; |
22 |
import org.eclipse.jdt.internal.core.util.HashtableOfArrayToObject; |
23 |
import org.eclipse.jdt.internal.core.util.HashtableOfArrayToObject; |
23 |
|
24 |
|
Lines 37-46
Link Here
|
37 |
static final IPackageFragmentRoot[] NO_ROOTS = new IPackageFragmentRoot[0]; |
38 |
static final IPackageFragmentRoot[] NO_ROOTS = new IPackageFragmentRoot[0]; |
38 |
|
39 |
|
39 |
static class ProjectCache { |
40 |
static class ProjectCache { |
40 |
ProjectCache(IPackageFragmentRoot[] allPkgFragmentRootsCache, HashtableOfArrayToObject allPkgFragmentsCache, Map rootToResolvedEntries) { |
41 |
ProjectCache(IPackageFragmentRoot[] allPkgFragmentRootsCache, Map rootToResolvedEntries, Map pkgFragmentsCaches) { |
41 |
this.allPkgFragmentRootsCache = allPkgFragmentRootsCache; |
42 |
this.allPkgFragmentRootsCache = allPkgFragmentRootsCache; |
42 |
this.allPkgFragmentsCache = allPkgFragmentsCache; |
|
|
43 |
this.rootToResolvedEntries = rootToResolvedEntries; |
43 |
this.rootToResolvedEntries = rootToResolvedEntries; |
|
|
44 |
this.pkgFragmentsCaches = pkgFragmentsCaches; |
44 |
} |
45 |
} |
45 |
|
46 |
|
46 |
/* |
47 |
/* |
Lines 50-59
Link Here
|
50 |
|
51 |
|
51 |
/* |
52 |
/* |
52 |
* A cache of all package fragments in this project. |
53 |
* 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) |
54 |
* (a map from String[] (the package name) to IPackageFragmentRoot[] (the package fragment roots that contain a package fragment with this name)) |
54 |
*/ |
55 |
*/ |
55 |
public HashtableOfArrayToObject allPkgFragmentsCache; |
56 |
public HashtableOfArrayToObject allPkgFragmentsCache; |
56 |
|
57 |
|
|
|
58 |
/* |
59 |
* A cache of package fragments for each package fragment root of this project |
60 |
* (a map from IPackageFragmentRoot to a set of String[] (the package name)) |
61 |
*/ |
62 |
public Map pkgFragmentsCaches; |
63 |
|
57 |
public Map rootToResolvedEntries; |
64 |
public Map rootToResolvedEntries; |
58 |
} |
65 |
} |
59 |
|
66 |
|
Lines 68-79
Link Here
|
68 |
* Adds the given name and its super names to the given set |
75 |
* Adds the given name and its super names to the given set |
69 |
* (e.g. for {"a", "b", "c"}, adds {"a", "b", "c"}, {"a", "b"}, and {"a"}) |
76 |
* (e.g. for {"a", "b", "c"}, adds {"a", "b", "c"}, {"a", "b"}, and {"a"}) |
70 |
*/ |
77 |
*/ |
71 |
public static void addSuperPackageNames(String[] pkgName, HashtableOfArrayToObject packageFragments) { |
78 |
static void addSuperPackageNames(String[] pkgName, HashtableOfArrayToObject packageFragments) { |
72 |
int length = pkgName.length; |
79 |
for (int i = pkgName.length-1; i > 0; i--) { |
73 |
for (int i = length-1; i > 0; i--) { |
80 |
if (packageFragments.getKey(pkgName, i) == null) { |
74 |
System.arraycopy(pkgName, 0, pkgName = new String[i], 0, i); |
81 |
System.arraycopy(pkgName, 0, pkgName = new String[i], 0, i); |
75 |
if (packageFragments.get(pkgName) == null) |
|
|
76 |
packageFragments.put(pkgName, NO_ROOTS); |
82 |
packageFragments.put(pkgName, NO_ROOTS); |
|
|
83 |
} |
77 |
} |
84 |
} |
78 |
} |
85 |
} |
79 |
|
86 |
|
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 |
HashSetOfArray fragmentsCache = new HashSetOfArray(); |
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, HashSetOfArray 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 |
fragmentsCache.add(((PackageFragment) frags[j]).names); |
258 |
} |
259 |
} |
261 |
|
260 |
|
262 |
/* |
261 |
/* |
263 |
* Returns whether the given path is a classpath entry or an output location. |
262 |
* Returns whether the given path is a classpath entry or an output location. |
Lines 284-289
Link Here
|
284 |
*/ |
283 |
*/ |
285 |
NameLookup newNameLookup(JavaProject project, ICompilationUnit[] workingCopies) { |
284 |
NameLookup newNameLookup(JavaProject project, ICompilationUnit[] workingCopies) { |
286 |
ProjectCache cache = getProjectCache(project); |
285 |
ProjectCache cache = getProjectCache(project); |
|
|
286 |
HashtableOfArrayToObject allPkgFragmentsCache = cache.allPkgFragmentsCache; |
287 |
if (allPkgFragmentsCache == null) { |
288 |
HashMap rootInfos = JavaModelManager.getJavaModelManager().deltaState.roots; |
289 |
IPackageFragmentRoot[] allRoots = cache.allPkgFragmentRootsCache; |
290 |
int length = allRoots.length; |
291 |
allPkgFragmentsCache = new HashtableOfArrayToObject(); |
292 |
for (int i = 0; i < length; i++) { |
293 |
IPackageFragmentRoot root = allRoots[i]; |
294 |
DeltaProcessor.RootInfo rootInfo = (DeltaProcessor.RootInfo) rootInfos.get(root.getPath()); |
295 |
JavaProject rootProject = rootInfo == null ? project : rootInfo.project; |
296 |
HashSetOfArray fragmentsCache; |
297 |
if (rootProject.equals(project)) { |
298 |
// retrieve package fragments cache from this project |
299 |
fragmentsCache = (HashSetOfArray) cache.pkgFragmentsCaches.get(root); |
300 |
} else { |
301 |
// retrieve package fragments cache from the root's project |
302 |
ProjectCache rootProjectCache; |
303 |
try { |
304 |
rootProjectCache = rootProject.getProjectCache(); |
305 |
} catch (JavaModelException e) { |
306 |
// project doesn't exit |
307 |
continue; |
308 |
} |
309 |
fragmentsCache = (HashSetOfArray) rootProjectCache.pkgFragmentsCaches.get(root); |
310 |
} |
311 |
Object[][] set = fragmentsCache.set; |
312 |
for (int j = 0, length2 = set.length; j < length2; j++) { |
313 |
String[] pkgName = (String[]) set[j]; |
314 |
if (pkgName == null) |
315 |
continue; |
316 |
Object existing = allPkgFragmentsCache.get(pkgName); |
317 |
if (existing == null || existing == NO_ROOTS) { |
318 |
allPkgFragmentsCache.put(pkgName, root); |
319 |
// ensure super packages (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=119161) |
320 |
// are also in the map |
321 |
addSuperPackageNames(pkgName, allPkgFragmentsCache); |
322 |
} else { |
323 |
if (existing instanceof PackageFragmentRoot) { |
324 |
allPkgFragmentsCache.put(pkgName, new IPackageFragmentRoot[] {(PackageFragmentRoot) existing, root}); |
325 |
} else { |
326 |
IPackageFragmentRoot[] roots = (IPackageFragmentRoot[]) existing; |
327 |
int rootLength = roots.length; |
328 |
System.arraycopy(roots, 0, roots = new IPackageFragmentRoot[rootLength+1], 0, rootLength); |
329 |
roots[rootLength] = root; |
330 |
allPkgFragmentsCache.put(pkgName, roots); |
331 |
} |
332 |
} |
333 |
} |
334 |
} |
335 |
cache.allPkgFragmentsCache = allPkgFragmentsCache; |
336 |
} |
287 |
return new NameLookup(cache.allPkgFragmentRootsCache, cache.allPkgFragmentsCache, workingCopies, cache.rootToResolvedEntries); |
337 |
return new NameLookup(cache.allPkgFragmentRootsCache, cache.allPkgFragmentsCache, workingCopies, cache.rootToResolvedEntries); |
288 |
} |
338 |
} |
289 |
|
339 |
|