classLiteral);
}
private JExpression createStaticRebindExpression(JMethodCall gwtCreateCall,
JClassLiteral classLiteral) {
JDeclaredType type = (JDeclaredType) classLiteral.getRefType();
String reboundTypeName = type.getName();
// TODO(stalcup): below a MinimalRebuildCache pattern of "clear cache entries for a type" and
// "rebuild cache entries for that type" is followed. There is a danger that a compile error
// could occur between the two stages and leave the cache in an invalid state. Switch to a
// transactionally safe update pattern like always updating a copy and swapping out the
// original for the copy at the end of a successful compile.
if (incrementalCompile) {
// If this is the first time we've rebound this type during this compile.
if (reboundTypeNames.add(reboundTypeName)) {
// The rebinding of this type will accumulate rebound type to input resource associations,
// but the accumulation should start from scratch, so clear any existing associations that
// might have been collected in previous compiles.
minimalRebuildCache.clearReboundTypeAssociations(reboundTypeName);
}
minimalRebuildCache.recordRebinderTypeForReboundType(reboundTypeName,
currentMethod.getEnclosingType().getName());
rpo.getGeneratorContext().setCurrentRebindBinaryTypeName(reboundTypeName);
}
String reqType = BinaryName.toSourceName(reboundTypeName);
List<String> answers;
try {
answers = Lists.create(rpo.getAllPossibleRebindAnswers(logger, reqType));
if (incrementalCompile) {
// Accumulate generated artifacts so that they can be output on recompiles even if no
// generators are run.
minimalRebuildCache.addGeneratedArtifacts(rpo.getGeneratorContext().getArtifacts());
}
rpo.getGeneratorContext().finish(logger);
if (incrementalCompile) {
// There may be more types known to be modified after Generator execution, which would
// mean the previous stale types calculation was too small. Redo it.
staleTypeNames =
minimalRebuildCache.computeAndClearStaleTypesCache(logger, program.typeOracle);
checkPreambleTypesStillFresh(logger);
fullFlowIntoRemainingStaleTypes();
}
} catch (UnableToCompleteException e) {
error(gwtCreateCall, "Failed to resolve '" + reqType + "' via deferred binding");
return null;
}
ArrayList<JExpression> instantiationExpressions = new ArrayList<JExpression>(answers.size());
for (String answer : answers) {
JDeclaredType answerType = internalFindType(answer, sourceNameBasedTypeLocator, true);
if (answerType == null) {
error(gwtCreateCall, "Rebind result '" + answer + "' could not be found");
return null;
}
if (!(answerType instanceof JClassType)) {
error(gwtCreateCall, "Rebind result '" + answer + "' must be a class");
return null;
}
if (answerType.isAbstract()) {
error(gwtCreateCall, "Rebind result '" + answer + "' cannot be abstract");
return null;
}
if (isJso(answerType)) {
error(gwtCreateCall, "Rebind result '" + answer + "' cannot be a JSO");