this.packageFragments = (HashtableOfArrayToObject) packageFragments.clone();
} catch (CloneNotSupportedException e1) {
// ignore (implementation of HashtableOfArrayToObject supports cloning)
}
this.typesInWorkingCopies = new HashMap();
HashtableOfObjectToInt rootPositions = new HashtableOfObjectToInt();
for (int i = 0, length = packageFragmentRoots.length; i < length; i++) {
rootPositions.put(packageFragmentRoots[i], i);
}
for (int i = 0, length = workingCopies.length; i < length; i++) {
ICompilationUnit workingCopy = workingCopies[i];
PackageFragment pkg = (PackageFragment) workingCopy.getParent();
IPackageFragmentRoot root = (IPackageFragmentRoot) pkg.getParent();
int rootPosition = rootPositions.get(root);
if (rootPosition == -1)
continue; // working copy is not visible from this project (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=169970)
HashMap typeMap = (HashMap) this.typesInWorkingCopies.get(pkg);
if (typeMap == null) {
typeMap = new HashMap();
this.typesInWorkingCopies.put(pkg, typeMap);
}
try {
IType[] types = workingCopy.getTypes();
int typeLength = types.length;
if (typeLength == 0) {
String typeName = Util.getNameWithoutJavaLikeExtension(workingCopy.getElementName());
typeMap.put(typeName, NO_TYPES);
} else {
for (int j = 0; j < typeLength; j++) {
IType type = types[j];
String typeName = type.getElementName();
Object existing = typeMap.get(typeName);
if (existing == null) {
typeMap.put(typeName, type);
} else if (existing instanceof IType) {
typeMap.put(typeName, new IType[] {(IType) existing, type});
} else {
IType[] existingTypes = (IType[]) existing;
int existingTypeLength = existingTypes.length;
System.arraycopy(existingTypes, 0, existingTypes = new IType[existingTypeLength+1], 0, existingTypeLength);
existingTypes[existingTypeLength] = type;
typeMap.put(typeName, existingTypes);
}
}
}
} catch (JavaModelException e) {
// working copy doesn't exist -> ignore
}
// add root of package fragment to cache
String[] pkgName = pkg.names;
Object existing = this.packageFragments.get(pkgName);
if (existing == null || existing == JavaProjectElementInfo.NO_ROOTS) {
this.packageFragments.put(pkgName, root);
// ensure super packages (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=119161)
// are also in the map
JavaProjectElementInfo.addSuperPackageNames(pkgName, this.packageFragments);
} else {
if (existing instanceof PackageFragmentRoot) {
int exisitingPosition = rootPositions.get(existing);
if (rootPosition != exisitingPosition) { // if not equal
this.packageFragments.put(
pkgName,
exisitingPosition < rootPosition ?
new IPackageFragmentRoot[] {(PackageFragmentRoot) existing, root} :
new IPackageFragmentRoot[] {root, (PackageFragmentRoot) existing});
}
} else {
// insert root in the existing list
IPackageFragmentRoot[] roots = (IPackageFragmentRoot[]) existing;
int rootLength = roots.length;
int insertionIndex = 0;
for (int j = 0; j < rootLength; j++) {
int existingPosition = rootPositions.get(roots[j]);
if (rootPosition > existingPosition) {
// root is after this index
insertionIndex = j;
} else if (rootPosition == existingPosition) {
// root already in the existing list