use of com.mvp4g.rebind.config.Mvp4gConfiguration 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.mvp4g.rebind.config.Mvp4gConfiguration in project mvp4g by mvp4g.
the class AbstractMvp4gAnnotationLoaderTest method setUp.
@Before
public void setUp() {
GeneratorContextStub context = new GeneratorContextStub();
oracle = context.getTypeOracleStub();
configuration = new Mvp4gConfiguration(null, context);
loader = createLoader();
}
use of com.mvp4g.rebind.config.Mvp4gConfiguration in project mvp4g by mvp4g.
the class Mvp4gConfigurationFileReaderTest method setUp.
@Before
public void setUp() {
sourceWriter = new SourceWriterTestStub();
TreeLogger tl = new UnitTestTreeLogger.Builder().createLogger();
configuration = new Mvp4gConfiguration(tl, new GeneratorContextStub());
writer = new Mvp4gConfigurationFileWriter(sourceWriter, configuration);
String eventBusInterface = EventBus.class.getName();
String eventBusClass = BaseEventBus.class.getName();
configuration.setEventBus(new EventBusElement(eventBusInterface, eventBusClass, false));
ViewElement view = new ViewElement();
view.setClassName(Object.class.getName());
view.setName("startView");
configuration.getViews().add(view);
PresenterElement presenter = new PresenterElement();
presenter.setClassName(SimplePresenter01.class.getCanonicalName());
presenter.setName("startPresenter");
presenter.setView("startView");
configuration.getPresenters().add(presenter);
StartElement start = new StartElement();
start.setPresenter("startPresenter");
configuration.setStart(start);
GinModuleElement ginModule = new GinModuleElement();
ginModule.setModules(new String[] { DefaultMvp4gGinModule.class.getCanonicalName() });
configuration.setGinModule(ginModule);
TypeOracleStub oracle = (TypeOracleStub) configuration.getOracle();
configuration.setModule(oracle.addClass(Mvp4gModule.class));
}
use of com.mvp4g.rebind.config.Mvp4gConfiguration in project mvp4g by mvp4g.
the class EventsAnnotationsLoaderTest method setUp.
@Before
public void setUp() {
GeneratorContextStub context = new GeneratorContextStub();
oracle = context.getTypeOracleStub();
configuration = new Mvp4gConfiguration(null, context);
configuration.setModule(oracle.addClass(Mvp4gModule.class));
loader = new EventsAnnotationsLoader();
}
Aggregations