use of com.github.mvp4g.mvp4g2.processor.Mvp4g2Processor 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.processor.Mvp4g2Processor in project mvp4g2 by mvp4g.
the class ShellTest method eventBusWithOneShells.
@Test
public void eventBusWithOneShells() {
Compilation compilation = javac().withProcessors(new Mvp4g2Processor()).compile(new ArrayList<JavaFileObject>() {
{
add(JavaFileObjects.forResource("com/github/mvp4g/mvp4g2/processor/shell/eventBusWithOneShell/EventBusWithOneShell.java"));
add(JavaFileObjects.forResource("com/github/mvp4g/mvp4g2/processor/shell/eventBusWithOneShell/IMockShellView01.java"));
add(JavaFileObjects.forResource("com/github/mvp4g/mvp4g2/processor/shell/eventBusWithOneShell/MockShellView01.java"));
add(JavaFileObjects.forResource("com/github/mvp4g/mvp4g2/processor/shell/eventBusWithOneShell/MockShellPresenter01.java"));
add(JavaFileObjects.forResource("com/github/mvp4g/mvp4g2/processor/shell/eventBusWithOneShell/IMockShellView02.java"));
add(JavaFileObjects.forResource("com/github/mvp4g/mvp4g2/processor/shell/eventBusWithOneShell/MockShellView02.java"));
add(JavaFileObjects.forResource("com/github/mvp4g/mvp4g2/processor/shell/eventBusWithOneShell/MockShellPresenter02.java"));
}
});
CompilationSubject.assertThat(compilation).succeeded();
}
Aggregations