use of com.github.mvp4g.mvp4g2.processor.model.EventBusMetaModel in project mvp4g2 by mvp4g.
the class EventBusAnnotationScanner method scan.
public EventBusMetaModel scan(RoundEnvironment roundEnvironment) throws ProcessorException {
// First we try to read an already created resource ...
EventBusMetaModel model = this.restore();
// Check if we have an element annotated with @Application
if (!roundEnvironment.getElementsAnnotatedWith(EventBus.class).isEmpty()) {
// create validator
EventBusAnnotationValidator eventBusValidaitor = EventBusAnnotationValidator.builder().roundEnvironment(roundEnvironment).processingEnvironment(processingEnvironment).build();
// check, whether we have o do something ...
eventBusValidaitor.validate();
// should only be one, so we can search for the first! ...
Optional<? extends Element> optionalElement = this.roundEnvironment.getElementsAnnotatedWith(EventBus.class).stream().findFirst();
if (optionalElement.isPresent()) {
Element eventBusAnnotationElement = optionalElement.get();
eventBusValidaitor.validate(eventBusAnnotationElement);
EventBus eventBusAnnotation = eventBusAnnotationElement.getAnnotation(EventBus.class);
if (!isNull(eventBusAnnotation)) {
TypeElement shellTypeElement = this.getShellTypeElement(eventBusAnnotation);
model = new EventBusMetaModel(eventBusAnnotationElement.toString(), isNull(shellTypeElement) ? "" : shellTypeElement.toString());
// Debug-Annotation
model = DebugAnnotationScanner.builder().processingEnvironment(processingEnvironment).eventBusTypeElement((TypeElement) eventBusAnnotationElement).eventBusMetaModel(model).build().scan(roundEnvironment);
// Filters-Annotation
model = FiltersAnnotationScanner.builder().processingEnvironment(processingEnvironment).eventBusTypeElement((TypeElement) eventBusAnnotationElement).eventBusMetaModel(model).build().scan(roundEnvironment);
// handle Event-annotation
model = EventAnnotationScanner.builder().processingEnvironment(processingEnvironment).eventBusTypeElement((TypeElement) eventBusAnnotationElement).eventBusMetaModel(model).build().scan(roundEnvironment);
// let's store the updated model
this.processorUtils.store(model, this.createRelativeFileName());
}
}
} else {
// @Debug annotation with no @EventBus annotation ... bad idea!
Optional<? extends Element> optionalDebugElement = this.roundEnvironment.getElementsAnnotatedWith(Debug.class).stream().findFirst();
if (optionalDebugElement.isPresent()) {
EventBus eventBusAnnotation = optionalDebugElement.get().getAnnotation(EventBus.class);
if (eventBusAnnotation == null) {
throw new ProcessorException(((TypeElement) optionalDebugElement.get()).getQualifiedName().toString() + " -> @Debug can only be used with an interfaces annotated with @EventBus");
}
}
// @Filters annotation with no @EventBus annotation ... bad idea!
Optional<? extends Element> optionalFiltersElement = this.roundEnvironment.getElementsAnnotatedWith(Filters.class).stream().findFirst();
if (optionalFiltersElement.isPresent()) {
EventBus eventBusAnnotation = optionalFiltersElement.get().getAnnotation(EventBus.class);
if (eventBusAnnotation == null) {
throw new ProcessorException(((TypeElement) optionalFiltersElement.get()).getQualifiedName().toString() + " -> @Filters can only be used with an interfaces annotated with @EventBus");
}
}
}
return model;
}
use of com.github.mvp4g.mvp4g2.processor.model.EventBusMetaModel in project mvp4g2 by mvp4g.
the class EventBusAnnotationScanner method restore.
private EventBusMetaModel restore() {
Properties props = new Properties();
try {
FileObject resource = this.processingEnvironment.getFiler().getResource(StandardLocation.CLASS_OUTPUT, "", this.createRelativeFileName());
props.load(resource.openInputStream());
EventBusMetaModel model = new EventBusMetaModel(props);
List<EventMetaModel> eventModels = new ArrayList<>();
for (String eventInternalName : model.getEvents()) {
FileObject resourceEvent = this.processingEnvironment.getFiler().getResource(StandardLocation.CLASS_OUTPUT, "", this.createRelativeEventModelFileName(eventInternalName));
props.load(resourceEvent.openInputStream());
eventModels.add(new EventMetaModel(props));
}
eventModels.forEach(model::add);
return model;
} 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.EventBusMetaModel in project mvp4g2 by mvp4g.
the class FiltersAnnotationScanner method scan.
public EventBusMetaModel scan(RoundEnvironment roundEnvironment) throws ProcessorException {
// do validation
FilterAnnotationValidator.builder().roundEnvironment(roundEnvironment).processingEnvironment(processingEnvironment).eventBusTypeElement(this.eventBusTypeElement).build().validate();
// handle filters-annotation
Filters filtersAnnotation = eventBusTypeElement.getAnnotation(Filters.class);
if (isNull(filtersAnnotation)) {
this.eventBusMetaModel.setHasFiltersAnnotation("false");
} else {
this.eventBusMetaModel.setHasFiltersAnnotation("true");
this.eventBusMetaModel.setFilters(this.getEventFiltersAsList(eventBusTypeElement));
}
return this.eventBusMetaModel;
}
Aggregations