use of com.github.mvp4g.mvp4g2.core.application.annotation.Application in project mvp4g2 by mvp4g.
the class HistoryAnnotationScanner method scan.
public HistoryMetaModel scan(RoundEnvironment roundEnvironment) throws ProcessorException {
// First we try to read an already created resource ...
HistoryMetaModel model = this.restore();
// Check if we have an element annotated with @Application
if (!roundEnvironment.getElementsAnnotatedWith(History.class).isEmpty()) {
// check annotation ...
HistoryAnnotationValidator validator = HistoryAnnotationValidator.builder().roundEnvironment(roundEnvironment).processingEnvironment(this.processingEnvironment).build();
// iterate over all history converters
for (Element element : roundEnvironment.getElementsAnnotatedWith(History.class)) {
// validate
validator.validate(element);
// process ...
TypeElement typeElement = (TypeElement) element;
History historyAnnotation = typeElement.getAnnotation(History.class);
validator.validate(element);
model.add(typeElement.getQualifiedName().toString(), historyAnnotation.type().toString());
}
// let's store the updated model
this.processorUtils.store(model, this.createRelativeFileName());
}
return model;
}
use of com.github.mvp4g.mvp4g2.core.application.annotation.Application 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()), String.valueOf(applicationAnnotation.encodeToken()));
// let's store the updated model
this.processorUtils.store(model, this.createRelativeFileName());
}
}
}
return model;
}
use of com.github.mvp4g.mvp4g2.core.application.annotation.Application 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.core.application.annotation.Application in project mvp4g2 by mvp4g.
the class FilterAnnotationValidator method validate.
public void validate() throws ProcessorException {
// get elements annotated with EventBus annotation
Set<? extends Element> elementsWithFilterAnnotation = this.roundEnvironment.getElementsAnnotatedWith(Filters.class);
// at least there should only one Application annotation!
if (elementsWithFilterAnnotation.size() > 1) {
throw new ProcessorException("Mvp4g2Processor: There should be at least only one interface, that is annotated with @Filter");
}
// annotated element has to be a interface
for (Element element : elementsWithFilterAnnotation) {
if (element instanceof TypeElement) {
TypeElement typeElement = (TypeElement) element;
if (!typeElement.getKind().isInterface()) {
throw new ProcessorException("Mvp4g2Processor: @Filter can only be used with an interface");
}
// @Filter can only be used on a interface that extends IsEventBus
if (!this.processorUtils.extendsClassOrInterface(this.processingEnvironment.getTypeUtils(), typeElement.asType(), this.processingEnvironment.getElementUtils().getTypeElement(IsEventBus.class.getCanonicalName()).asType())) {
throw new ProcessorException("Mvp4g2Processor: @Filter can only be used on interfaces that extends IsEventBus");
}
// test, that all filters implement IsEventFilter!
List<String> eventFilterAsStringList = this.getEventFiltersAsList(eventBusTypeElement);
for (String eventFilterClassname : eventFilterAsStringList) {
TypeElement filterElement = this.processingEnvironment.getElementUtils().getTypeElement(eventFilterClassname);
if (!this.processorUtils.extendsClassOrInterface(this.processingEnvironment.getTypeUtils(), filterElement.asType(), this.processingEnvironment.getElementUtils().getTypeElement(IsEventFilter.class.getCanonicalName()).asType())) {
throw new ProcessorException("Mvp4g2Processor: @Filter - the filters attribute needs class that implements IsEventFilter");
}
}
} else {
throw new ProcessorException("Mvp4g2Processor: @Filter can only be used on a type (interface)");
}
}
}
use of com.github.mvp4g.mvp4g2.core.application.annotation.Application in project mvp4g2 by mvp4g.
the class ApplicationTest method testApplicationAnnotationOkWithoutLoaderAsInnerInterface.
@Test
public void testApplicationAnnotationOkWithoutLoaderAsInnerInterface() {
Compilation compilation = javac().withProcessors(new Mvp4g2Processor()).compile(new ArrayList<JavaFileObject>() {
{
add(JavaFileObjects.forResource("com/github/mvp4g/mvp4g2/processor/application/applicationAnnotationOkWithoutLoaderAsInnerInterface/ApplicationAnnotationOkWithoutLoaderAsInnerInterface.java"));
add(JavaFileObjects.forResource("com/github/mvp4g/mvp4g2/processor/application/applicationAnnotationOkWithoutLoaderAsInnerInterface/MockEventBus.java"));
add(JavaFileObjects.forResource("com/github/mvp4g/mvp4g2/processor/application/applicationAnnotationOkWithoutLoaderAsInnerInterface/MockOneEventHandler.java"));
add(JavaFileObjects.forResource("com/github/mvp4g/mvp4g2/processor/application/applicationAnnotationOkWithoutLoaderAsInnerInterface/MockShellPresenter.java"));
}
});
CompilationSubject.assertThat(compilation).succeeded();
JavaFileObjectSubject.assertThat(JavaFileObjects.forResource("com/github/mvp4g/mvp4g2/processor/application/applicationAnnotationOkWithoutLoaderAsInnerInterface/MyApplicationImpl.java")).hasSourceEquivalentTo(JavaFileObjects.forResource("com/github/mvp4g/mvp4g2/processor/application/applicationAnnotationOkWithoutLoaderAsInnerInterface/MyApplicationImpl.java"));
}
Aggregations