use of com.github.mvp4g.mvp4g2.core.history.annotation.History in project mvp4g2 by mvp4g.
the class HistoryTest method testHistoryAnnotationOnAClassWhichDoesNotExtendsIsHistoryConverter.
@Test
public void testHistoryAnnotationOnAClassWhichDoesNotExtendsIsHistoryConverter() {
Compilation compilation = javac().withProcessors(new Mvp4g2Processor()).compile(new ArrayList<JavaFileObject>() {
{
add(JavaFileObjects.forResource("com/github/mvp4g/mvp4g2/processor/history/historyAnnotationOnAClassWhichDoesNotExtendsIsHistoryConverter/HistoryAnnotationOnAClassWhichDoesNotExtendsIsHistoryConverter.java"));
}
});
CompilationSubject.assertThat(compilation).failed();
CompilationSubject.assertThat(compilation).hadErrorContaining("a class annotated with @History must extend IsHistoryConverter.class!");
}
use of com.github.mvp4g.mvp4g2.core.history.annotation.History 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.history.annotation.History in project mvp4g2 by mvp4g.
the class HistoryTest method testHistoryAnnoationOnAInterface.
@Test
public void testHistoryAnnoationOnAInterface() {
Compilation compilation = javac().withProcessors(new Mvp4g2Processor()).compile(new ArrayList<JavaFileObject>() {
{
add(JavaFileObjects.forResource("com/github/mvp4g/mvp4g2/processor/history/historyAnnotationOnAInterface/HistoryAnnoationOnAInterface.java"));
}
});
CompilationSubject.assertThat(compilation).failed();
CompilationSubject.assertThat(compilation).hadErrorContaining("@History can only be used with a class!");
}
use of com.github.mvp4g.mvp4g2.core.history.annotation.History 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