use of com.github.mvp4g.mvp4g2.processor.model.HandlerMetaModel in project mvp4g2 by mvp4g.
the class EventBusGenerator method generate.
public void generate(EventBusMetaModel eventBusMetaMetaModel, HandlerMetaModel handlerMetaModel, PresenterMetaModel presenterMetaModel, HistoryMetaModel historyMetaModel) throws ProcessorException {
// check if element is existing (to avoid generating code for deleted items)
if (!this.processorUtils.doesExist(eventBusMetaMetaModel.getEventBus())) {
return;
}
ClassName abstractEventBusClassName = ClassName.get(AbstractEventBus.class);
TypeSpec.Builder typeSpec = TypeSpec.classBuilder(eventBusMetaMetaModel.getEventBus().getSimpleName() + EventBusGenerator.IMPL_NAME).superclass(ParameterizedTypeName.get(abstractEventBusClassName, eventBusMetaMetaModel.getEventBus().getTypeName())).addModifiers(Modifier.PUBLIC, Modifier.FINAL).addSuperinterface(eventBusMetaMetaModel.getEventBus().getTypeName());
MethodSpec constructor = MethodSpec.constructorBuilder().addModifiers(Modifier.PUBLIC).addStatement("super($S)", eventBusMetaMetaModel.getShell().getClassName()).build();
typeSpec.addMethod(constructor);
DebugGenerator.builder().eventBusMetaModel(eventBusMetaMetaModel).typeSpec(typeSpec).build().generate();
FilterGenerator.builder().eventBusMetaModel(eventBusMetaMetaModel).typeSpec(typeSpec).build().generate();
EventLoadMetaDataGenerator.builder().processingEnvironment(this.processingEnvironment).eventBusMetaModel(eventBusMetaMetaModel).typeSpec(typeSpec).build().generate();
EventMetaDataGenerator.builder().processingEnvironment(this.processingEnvironment).eventBusMetaModel(eventBusMetaMetaModel).build().generate();
EventHandlingMethodGenerator.builder().processorUtils(this.processorUtils).typeSpec(typeSpec).eventBusMetaModel(eventBusMetaMetaModel).historyMetaModel(historyMetaModel).presenterMetaModel(presenterMetaModel).handlerMetaModel(handlerMetaModel).build().generate();
AddPresenterGenerator.builder().typeSpec(typeSpec).processingEnvironment(this.processingEnvironment).presenterMetaModel(presenterMetaModel).build().generate();
HandlerAndPresenterRegristrationGenerator.builder().processingEnvironment(this.processingEnvironment).typeSpec(typeSpec).eventBusMetaModel(eventBusMetaMetaModel).presenterMetaModel(presenterMetaModel).handlerMetaModel(handlerMetaModel).build().generate();
JavaFile javaFile = JavaFile.builder(eventBusMetaMetaModel.getEventBus().getPackage(), typeSpec.build()).build();
// System.out.println(javaFile.toString());
try {
javaFile.writeTo(this.processingEnvironment.getFiler());
} catch (IOException e) {
throw new ProcessorException("Unable to write generated file: >>" + eventBusMetaMetaModel.getEventBus().getSimpleName() + EventBusGenerator.IMPL_NAME + "<< -> exception: " + e.getMessage());
}
}
use of com.github.mvp4g.mvp4g2.processor.model.HandlerMetaModel in project mvp4g2 by mvp4g.
the class HandlerGenerator method generate.
public void generate(HandlerMetaModel metaModel) throws ProcessorException {
ClassName eventHandlerMetaDataClassName = ClassName.get(HandlerMetaData.class);
ClassName eventHandlerMetaDataKindClassName = ClassName.get(HandlerMetaData.Kind.class);
for (String eventHandler : metaModel.getHandlerKeys()) {
// check if element is existing (to avoid generating code for deleted items)
if (this.processorUtils.doesExist(new ClassNameModel(eventHandler))) {
HandlerMetaModel.HandlerData data = metaModel.getHandlerData(eventHandler);
String className = this.processorUtils.createFullClassName(data.getHandler().getPackage(), data.getHandler().getSimpleName() + ProcessorConstants.META_DATA);
TypeSpec.Builder typeSpec = TypeSpec.classBuilder(this.processorUtils.setFirstCharacterToUpperCase(className)).superclass(ParameterizedTypeName.get(eventHandlerMetaDataClassName, data.getHandler().getTypeName())).addModifiers(Modifier.PUBLIC, Modifier.FINAL);
// constructor ...
MethodSpec.Builder constructor = MethodSpec.constructorBuilder().addModifiers(Modifier.PUBLIC).addStatement("super($S, $T.EVENT_HANDLER, new $T())", data.getHandler().getClassName(), eventHandlerMetaDataKindClassName, data.getHandler().getTypeName());
typeSpec.addMethod(constructor.build());
JavaFile javaFile = JavaFile.builder(data.getHandler().getPackage(), typeSpec.build()).build();
try {
javaFile.writeTo(this.processingEnvironment.getFiler());
} catch (IOException e) {
throw new ProcessorException("Unable to write generated file: >>" + data.getHandler().getSimpleName() + ProcessorConstants.META_DATA + "<< -> exception: " + e.getMessage());
}
}
}
}
use of com.github.mvp4g.mvp4g2.processor.model.HandlerMetaModel in project mvp4g2 by mvp4g.
the class HandlerAnnotationScanner method scan.
public HandlerMetaModel scan(RoundEnvironment roundEnvironment) throws ProcessorException {
// Validator
HandlerAnnotationValidator validator = HandlerAnnotationValidator.builder().roundEnvironment(roundEnvironment).processingEnvironment(processingEnvironment).build();
// read all already created model
HandlerMetaModel model = this.restore();
for (Element element : roundEnvironment.getElementsAnnotatedWith(Handler.class)) {
TypeElement typeElement = (TypeElement) element;
// validate the element. In case of error throw exception!
validator.validate(typeElement);
// update model
model.add(((TypeElement) element).getQualifiedName().toString(), this.processorUtils.createHandledEventArray(typeElement));
}
// let's store the updated model
this.processorUtils.store(model, this.createRelativeFileName());
return model;
}
use of com.github.mvp4g.mvp4g2.processor.model.HandlerMetaModel in project mvp4g2 by mvp4g.
the class HandlerAnnotationScanner method restore.
private HandlerMetaModel restore() {
Properties props = new Properties();
try {
FileObject resource = this.processingEnvironment.getFiler().getResource(StandardLocation.CLASS_OUTPUT, "", this.createRelativeFileName());
props.load(resource.openInputStream());
return new HandlerMetaModel(props);
} catch (IOException e) {
// every thing is ok -> no operation
// this.processorUtils.createNoteMessage("no resource found for : >>" + this.createRelativeFileName() + "<<");
}
return new HandlerMetaModel();
}
use of com.github.mvp4g.mvp4g2.processor.model.HandlerMetaModel in project mvp4g2 by mvp4g.
the class PropertiesTest method testHandlerMetaModel.
@Test
public void testHandlerMetaModel() {
Properties properties = new Properties();
try {
properties.load(ClassLoader.getSystemResourceAsStream("META-INF" + File.separator + "mvp4g2" + File.separator + "handler.properties"));
} catch (IOException e) {
assert false : "IOException reading handler.properties";
}
HandlerMetaModel metaModel = new HandlerMetaModel(properties);
Properties newProperties = metaModel.createPropertes();
assertEquals(properties, newProperties);
}
Aggregations