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

Collapse All | Expand All

(-)model/org/eclipse/jdt/internal/core/ClasspathChange.java (-1 / +22 lines)
Lines 28-33 Link Here
28
import org.eclipse.jdt.core.IPackageFragmentRoot;
28
import org.eclipse.jdt.core.IPackageFragmentRoot;
29
import org.eclipse.jdt.core.JavaModelException;
29
import org.eclipse.jdt.core.JavaModelException;
30
import org.eclipse.jdt.internal.compiler.util.ObjectVector;
30
import org.eclipse.jdt.internal.compiler.util.ObjectVector;
31
import org.eclipse.jdt.internal.core.DeltaProcessor.RootInfo;
31
import org.eclipse.jdt.internal.core.JavaModelManager.PerProjectInfo;
32
import org.eclipse.jdt.internal.core.JavaModelManager.PerProjectInfo;
32
import org.eclipse.jdt.internal.core.search.indexing.IndexManager;
33
import org.eclipse.jdt.internal.core.search.indexing.IndexManager;
33
import org.eclipse.jdt.internal.core.util.Util;
34
import org.eclipse.jdt.internal.core.util.Util;
Lines 304-310 Link Here
304
					result |= HAS_LIBRARY_CHANGE;
305
					result |= HAS_LIBRARY_CHANGE;
305
				}
306
				}
306
307
307
				PackageFragmentRoot[] pkgFragmentRoots = null;
308
				IPackageFragmentRoot[] pkgFragmentRoots = null;
308
				if (removedRoots != null) {
309
				if (removedRoots != null) {
309
					PackageFragmentRoot oldRoot = (PackageFragmentRoot)  removedRoots.get(this.oldResolvedClasspath[i].getPath());
310
					PackageFragmentRoot oldRoot = (PackageFragmentRoot)  removedRoots.get(this.oldResolvedClasspath[i].getPath());
310
					if (oldRoot != null) { // use old root if any (could be none if entry wasn't bound)
311
					if (oldRoot != null) { // use old root if any (could be none if entry wasn't bound)
Lines 323-328 Link Here
323
							null, // inside original project
324
							null, // inside original project
324
							false, // don't retrieve exported roots
325
							false, // don't retrieve exported roots
325
							null); /*no reverse map*/
326
							null); /*no reverse map*/
327
						// https://bugs.eclipse.org/bugs/show_bug.cgi?id=335986
328
						// When a package fragment's corresponding resource is removed from the project, 
329
						// IJavaProject#computePackageFragmentRoots() doesn't include that entry. Hence 
330
						// the cache become necessary in such cases. Add the cache to the accumulatedRoots 
331
						// only when it's not already present.
332
						RootInfo rootInfo = (RootInfo) state.oldRoots.get(this.oldResolvedClasspath[i].getPath());
333
						if (rootInfo != null && rootInfo.cache != null) {
334
							IPackageFragmentRoot oldRoot = rootInfo.cache;
335
							boolean found = false;
336
							for (int j = 0; j < accumulatedRoots.size(); j++) {
337
								IPackageFragmentRoot root = (IPackageFragmentRoot) accumulatedRoots.elementAt(j);
338
								if (!root.getPath().equals(oldRoot.getPath())) {
339
									found = true;
340
									break;
341
								}
342
							}
343
							if (!found)
344
								accumulatedRoots.add(oldRoot);
345
						}
346
326
						pkgFragmentRoots = new PackageFragmentRoot[accumulatedRoots.size()];
347
						pkgFragmentRoots = new PackageFragmentRoot[accumulatedRoots.size()];
327
						accumulatedRoots.copyInto(pkgFragmentRoots);
348
						accumulatedRoots.copyInto(pkgFragmentRoots);
328
					} catch (JavaModelException e) {
349
					} catch (JavaModelException e) {
(-)model/org/eclipse/jdt/internal/core/DeltaProcessor.java (-6 / +15 lines)
Lines 105-130 Link Here
105
		IPath rootPath;
105
		IPath rootPath;
106
		int entryKind;
106
		int entryKind;
107
		IPackageFragmentRoot root;
107
		IPackageFragmentRoot root;
108
		IPackageFragmentRoot cache;
108
		RootInfo(JavaProject project, IPath rootPath, char[][] inclusionPatterns, char[][] exclusionPatterns, int entryKind) {
109
		RootInfo(JavaProject project, IPath rootPath, char[][] inclusionPatterns, char[][] exclusionPatterns, int entryKind) {
109
			this.project = project;
110
			this.project = project;
110
			this.rootPath = rootPath;
111
			this.rootPath = rootPath;
111
			this.inclusionPatterns = inclusionPatterns;
112
			this.inclusionPatterns = inclusionPatterns;
112
			this.exclusionPatterns = exclusionPatterns;
113
			this.exclusionPatterns = exclusionPatterns;
113
			this.entryKind = entryKind;
114
			this.entryKind = entryKind;
115
			this.cache = getPackageFragmentRoot();
116
		}
117
		public IPackageFragmentRoot getPackageFragmentRoot() {
118
			IPackageFragmentRoot tRoot = null;
119
			Object target = JavaModel.getTarget(this.rootPath, false/*don't check existence*/);
120
			if (target instanceof IResource) {
121
				tRoot = this.project.getPackageFragmentRoot((IResource)target);
122
			} else {
123
				tRoot = this.project.getPackageFragmentRoot(this.rootPath.toOSString());
124
			}
125
			return tRoot;
114
		}
126
		}
115
		public IPackageFragmentRoot getPackageFragmentRoot(IResource resource) {
127
		public IPackageFragmentRoot getPackageFragmentRoot(IResource resource) {
116
			if (this.root == null) {
128
			if (this.root == null) {
117
				if (resource != null) {
129
				if (resource != null) {
118
					this.root = this.project.getPackageFragmentRoot(resource);
130
					this.root = this.project.getPackageFragmentRoot(resource);
119
				} else {
131
				} else {
120
					Object target = JavaModel.getTarget(this.rootPath, false/*don't check existence*/);
132
					this.root = getPackageFragmentRoot();
121
					if (target instanceof IResource) {
122
						this.root = this.project.getPackageFragmentRoot((IResource)target);
123
					} else {
124
						this.root = this.project.getPackageFragmentRoot(this.rootPath.toOSString());
125
					}
126
				}
133
				}
127
			}
134
			}
135
			if (this.root != null) 
136
				this.cache = this.root;
128
			return this.root;
137
			return this.root;
129
		}
138
		}
130
		boolean isRootOfProject(IPath path) {
139
		boolean isRootOfProject(IPath path) {
(-)src/org/eclipse/jdt/core/tests/model/JavaElementDeltaTests.java (-2 / +4 lines)
Lines 2432-2438 Link Here
2432
		setClasspath(p, new IClasspathEntry[] {});
2432
		setClasspath(p, new IClasspathEntry[] {});
2433
		assertDeltas(
2433
		assertDeltas(
2434
			"Unexpected delta",
2434
			"Unexpected delta",
2435
			"P[*]: {CONTENT | RAW CLASSPATH CHANGED | RESOLVED CLASSPATH CHANGED}\n" +
2435
			"P[*]: {CHILDREN | CONTENT | RAW CLASSPATH CHANGED | RESOLVED CLASSPATH CHANGED}\n" + 
2436
			"	"+ getExternalPath() + "externalLib[*]: {REMOVED FROM CLASSPATH}\n" + 
2436
			"	ResourceDelta(/P/.classpath)[*]"
2437
			"	ResourceDelta(/P/.classpath)[*]"
2437
		);
2438
		);
2438
	} finally {
2439
	} finally {
Lines 2523-2529 Link Here
2523
		setClasspath(p, new IClasspathEntry[] {});
2524
		setClasspath(p, new IClasspathEntry[] {});
2524
		assertDeltas(
2525
		assertDeltas(
2525
			"Unexpected delta",
2526
			"Unexpected delta",
2526
			"P[*]: {CONTENT | RAW CLASSPATH CHANGED | RESOLVED CLASSPATH CHANGED}\n" +
2527
			"P[*]: {CHILDREN | CONTENT | RAW CLASSPATH CHANGED | RESOLVED CLASSPATH CHANGED}\n" + 
2528
			"	"+ getExternalPath() + "externalLib.abc[*]: {REMOVED FROM CLASSPATH}\n" + 
2527
			"	ResourceDelta(/P/.classpath)[*]"		);
2529
			"	ResourceDelta(/P/.classpath)[*]"		);
2528
	} finally {
2530
	} finally {
2529
		stopDeltas();
2531
		stopDeltas();

Return to bug 335986