int cpLength = classpath.length;
int newCPIndex = -1;
for (int i = 0; i < cpLength; i++) {
IClasspathEntry entry = classpath[i];
IPath entryPath = entry.getPath();
if (rootPath.equals(entryPath)) {
// rename entry
if (newClasspath == null) {
newClasspath = new IClasspathEntry[cpLength];
System.arraycopy(classpath, 0, newClasspath, 0, i);
newCPIndex = i;
}
newClasspath[newCPIndex++] = copy(entry);
} else if (this.destination.equals(entryPath)) {
// remove entry equals to destination
if (newClasspath == null) {
newClasspath = new IClasspathEntry[cpLength];
System.arraycopy(classpath, 0, newClasspath, 0, i);
newCPIndex = i;
}
} else if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
// update exclusion/inclusion patterns
IPath projectRelativePath = rootPath.removeFirstSegments(1);
IPath[] newExclusionPatterns = renamePatterns(projectRelativePath, entry.getExclusionPatterns());
IPath[] newInclusionPatterns = renamePatterns(projectRelativePath, entry.getInclusionPatterns());
if (newExclusionPatterns != null || newInclusionPatterns != null) {
if (newClasspath == null) {
newClasspath = new IClasspathEntry[cpLength];