use of com.github.mvp4g.mvp4g2.core.history.annotation.NotFoundHistory in project mvp4g2 by mvp4g.
the class EventTest method testEventBusWithOneNotFoundHistoryAnnotationAndNonZeroArgmentsSignature.
@Test
public void testEventBusWithOneNotFoundHistoryAnnotationAndNonZeroArgmentsSignature() {
Compilation compilation = javac().withProcessors(new Mvp4g2Processor()).compile(new ArrayList<JavaFileObject>() {
{
add(JavaFileObjects.forResource("com/github/mvp4g/mvp4g2/processor/event/eventBusWithOneNotFoundHistoryAnnotationAndNonZeroArgmentsSignature/EventBusWithOneNotFoundHistoryAnnotationAndNonZeroArgmentsSignature.java"));
add(JavaFileObjects.forResource("com/github/mvp4g/mvp4g2/processor/event/eventBusWithOneNotFoundHistoryAnnotationAndNonZeroArgmentsSignature/MockShellPresenter.java"));
}
});
CompilationSubject.assertThat(compilation).failed();
CompilationSubject.assertThat(compilation).hadErrorContaining("@NotFoundHistory can only be used on a method with no arguments");
}
use of com.github.mvp4g.mvp4g2.core.history.annotation.NotFoundHistory in project mvp4g2 by mvp4g.
the class EventTest method testEventBusWithMoreThanOnNotFoundHistoryAnnodation.
@Test
public void testEventBusWithMoreThanOnNotFoundHistoryAnnodation() {
Compilation compilation = javac().withProcessors(new Mvp4g2Processor()).compile(new ArrayList<JavaFileObject>() {
{
add(JavaFileObjects.forResource("com/github/mvp4g/mvp4g2/processor/event/eventBusWithMoreThanOnNotFoundHistoryAnnodation/EventBusWithMoreThanOnNotFoundHistoryAnnodation.java"));
add(JavaFileObjects.forResource("com/github/mvp4g/mvp4g2/processor/event/eventBusWithMoreThanOnNotFoundHistoryAnnodation/MockShellPresenter.java"));
}
});
CompilationSubject.assertThat(compilation).failed();
CompilationSubject.assertThat(compilation).hadErrorContaining("@NotFoundHistory can only be set a single time inside a event bus");
}
use of com.github.mvp4g.mvp4g2.core.history.annotation.NotFoundHistory in project mvp4g2 by mvp4g.
the class EventAnnotationValidator method validate.
public void validate() throws ProcessorException {
// check if all historyNames are unique!
List<String> historyNames = new ArrayList<>();
for (Element element : this.roundEnvironment.getElementsAnnotatedWith(Event.class)) {
Event eventAnnotation = element.getAnnotation(Event.class);
// check, that the parent element extends IsEventBus
if (!this.processorUtils.extendsClassOrInterface(this.processingEnvironment.getTypeUtils(), element.getEnclosingElement().asType(), this.processingEnvironment.getElementUtils().getTypeElement(IsEventBus.class.getCanonicalName()).asType())) {
throw new ProcessorException("Mvp4g2Processor: @Event can only be used inside a event bus! >>" + element.getEnclosingElement().toString() + "<< does no implement IsEventBus");
}
if (!Event.DEFAULT_HISTORY_NAME.equals(eventAnnotation.historyName())) {
if (historyNames.contains(eventAnnotation.historyName())) {
throw new ProcessorException("Mvp4g2Processor: EventElement: >>" + element.getSimpleName().toString() + "<< using a already used historyName -> >>" + eventAnnotation.historyName() + "<<");
} else {
historyNames.add(eventAnnotation.historyName());
}
}
ExecutableElement eventExecutableElement = (ExecutableElement) element;
if (!"void".equals(eventExecutableElement.getReturnType().toString())) {
throw new ProcessorException("Mvp4g2Processor: EventElement: >>" + element.getSimpleName().toString() + "<< must return 'void'");
}
}
// check, if there are more than one InitHistory-annotation!
if (this.roundEnvironment.getElementsAnnotatedWith(InitHistory.class).size() > 1) {
throw new ProcessorException("Mvp4g2Processor: @InitHistory can only be set a single time inside a event bus");
} else if (this.roundEnvironment.getElementsAnnotatedWith(InitHistory.class).size() == 1) {
for (Element element : this.roundEnvironment.getElementsAnnotatedWith(InitHistory.class)) {
ExecutableElement executableElement = (ExecutableElement) element;
if (((ExecutableElement) element).getParameters().size() > 0) {
throw new ProcessorException("Mvp4g2Processor: @InitHistory can only be used on a method with no arguments");
}
}
}
// check, if there are more than one NotFoundHistory-annotation!
if (this.roundEnvironment.getElementsAnnotatedWith(NotFoundHistory.class).size() > 1) {
throw new ProcessorException("Mvp4g2Processor: @NotFoundHistory can only be set a single time inside a event bus");
} else if (this.roundEnvironment.getElementsAnnotatedWith(NotFoundHistory.class).size() == 1) {
for (Element element : this.roundEnvironment.getElementsAnnotatedWith(NotFoundHistory.class)) {
ExecutableElement executableElement = (ExecutableElement) element;
if (((ExecutableElement) element).getParameters().size() > 0) {
throw new ProcessorException("Mvp4g2Processor: @NotFoundHistory can only be used on a method with no arguments");
}
}
}
}
Aggregations