Set addedCups = cacheManager.getAddedCups();
TypeOracle oracle = cacheManager.getTypeOracle();
// Make a copy that we can sort.
//
for (Iterator iter = addedCups.iterator(); iter.hasNext();) {
CompilationUnitProvider cup = (CompilationUnitProvider) iter.next();
String location = cup.getLocation();
if (!((location.indexOf("http://") != -1) || (location.indexOf("ftp://") != -1))) {
location = Util.findFileName(location);
if (!(new File(location).exists() || cup.isTransient())) {
iter.remove();
logger.log(
TreeLogger.TRACE,
"The file "
+ location
+ " was removed by the user. All types therein are now unavailable.",
null);
}
}
}
CompilationUnitProvider[] cups = (CompilationUnitProvider[]) Util.toArray(
CompilationUnitProvider.class, addedCups);
Arrays.sort(cups, CompilationUnitProvider.LOCATION_COMPARATOR);
// Make sure we can find the java.lang.Object compilation unit.
//
boolean foundJavaLangPackage = oracle.findPackage("java.lang") != null;
// Adapt to JDT idioms.
//
ICompilationUnit[] units = new ICompilationUnit[cups.length];
for (int i = 0; i < cups.length; i++) {
if (!foundJavaLangPackage && cups[i].getPackageName().equals("java.lang")) {
foundJavaLangPackage = true;
}
units[i] = cacheManager.findUnitForCup(cups[i]);
}
// Error if no java.lang.
if (!foundJavaLangPackage) {
Util.logMissingTypeErrorWithHints(logger, "java.lang.Object");
throw new UnableToCompleteException();
}
cacheManager.invalidateOnRefresh(oracle);
CompilationUnitDeclaration[] cuds = cacheManager.getAstCompiler().getCompilationUnitDeclarations(
logger, units);
// Build a list that makes it easy to remove problems.
//
final Map cudsByFileName = new HashMap();
for (int i = 0; i < cuds.length; i++) {
CompilationUnitDeclaration cud = cuds[i];
char[] location = cud.getFileName();
cudsByFileName.put(String.valueOf(location), cud);
}
cacheManager.getCudsByFileName().putAll(cudsByFileName);
// Remove bad cuds and all the other cuds that are affected.
//
removeUnitsWithErrors(logger, cudsByFileName);
// Also remove any compilation units that we've seen before.
//
for (Iterator iter = cudsByFileName.values().iterator(); iter.hasNext();) {
CompilationUnitDeclaration cud = (CompilationUnitDeclaration) iter.next();
// If we've seen this compilation unit before, the type oracle will
// tell us about it and so we don't assimilate it again.
//
ICompilationUnit unit = cud.compilationResult.compilationUnit;
ICompilationUnitAdapter adapter = ((ICompilationUnitAdapter) unit);
CompilationUnitProvider cup = adapter.getCompilationUnitProvider();
JClassType[] seen = oracle.getTypesInCompilationUnit(cup);
if (seen.length > 0) {
// This compilation unit has already been assimilated.
//
iter.remove();