### Eclipse Workspace Patch 1.0 #P org.eclipse.jdt.core Index: model/org/eclipse/jdt/internal/core/ClasspathChange.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/ClasspathChange.java,v retrieving revision 1.25 diff -u -r1.25 ClasspathChange.java --- model/org/eclipse/jdt/internal/core/ClasspathChange.java 23 Jun 2009 05:40:04 -0000 1.25 +++ model/org/eclipse/jdt/internal/core/ClasspathChange.java 17 Mar 2011 06:11:47 -0000 @@ -28,6 +28,7 @@ import org.eclipse.jdt.core.IPackageFragmentRoot; import org.eclipse.jdt.core.JavaModelException; import org.eclipse.jdt.internal.compiler.util.ObjectVector; +import org.eclipse.jdt.internal.core.DeltaProcessor.RootInfo; import org.eclipse.jdt.internal.core.JavaModelManager.PerProjectInfo; import org.eclipse.jdt.internal.core.search.indexing.IndexManager; import org.eclipse.jdt.internal.core.util.Util; @@ -304,7 +305,7 @@ result |= HAS_LIBRARY_CHANGE; } - PackageFragmentRoot[] pkgFragmentRoots = null; + IPackageFragmentRoot[] pkgFragmentRoots = null; if (removedRoots != null) { PackageFragmentRoot oldRoot = (PackageFragmentRoot) removedRoots.get(this.oldResolvedClasspath[i].getPath()); if (oldRoot != null) { // use old root if any (could be none if entry wasn't bound) @@ -323,6 +324,26 @@ null, // inside original project false, // don't retrieve exported roots null); /*no reverse map*/ + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=335986 + // When a package fragment's corresponding resource is removed from the project, + // IJavaProject#computePackageFragmentRoots() doesn't include that entry. Hence + // the cache become necessary in such cases. Add the cache to the accumulatedRoots + // only when it's not already present. + RootInfo rootInfo = (RootInfo) state.oldRoots.get(this.oldResolvedClasspath[i].getPath()); + if (rootInfo != null && rootInfo.cache != null) { + IPackageFragmentRoot oldRoot = rootInfo.cache; + boolean found = false; + for (int j = 0; j < accumulatedRoots.size(); j++) { + IPackageFragmentRoot root = (IPackageFragmentRoot) accumulatedRoots.elementAt(j); + if (!root.getPath().equals(oldRoot.getPath())) { + found = true; + break; + } + } + if (!found) + accumulatedRoots.add(oldRoot); + } + pkgFragmentRoots = new PackageFragmentRoot[accumulatedRoots.size()]; accumulatedRoots.copyInto(pkgFragmentRoots); } catch (JavaModelException e) { Index: model/org/eclipse/jdt/internal/core/DeltaProcessor.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/DeltaProcessor.java,v retrieving revision 1.342 diff -u -r1.342 DeltaProcessor.java --- model/org/eclipse/jdt/internal/core/DeltaProcessor.java 4 Mar 2011 13:54:41 -0000 1.342 +++ model/org/eclipse/jdt/internal/core/DeltaProcessor.java 17 Mar 2011 06:11:47 -0000 @@ -105,26 +105,35 @@ IPath rootPath; int entryKind; IPackageFragmentRoot root; + IPackageFragmentRoot cache; RootInfo(JavaProject project, IPath rootPath, char[][] inclusionPatterns, char[][] exclusionPatterns, int entryKind) { this.project = project; this.rootPath = rootPath; this.inclusionPatterns = inclusionPatterns; this.exclusionPatterns = exclusionPatterns; this.entryKind = entryKind; + this.cache = getPackageFragmentRoot(); + } + public IPackageFragmentRoot getPackageFragmentRoot() { + IPackageFragmentRoot tRoot = null; + Object target = JavaModel.getTarget(this.rootPath, false/*don't check existence*/); + if (target instanceof IResource) { + tRoot = this.project.getPackageFragmentRoot((IResource)target); + } else { + tRoot = this.project.getPackageFragmentRoot(this.rootPath.toOSString()); + } + return tRoot; } public IPackageFragmentRoot getPackageFragmentRoot(IResource resource) { if (this.root == null) { if (resource != null) { this.root = this.project.getPackageFragmentRoot(resource); } else { - Object target = JavaModel.getTarget(this.rootPath, false/*don't check existence*/); - if (target instanceof IResource) { - this.root = this.project.getPackageFragmentRoot((IResource)target); - } else { - this.root = this.project.getPackageFragmentRoot(this.rootPath.toOSString()); - } + this.root = getPackageFragmentRoot(); } } + if (this.root != null) + this.cache = this.root; return this.root; } boolean isRootOfProject(IPath path) { #P org.eclipse.jdt.core.tests.model Index: src/org/eclipse/jdt/core/tests/model/JavaElementDeltaTests.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaElementDeltaTests.java,v retrieving revision 1.97 diff -u -r1.97 JavaElementDeltaTests.java --- src/org/eclipse/jdt/core/tests/model/JavaElementDeltaTests.java 30 Nov 2010 15:06:52 -0000 1.97 +++ src/org/eclipse/jdt/core/tests/model/JavaElementDeltaTests.java 17 Mar 2011 06:11:50 -0000 @@ -2432,7 +2432,8 @@ setClasspath(p, new IClasspathEntry[] {}); assertDeltas( "Unexpected delta", - "P[*]: {CONTENT | RAW CLASSPATH CHANGED | RESOLVED CLASSPATH CHANGED}\n" + + "P[*]: {CHILDREN | CONTENT | RAW CLASSPATH CHANGED | RESOLVED CLASSPATH CHANGED}\n" + + " "+ getExternalPath() + "externalLib[*]: {REMOVED FROM CLASSPATH}\n" + " ResourceDelta(/P/.classpath)[*]" ); } finally { @@ -2523,7 +2524,8 @@ setClasspath(p, new IClasspathEntry[] {}); assertDeltas( "Unexpected delta", - "P[*]: {CONTENT | RAW CLASSPATH CHANGED | RESOLVED CLASSPATH CHANGED}\n" + + "P[*]: {CHILDREN | CONTENT | RAW CLASSPATH CHANGED | RESOLVED CLASSPATH CHANGED}\n" + + " "+ getExternalPath() + "externalLib.abc[*]: {REMOVED FROM CLASSPATH}\n" + " ResourceDelta(/P/.classpath)[*]" ); } finally { stopDeltas();