String lookupClassName = canonicalizeClassName(className);
CompiledClass compiledClass = compilationState.getClassFileMap().get(
lookupClassName);
CompilationUnit unit = (compiledClass == null)
? getUnitForClassName(lookupClassName) : compiledClass.getUnit();
if (emmaAvailable) {
/*
* build the map for anonymous classes. Do so only if unit has anonymous
* classes, jsni methods, is not super-source and the map has not been
* built before.
*/
List<JsniMethod> jsniMethods = (unit == null) ? null
: unit.getJsniMethods();
if (unit != null && !unit.isSuperSource() && !unit.isGenerated()
&& unit.hasAnonymousClasses() && jsniMethods != null
&& jsniMethods.size() > 0 && !unit.createdClassMapping()) {
if (!unit.constructAnonymousClassMappings(logger)) {
logger.log(TreeLogger.ERROR,
"Our heuristic for mapping anonymous classes between compilers "
+ "failed. Unsafe to continue because the wrong jsni code "
+ "could end up running. className = " + className);
return null;
}
}
}
byte classBytes[] = null;
if (compiledClass != null) {
classBytes = compiledClass.getBytes();
if (!compiledClass.getUnit().isSuperSource()) {
classBytes = emmaStrategy.getEmmaClassBytes(classBytes,
lookupClassName, compiledClass.getUnit().getLastModified());
} else {
if (logger.isLoggable(TreeLogger.SPAM)) {
logger.log(TreeLogger.SPAM, "no emma instrumentation for "
+ lookupClassName + " because it is from super-source");
}
}
} else if (emmaAvailable) {
/*
* TypeOracle does not know about this class. Most probably, this class
* was referenced in one of the classes loaded from disk. Check if we can
* find it on disk. Typically this is a synthetic class added by the
* compiler.
*/
if (typeHasCompilationUnit(lookupClassName)
&& CompilationUnit.isClassnameGenerated(className)) {
/*
* modification time = 0 ensures that whatever is on the disk is always
* loaded.
*/
if (logger.isLoggable(TreeLogger.DEBUG)) {
logger.log(TreeLogger.DEBUG, "EmmaStrategy: loading " + lookupClassName
+ " from disk even though TypeOracle does not know about it");
}
classBytes = emmaStrategy.getEmmaClassBytes(null, lookupClassName, 0);
}
}
if (classBytes != null && classRewriter != null) {
Map<String, String> anonymousClassMap = Collections.emptyMap();
if (unit != null) {
anonymousClassMap = unit.getAnonymousClassMap();
}
byte[] newBytes = classRewriter.rewrite(typeOracle, className,
classBytes, anonymousClassMap);
if (CLASS_DUMP) {
if (!Arrays.equals(classBytes, newBytes)) {
classDump(className, newBytes);
}
}
classBytes = newBytes;
}
if (unit != null && unit.isError()) {
// Compile worked, but the unit had some kind of error (JSNI?)
CompilationProblemReporter.reportErrors(logger, unit, false);
}
return classBytes;