use of com.github.mvp4g.mvp4g2.processor.model.EventBusMetaModel in project mvp4g2 by mvp4g.
the class ImplementationTest method testOnlyApplicationData.
@Test
public void testOnlyApplicationData() {
Compilation compilation = javac().withProcessors(new Mvp4g2Processor()).compile(new ArrayList<JavaFileObject>() {
{
add(JavaFileObjects.forResource("com/github/mvp4g/mvp4g2/processor/implementation/testOnlyApplicationData/ApplicationAnnotation.java"));
}
});
CompilationSubject.assertThat(compilation).failed();
CompilationSubject.assertThat(compilation).hadErrorContaining("no EventBusMetaModel found! Did you forget to create an EventBus for mvp4g2 or forget to annotate the EventBus with @EventBus?");
}
use of com.github.mvp4g.mvp4g2.processor.model.EventBusMetaModel in project mvp4g2 by mvp4g.
the class DebugAnnotationScanner method scan.
public EventBusMetaModel scan(RoundEnvironment roundEnvironment) throws ProcessorException {
// do validation
DebugAnnotationValidator.builder().roundEnvironment(roundEnvironment).processingEnvironment(processingEnvironment).build().validate();
// handle debug-annotation
Debug debugAnnotation = eventBusTypeElement.getAnnotation(Debug.class);
if (!isNull(debugAnnotation)) {
this.eventBusMetaModel.setHasDebugAnnotation("true");
this.eventBusMetaModel.setDebugLogLevel(debugAnnotation.logLevel().toString());
if (!isNull(getLogger(debugAnnotation))) {
this.eventBusMetaModel.setDebugLogger(getLogger(debugAnnotation).getQualifiedName().toString());
}
} else {
this.eventBusMetaModel.setHasDebugAnnotation("false");
this.eventBusMetaModel.setDebugLogLevel("");
this.eventBusMetaModel.setDebugLogger("");
}
return this.eventBusMetaModel;
}
use of com.github.mvp4g.mvp4g2.processor.model.EventBusMetaModel 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.EventBusMetaModel in project mvp4g2 by mvp4g.
the class PropertiesTest method testEventBusMetaModel.
@Test
public void testEventBusMetaModel() {
Properties properties = new Properties();
try {
properties.load(ClassLoader.getSystemResourceAsStream("META-INF" + File.separator + "mvp4g2" + File.separator + "eventBus.properties"));
} catch (IOException e) {
assert false : "IOException reading eventBus.properties";
}
EventBusMetaModel metaModel = new EventBusMetaModel(properties);
for (String eventInternalName : properties.getProperty("events").split(",")) {
try {
Properties eventProperties = new Properties();
eventProperties.load(ClassLoader.getSystemResourceAsStream("META-INF" + File.separator + "mvp4g2" + File.separator + eventInternalName + ".properties"));
metaModel.add(new EventMetaModel(eventProperties));
} catch (IOException e) {
assert false : "IOException reading " + eventInternalName + ".properties";
}
}
Properties newProperties = metaModel.createPropertes();
assertEquals(properties, newProperties);
}
use of com.github.mvp4g.mvp4g2.processor.model.EventBusMetaModel in project mvp4g2 by mvp4g.
the class EventAnnotationScanner method scan.
public EventBusMetaModel scan(RoundEnvironment roundEnvironment) throws ProcessorException {
EventAnnotationValidator eventAnnotationValidator = EventAnnotationValidator.builder().roundEnvironment(roundEnvironment).processingEnvironment(processingEnvironment).eventBusMetaModel(this.eventBusMetaModel).eventBusTypeElement(eventBusTypeElement).build();
// validate event bus
eventAnnotationValidator.validate();
// handle events
for (Element element : roundEnvironment.getElementsAnnotatedWith(Event.class)) {
// do validation
EventAnnotationValidator.builder().roundEnvironment(roundEnvironment).processingEnvironment(processingEnvironment).eventBusMetaModel(this.eventBusMetaModel).eventBusTypeElement(eventBusTypeElement).build().validate(element);
ExecutableElement executableElement = (ExecutableElement) element;
// restore meta data (if there is one)
// First we try to read an already created resource ...
EventMetaModel model = this.restore(element);
// get event annoation
Event eventAnnotation = element.getAnnotation(Event.class);
// scan for data
// internal event name
model.setEventInternalName(this.processorUtils.createInternalEventName(executableElement));
// event name
model.setEventName(executableElement.getSimpleName().toString());
// history name of hte event
model.setHistoryEventName(eventAnnotation.historyName());
// navigation event
model.setNavigationEvent(Boolean.toString(eventAnnotation.navigationEvent()));
// passive
model.setPassive(Boolean.toString(eventAnnotation.passive()));
// handlers
model.setHandlers(this.getElementsFromAnnotationAsList(executableElement, "handlers"));
// List of binding handlers (full class names as String)
model.setBindings(this.getElementsFromAnnotationAsList(executableElement, "bind"));
// List of activate handlers (full class names as String)
model.setActivateHandlers(this.getElementsFromAnnotationAsList(executableElement, "activate"));
// List of deactivate handlers (full class names as String)
model.setDeactivateHandlers(this.getElementsFromAnnotationAsList(executableElement, "deactivate"));
// history converter
model.setHistoryConverter(Objects.requireNonNull(this.getHistoryConverterTypeElement(eventAnnotation)).getQualifiedName().toString());
// start event?
model.setStartEvent(isNull(executableElement.getAnnotation(Start.class)) ? "false" : "true");
// initHistory event?
model.setInitHistory(isNull(executableElement.getAnnotation(InitHistory.class)) ? "false" : "true");
// start event?
model.setNotFoundHistory(isNull(executableElement.getAnnotation(NotFoundHistory.class)) ? "false" : "true");
// parameters
executableElement.getParameters().forEach(v -> model.addParameter(v.getSimpleName().toString(), v.asType().toString()));
// let's store the updated model
this.processorUtils.store(model, this.createRelativeFileName(element));
// store the event meta data model in the eventbus meta data model
this.eventBusMetaModel.add(model);
}
return this.eventBusMetaModel;
}
Aggregations