* @param logger logger to use
* @param units collection of compilation units to process
*/
public void addNewUnits(TreeLogger logger,
Collection<CompilationUnit> units) {
Event typeOracleMediatorEvent = SpeedTracerLogger.start(CompilerEventType.TYPE_ORACLE_MEDIATOR);
// First collect all class data.
Event visitClassFileEvent = SpeedTracerLogger.start(
CompilerEventType.TYPE_ORACLE_MEDIATOR, "phase", "Visit Class Files");
classMap = new HashMap<String, CollectClassData>();
for (CompilationUnit unit : units) {
Collection<CompiledClass> compiledClasses = unit.getCompiledClasses();
for (CompiledClass compiledClass : compiledClasses) {
// XXX <<< Instantiations
if (compiledClass.getBytes().length == 0) {
continue;
}
// XXX >>> Instantiations
CollectClassData cv = processClass(compiledClass);
// skip any classes that can't be referenced by name outside of
// their local scope, such as anonymous classes and method-local classes
if (!cv.hasNoExternalName()) {
classMap.put(compiledClass.getInternalName(), cv);
}
}
}
visitClassFileEvent.end();
Event identityEvent = SpeedTracerLogger.start(
CompilerEventType.TYPE_ORACLE_MEDIATOR, "phase", "Establish Identity");
// Perform a shallow pass to establish identity for new and old types.
classMapType = new HashMap<JRealClassType, CollectClassData>();
allMethodArgs = new MethodArgNamesLookup();
Set<JRealClassType> unresolvedTypes = new HashSet<JRealClassType>();
for (CompilationUnit unit : units) {
Collection<CompiledClass> compiledClasses = unit.getCompiledClasses();
for (CompiledClass compiledClass : compiledClasses) {
String internalName = compiledClass.getInternalName();
CollectClassData cv = classMap.get(internalName);
if (cv == null) {
// ignore classes that were skipped earlier
continue;
}
JRealClassType type = createType(compiledClass, unresolvedTypes);
if (type != null) {
allMethodArgs.mergeFrom(unit.getMethodArgs());
binaryMapper.put(internalName, type);
classMapType.put(type, cv);
}
}
}
identityEvent.end();
Event resolveEnclosingEvent = SpeedTracerLogger.start(CompilerEventType.TYPE_ORACLE_MEDIATOR, "phase", "Resolve Enclosing Classes");
// Hook up enclosing types
TreeLogger branch = logger.branch(TreeLogger.SPAM,
"Resolving enclosing classes");
for (Iterator<JRealClassType> it = unresolvedTypes.iterator(); it.hasNext();) {
JRealClassType type = it.next();
if (!resolveEnclosingClass(branch, type)) {
// already logged why it failed, don't try and use it further
it.remove();
}
}
resolveEnclosingEvent.end();
Event resolveUnresolvedEvent = SpeedTracerLogger.start(CompilerEventType.TYPE_ORACLE_MEDIATOR, "phase", "Resolve Unresolved Types");
// Resolve unresolved types.
for (JRealClassType type : unresolvedTypes) {
branch = logger.branch(TreeLogger.SPAM, "Resolving "
+ type.getQualifiedSourceName());
if (!resolveClass(branch, type)) {
// already logged why it failed
// TODO: should we do anything else here?
}
}
resolveUnresolvedEvent.end();
Event finishEvent = SpeedTracerLogger.start(CompilerEventType.TYPE_ORACLE_MEDIATOR, "phase", "Finish");
super.finish();
finishEvent.end();
// no longer needed
allMethodArgs = null;
classMap = null;
classMapType = null;