public RebindResult runGeneratorIncrementally(TreeLogger logger,
Class<? extends Generator> generatorClass, String typeName) throws UnableToCompleteException {
String msg = "Invoking generator " + generatorClass.getName();
logger = logger.branch(TreeLogger.DEBUG, msg, null);
Generator generator = generators.get(generatorClass);
if (generator == null) {
try {
generator = generatorClass.newInstance();
generators.put(generatorClass, generator);
} catch (Throwable e) {
logger.log(TreeLogger.ERROR, "Unexpected error trying to instantiate Generator '"
+ generatorClass.getName() + "'", e);
throw new UnableToCompleteException();
}
}
setCurrentGenerator(generatorClass);
// Avoid call to System.currentTimeMillis() if not logging DEBUG level
boolean loggable = logger.isLoggable(TreeLogger.DEBUG);
long before = loggable ? System.currentTimeMillis() : 0L;
String generatorClassName = generator.getClass().getName();
CompilerEventType type = eventsByGeneratorType.get(generatorClassName);
if (type == null) {
type = CompilerEventType.GENERATOR_OTHER;
}
Event generatorEvent =
SpeedTracerLogger.start(type, "class", generatorClassName, "type", typeName);
PropertyOracle originalPropertyOracle = propertyOracle;
try {
RebindResult result;
// TODO(stalcup): refactor the Generator/PropertyOracle system (in a potentially backwards
// incompatible way) so that all Generators are forced to accurately declare the names of
// properties they care about.
propertyOracle = new SubsetFilteringPropertyOracle(
RuleGenerateWith.getAccessedPropertyNames(generator.getClass()), originalPropertyOracle,
generatorClassName + "'s RunsLocal annotation may need to be updated.");
if (generator instanceof IncrementalGenerator) {
IncrementalGenerator incGenerator = (IncrementalGenerator) generator;
// check version id for any previously cached rebind result