use of com.github.mvp4g.mvp4g2.processor.model.ApplicationMetaModel in project mvp4g2 by mvp4g.
the class ApplicationAnnotationScanner method scan.
public ApplicationMetaModel scan(RoundEnvironment roundEnvironment) throws ProcessorException {
// First we try to read an already created resource ...
ApplicationMetaModel model = this.restore();
// Check if we have an element annotated with @Application
if (!roundEnvironment.getElementsAnnotatedWith(Application.class).isEmpty()) {
// check, whether we have o do something ...
ApplicationAnnotationValidator validator = ApplicationAnnotationValidator.builder().roundEnvironment(roundEnvironment).processingEnvironment(this.processingEnvironment).build();
validator.validate();
// should only be one, so we can search for the first! ...
Optional<? extends Element> optionalElement = this.roundEnvironment.getElementsAnnotatedWith(Application.class).stream().findFirst();
if (optionalElement.isPresent()) {
Element applicationAnnotationElement = optionalElement.get();
validator.validate(applicationAnnotationElement);
Application applicationAnnotation = applicationAnnotationElement.getAnnotation(Application.class);
if (!isNull(applicationAnnotation)) {
TypeElement eventBusTypeElement = this.getEventBusTypeElement(applicationAnnotation);
TypeElement applicationLoaderTypeElement = this.getApplicationLoaderTypeElement(applicationAnnotation);
model = new ApplicationMetaModel(applicationAnnotationElement.toString(), isNull(eventBusTypeElement) ? "" : eventBusTypeElement.toString(), isNull(applicationLoaderTypeElement) ? "" : applicationLoaderTypeElement.toString(), String.valueOf(applicationAnnotation.historyOnStart()));
// let's store the updated model
this.processorUtils.store(model, this.createRelativeFileName());
}
}
}
return model;
}
use of com.github.mvp4g.mvp4g2.processor.model.ApplicationMetaModel in project mvp4g2 by mvp4g.
the class ApplicationAnnotationScanner method restore.
private ApplicationMetaModel restore() {
Properties props = new Properties();
try {
FileObject resource = this.processingEnvironment.getFiler().getResource(StandardLocation.CLASS_OUTPUT, "", this.createRelativeFileName());
props.load(resource.openInputStream());
return new ApplicationMetaModel(props);
} catch (IOException e) {
// every thing is ok -> no operation
// this.processorUtils.createNoteMessage("no resource found for : >>" + this.createRelativeFileName() + "<<");
}
return null;
}
use of com.github.mvp4g.mvp4g2.processor.model.ApplicationMetaModel in project mvp4g2 by mvp4g.
the class ApplicationGenerator method generate.
public void generate(ApplicationMetaModel metaModel) throws ProcessorException {
// check if element is existing (to avoid generating code for deleted items)
if (!this.processorUtils.doesExist(metaModel.getApplication())) {
return;
}
// generate code
TypeSpec.Builder typeSpec = TypeSpec.classBuilder(metaModel.getApplication().getSimpleName() + ApplicationGenerator.IMPL_NAME).superclass(ParameterizedTypeName.get(ClassName.get(AbstractApplication.class), metaModel.getEventBus().getTypeName())).addModifiers(Modifier.PUBLIC, Modifier.FINAL).addSuperinterface(metaModel.getApplication().getTypeName());
// constructor ...
MethodSpec constructor = MethodSpec.constructorBuilder().addModifiers(Modifier.PUBLIC).addStatement("super()").addStatement("super.eventBus = new $N.$N()", metaModel.getEventBus().getPackage(), metaModel.getEventBus().getSimpleName() + ApplicationGenerator.IMPL_NAME).addStatement("super.historyOnStart = $L", metaModel.getHistoryOnStart()).build();
typeSpec.addMethod(constructor);
// method "getApplicaitonLoader"
MethodSpec getApplicaitonLaoderMethod = MethodSpec.methodBuilder("getApplicationLoader").addModifiers(Modifier.PUBLIC).addAnnotation(Override.class).returns(IsApplicationLoader.class).addStatement("return new $T()", metaModel.getLoader().getTypeName()).build();
typeSpec.addMethod(getApplicaitonLaoderMethod);
JavaFile javaFile = JavaFile.builder(metaModel.getEventBus().getPackage(), typeSpec.build()).build();
try {
javaFile.writeTo(this.processingEnvironment.getFiler());
} catch (IOException e) {
throw new ProcessorException("Unable to write generated file: >>" + metaModel.getEventBus().getSimpleName() + ApplicationGenerator.IMPL_NAME + "<< -> exception: " + e.getMessage());
}
}
use of com.github.mvp4g.mvp4g2.processor.model.ApplicationMetaModel in project mvp4g2 by mvp4g.
the class PropertiesTest method testApplicationMetaModel.
@Test
public void testApplicationMetaModel() {
Properties properties = new Properties();
try {
properties.load(ClassLoader.getSystemResourceAsStream("META-INF" + File.separator + "mvp4g2" + File.separator + "application.properties"));
} catch (IOException e) {
assert false : "IOException reading application.properties";
}
ApplicationMetaModel metaModel = new ApplicationMetaModel(properties);
Properties newProperties = metaModel.createPropertes();
assertEquals(properties, newProperties);
}
Aggregations