roots = (IPackageFragmentRoot[]) allOldRoots.get(this.project);
}
if (roots != null) {
removedRoots = new HashMap();
for (int i = 0; i < roots.length; i++) {
IPackageFragmentRoot root = roots[i];
removedRoots.put(root.getPath(), root);
}
}
int newLength = newResolvedClasspath.length;
int oldLength = this.oldResolvedClasspath.length;
for (int i = 0; i < oldLength; i++) {
int index = classpathContains(newResolvedClasspath, this.oldResolvedClasspath[i]);
if (index == -1) {
// remote project changes
int entryKind = this.oldResolvedClasspath[i].getEntryKind();
if (entryKind == IClasspathEntry.CPE_PROJECT) {
result |= HAS_PROJECT_CHANGE;
continue;
}
if (entryKind == IClasspathEntry.CPE_LIBRARY) {
result |= HAS_LIBRARY_CHANGE;
}
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)
pkgFragmentRoots = new PackageFragmentRoot[] { oldRoot };
}
}
if (pkgFragmentRoots == null) {
try {
ObjectVector accumulatedRoots = new ObjectVector();
HashSet rootIDs = new HashSet(5);
rootIDs.add(this.project.rootID());
this.project.computePackageFragmentRoots(
this.oldResolvedClasspath[i],
accumulatedRoots,
rootIDs,
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) {
pkgFragmentRoots = new PackageFragmentRoot[] {};
}
}
addClasspathDeltas(delta, pkgFragmentRoots, IJavaElementDelta.F_REMOVED_FROM_CLASSPATH);
} else {
// remote project changes
if (this.oldResolvedClasspath[i].getEntryKind() == IClasspathEntry.CPE_PROJECT) {
result |= HAS_PROJECT_CHANGE;
continue;
}
if (index != i) { //reordering of the classpath
addClasspathDeltas(delta, this.project.computePackageFragmentRoots(this.oldResolvedClasspath[i]), IJavaElementDelta.F_REORDER);
}
// check source attachment
IPath newSourcePath = newResolvedClasspath[index].getSourceAttachmentPath();
int sourceAttachmentFlags = getSourceAttachmentDeltaFlag(this.oldResolvedClasspath[i].getSourceAttachmentPath(), newSourcePath);
IPath oldRootPath = this.oldResolvedClasspath[i].getSourceAttachmentRootPath();
IPath newRootPath = newResolvedClasspath[index].getSourceAttachmentRootPath();
int sourceAttachmentRootFlags = getSourceAttachmentDeltaFlag(oldRootPath, newRootPath);
int flags = sourceAttachmentFlags | sourceAttachmentRootFlags;
if (flags != 0) {
addClasspathDeltas(delta, this.project.computePackageFragmentRoots(this.oldResolvedClasspath[i]), flags);
} else {
if (oldRootPath == null && newRootPath == null) {
// if source path is specified and no root path, it needs to be recomputed dynamically
// force detach source on jar package fragment roots (source will be lazily computed when needed)
IPackageFragmentRoot[] computedRoots = this.project.computePackageFragmentRoots(this.oldResolvedClasspath[i]);
for (int j = 0; j < computedRoots.length; j++) {
IPackageFragmentRoot root = computedRoots[j];
// force detach source on jar package fragment roots (source will be lazily computed when needed)
try {
root.close();
} catch (JavaModelException e) {
// ignore
}
}
}