View | Details | Raw Unified | Return to bug 182930 | Differences between
and this patch

Collapse All | Expand All

(-)model/org/eclipse/jdt/internal/core/JavaProjectElementInfo.java (-15 / +14 lines)
Lines 33-44 Link Here
33
33
34
/* package */
34
/* package */
35
class JavaProjectElementInfo extends OpenableElementInfo {
35
class JavaProjectElementInfo extends OpenableElementInfo {
36
	
37
	static final IPackageFragmentRoot[] NO_ROOTS = new IPackageFragmentRoot[0];
36
38
37
	static class ProjectCache {
39
	static class ProjectCache {
38
		ProjectCache(IPackageFragmentRoot[] allPkgFragmentRootsCache, HashtableOfArrayToObject allPkgFragmentsCache, HashtableOfArrayToObject isPackageCache, Map rootToResolvedEntries) {
40
		ProjectCache(IPackageFragmentRoot[] allPkgFragmentRootsCache, HashtableOfArrayToObject allPkgFragmentsCache, Map rootToResolvedEntries) {
39
			this.allPkgFragmentRootsCache = allPkgFragmentRootsCache;
41
			this.allPkgFragmentRootsCache = allPkgFragmentRootsCache;
40
			this.allPkgFragmentsCache = allPkgFragmentsCache;
42
			this.allPkgFragmentsCache = allPkgFragmentsCache;
41
			this.isPackageCache = isPackageCache;
42
			this.rootToResolvedEntries = rootToResolvedEntries;
43
			this.rootToResolvedEntries = rootToResolvedEntries;
43
		}
44
		}
44
		
45
		
Lines 72-84 Link Here
72
	 * Adds the given name and its super names to the given set
73
	 * Adds the given name and its super names to the given set
73
	 * (e.g. for {"a", "b", "c"}, adds {"a", "b", "c"}, {"a", "b"}, and {"a"})
74
	 * (e.g. for {"a", "b", "c"}, adds {"a", "b", "c"}, {"a", "b"}, and {"a"})
74
	 */
75
	 */
75
	public static void addNames(String[] name, HashtableOfArrayToObject set) {
76
	public static void addSuperPackageNames(String[] pkgName, HashtableOfArrayToObject packageFragments) {
76
		set.put(name, name);
77
		int length = pkgName.length;
77
		int length = name.length;
78
		for (int i = length-1; i > 0; i--) {
78
		for (int i = length-1; i > 0; i--) {
79
			String[] superName = new String[i];
79
			System.arraycopy(pkgName, 0, pkgName = new String[i], 0, i);
80
			System.arraycopy(name, 0, superName, 0, i);
80
			if (packageFragments.get(pkgName) == null)
81
			set.put(superName, superName);
81
				packageFragments.put(pkgName, NO_ROOTS);
82
		}
82
		}
83
	}
83
	}
84
	
84
	
Lines 209-215 Link Here
209
			
209
			
210
			HashMap otherRoots = JavaModelManager.getJavaModelManager().deltaState.otherRoots;
210
			HashMap otherRoots = JavaModelManager.getJavaModelManager().deltaState.otherRoots;
211
			HashtableOfArrayToObject fragmentsCache = new HashtableOfArrayToObject();
211
			HashtableOfArrayToObject fragmentsCache = new HashtableOfArrayToObject();
212
			HashtableOfArrayToObject isPackageCache = new HashtableOfArrayToObject();
213
			for (int i = 0, length = roots.length; i < length; i++) {
212
			for (int i = 0, length = roots.length; i < length; i++) {
214
				IPackageFragmentRoot root = roots[i];
213
				IPackageFragmentRoot root = roots[i];
215
				IJavaElement[] frags = null;
214
				IJavaElement[] frags = null;
Lines 230-240 Link Here
230
					PackageFragment fragment= (PackageFragment) frags[j];
229
					PackageFragment fragment= (PackageFragment) frags[j];
231
					String[] pkgName = fragment.names;
230
					String[] pkgName = fragment.names;
232
					Object existing = fragmentsCache.get(pkgName);
231
					Object existing = fragmentsCache.get(pkgName);
233
					if (existing == null) {
232
					if (existing == null || existing == NO_ROOTS) {
234
						fragmentsCache.put(pkgName, root);
233
						fragmentsCache.put(pkgName, root);
235
						// cache whether each package and its including packages (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=119161)
234
						// ensure super packages (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=119161)
236
						// are actual packages
235
						// are also in the map
237
						addNames(pkgName, isPackageCache);
236
						addSuperPackageNames(pkgName, fragmentsCache);
238
					} else {
237
					} else {
239
						if (existing instanceof PackageFragmentRoot) {
238
						if (existing instanceof PackageFragmentRoot) {
240
							fragmentsCache.put(pkgName, new IPackageFragmentRoot[] {(PackageFragmentRoot) existing, root});
239
							fragmentsCache.put(pkgName, new IPackageFragmentRoot[] {(PackageFragmentRoot) existing, root});
Lines 248-254 Link Here
248
					}
247
					}
249
				}
248
				}
250
			}
249
			}
251
			cache = new ProjectCache(roots, fragmentsCache, isPackageCache, reverseMap);
250
			cache = new ProjectCache(roots, fragmentsCache, reverseMap);
252
			this.projectCache = cache;
251
			this.projectCache = cache;
253
		}
252
		}
254
		return cache;
253
		return cache;
Lines 290-296 Link Here
290
	 */
289
	 */
291
	NameLookup newNameLookup(JavaProject project, ICompilationUnit[] workingCopies) {
290
	NameLookup newNameLookup(JavaProject project, ICompilationUnit[] workingCopies) {
292
		ProjectCache cache = getProjectCache(project);
291
		ProjectCache cache = getProjectCache(project);
293
		return new NameLookup(cache.allPkgFragmentRootsCache, cache.allPkgFragmentsCache, cache.isPackageCache, workingCopies, cache.rootToResolvedEntries);
292
		return new NameLookup(cache.allPkgFragmentRootsCache, cache.allPkgFragmentsCache, workingCopies, cache.rootToResolvedEntries);
294
	}
293
	}
295
	
294
	
296
	/*
295
	/*
(-)model/org/eclipse/jdt/internal/core/NameLookup.java (-14 / +5 lines)
Lines 125-136 Link Here
125
	 */
125
	 */
126
	protected HashtableOfArrayToObject packageFragments;
126
	protected HashtableOfArrayToObject packageFragments;
127
	
127
	
128
	/*
129
	 * A set of names (String[]) that are known to be package names.
130
	 * Value is not null for known package.
131
	 */
132
	protected HashtableOfArrayToObject isPackageCache;
133
134
	/**
128
	/**
135
	 * Reverse map from root path to corresponding resolved CP entry
129
	 * Reverse map from root path to corresponding resolved CP entry
136
	 * (so as to be able to figure inclusion/exclusion rules)
130
	 * (so as to be able to figure inclusion/exclusion rules)
Lines 149-155 Link Here
149
	public NameLookup(
143
	public NameLookup(
150
			IPackageFragmentRoot[] packageFragmentRoots, 
144
			IPackageFragmentRoot[] packageFragmentRoots, 
151
			HashtableOfArrayToObject packageFragments, 
145
			HashtableOfArrayToObject packageFragments, 
152
			HashtableOfArrayToObject isPackage, 
153
			ICompilationUnit[] workingCopies, 
146
			ICompilationUnit[] workingCopies, 
154
			Map rootToResolvedEntries) {
147
			Map rootToResolvedEntries) {
155
		long start = -1;
148
		long start = -1;
Lines 163-174 Link Here
163
		this.packageFragmentRoots = packageFragmentRoots;
156
		this.packageFragmentRoots = packageFragmentRoots;
164
		if (workingCopies == null) {
157
		if (workingCopies == null) {
165
			this.packageFragments = packageFragments;
158
			this.packageFragments = packageFragments;
166
			this.isPackageCache = isPackage;
167
		} else {
159
		} else {
168
			// clone tables as we're adding packages from working copies
160
			// clone tables as we're adding packages from working copies
169
			try {
161
			try {
170
				this.packageFragments = (HashtableOfArrayToObject) packageFragments.clone();
162
				this.packageFragments = (HashtableOfArrayToObject) packageFragments.clone();
171
				this.isPackageCache = (HashtableOfArrayToObject) isPackage.clone();
172
			} catch (CloneNotSupportedException e1) {
163
			} catch (CloneNotSupportedException e1) {
173
				// ignore (implementation of HashtableOfArrayToObject supports cloning)
164
				// ignore (implementation of HashtableOfArrayToObject supports cloning)
174
			}
165
			}
Lines 213-223 Link Here
213
				IPackageFragmentRoot root = (IPackageFragmentRoot) pkg.getParent();
204
				IPackageFragmentRoot root = (IPackageFragmentRoot) pkg.getParent();
214
				String[] pkgName = pkg.names;
205
				String[] pkgName = pkg.names;
215
				Object existing = this.packageFragments.get(pkgName);
206
				Object existing = this.packageFragments.get(pkgName);
216
				if (existing == null) {
207
				if (existing == null || existing == JavaProjectElementInfo.NO_ROOTS) {
217
					this.packageFragments.put(pkgName, root);
208
					this.packageFragments.put(pkgName, root);
218
					// cache whether each package and its including packages (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=119161)
209
					// ensure super packages (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=119161)
219
					// are actual packages
210
					// are also in the map
220
					JavaProjectElementInfo.addNames(pkgName, this.isPackageCache);
211
					JavaProjectElementInfo.addSuperPackageNames(pkgName, this.packageFragments);
221
				} else {
212
				} else {
222
					if (existing instanceof PackageFragmentRoot) {
213
					if (existing instanceof PackageFragmentRoot) {
223
						if (!existing.equals(root))
214
						if (!existing.equals(root))
Lines 778-784 Link Here
778
	}
769
	}
779
	
770
	
780
	public boolean isPackage(String[] pkgName) {
771
	public boolean isPackage(String[] pkgName) {
781
		return this.isPackageCache.get(pkgName) != null;
772
		return this.packageFragments.get(pkgName) != null;
782
	}
773
	}
783
774
784
	/**
775
	/**

Return to bug 182930