use of com.google.gwt.core.ext.RebindResult in project mvp4g by mvp4g.
the class Mvp4gGenerator method create.
private RebindResult create(TreeLogger logger, GeneratorContext context, String moduleName) throws UnableToCompleteException {
Date start = new Date();
String generatedClassQualifiedName;
try {
TypeOracle typeOracle = context.getTypeOracle();
JClassType module = typeOracle.findType(moduleName);
if (module == null) {
logger.log(TreeLogger.ERROR, "Unable to find metadata for type '" + moduleName + "'", null);
throw new UnableToCompleteException();
}
@SuppressWarnings("unchecked") Map<Class<? extends Annotation>, List<JClassType>> scanResult = AnnotationScanner.scan(logger, typeOracle, new Class[] { Presenter.class, History.class, Events.class, Service.class, EventHandler.class });
Mvp4gConfiguration configuration = new Mvp4gConfiguration(logger, context);
String suffix = "Impl" + configuration.load(module, scanResult);
generatedClassQualifiedName = module.getParameterizedQualifiedSourceName() + suffix;
String packageName = module.getPackage().getName();
String originalClassName = module.getSimpleSourceName();
String generatedClassName = originalClassName + suffix;
// check weather there is a usual version or not.
if (checkAlreadyGenerated(logger, context, configuration)) {
// Log
logger.log(TreeLogger.INFO, "Reuse already generated files", null);
// stop generating
return new RebindResult(RebindMode.USE_EXISTING, packageName + "." + generatedClassName);
}
// Log
logger.log(TreeLogger.INFO, "Start generate files ... ", null);
// No, there is non. Create a new one.
SourceWriter sourceWriter = getSourceWriter(logger, context, module, packageName, generatedClassName);
if (sourceWriter != null) {
logger.log(TreeLogger.INFO, "Generating source for " + generatedClassQualifiedName + " ", null);
Mvp4gConfigurationFileWriter writer = new Mvp4gConfigurationFileWriter(sourceWriter, configuration);
writer.writeConf();
sourceWriter.commit(logger);
} else {
// don't expect this to occur, but could happen if an instance was
// recently generated but not yet committed
new RebindResult(RebindMode.USE_EXISTING, generatedClassQualifiedName);
}
Date end = new Date();
logger.log(TreeLogger.INFO, "Mvp4g Compilation: " + (end.getTime() - start.getTime()) + "ms.");
return new RebindResult(RebindMode.USE_ALL_NEW_WITH_NO_CACHING, packageName + "." + generatedClassName);
} catch (InvalidMvp4gConfigurationException e) {
logger.log(TreeLogger.ERROR, e.getMessage(), e);
throw new UnableToCompleteException();
}
}
use of com.google.gwt.core.ext.RebindResult in project mvp4g by mvp4g.
the class Mvp4gRunAsyncGenerator method create.
private RebindResult create(JClassType originalType, TreeLogger logger, GeneratorContext context, String typeName) throws UnableToCompleteException {
Date start = new Date();
String packageName = originalType.getPackage().getName();
String originalClassName = originalType.getSimpleSourceName();
String generatedClassName = originalClassName + "Impl";
String generatedClassQualifiedName = packageName + "." + generatedClassName;
// check weather there is a usual version or not.
if (checkAlreadyGenerated(logger, context, generatedClassQualifiedName)) {
// Log
logger.log(TreeLogger.INFO, "reuse already generated files", null);
// stop generating
return new RebindResult(RebindMode.USE_EXISTING, generatedClassQualifiedName);
}
logger.log(TreeLogger.INFO, "Generating writer for " + packageName + "." + generatedClassName, null);
PrintWriter printWriter = context.tryCreate(logger, packageName, generatedClassName);
ClassSourceFileComposerFactory classFactory = new ClassSourceFileComposerFactory(packageName, generatedClassName);
classFactory.addImplementedInterface(originalType.getName());
String[] classesToImport = getClassesToImport();
for (String classToImport : classesToImport) {
classFactory.addImport(classToImport);
}
if (printWriter != null) {
SourceWriter sourceWriter = classFactory.createSourceWriter(context, printWriter);
logger.log(TreeLogger.INFO, "Generating source for " + generatedClassQualifiedName + " ", null);
writeClass(sourceWriter, getRunAsync(originalType));
sourceWriter.commit(logger);
}
Date end = new Date();
logger.log(TreeLogger.INFO, "Mvp4g Module Cretor: " + (end.getTime() - start.getTime()) + "ms.");
return new RebindResult(RebindMode.USE_ALL_NEW_WITH_NO_CACHING, generatedClassQualifiedName);
}
Aggregations