use of com.github.mvp4g.mvp4g2.core.eventbus.annotation.Debug in project mvp4g2 by mvp4g.
the class DebugTest method testDebugAnnotationOnAMethod.
@Test
public void testDebugAnnotationOnAMethod() {
Compilation compilation = javac().withProcessors(new Mvp4g2Processor()).compile(new ArrayList<JavaFileObject>() {
{
add(JavaFileObjects.forResource("com/github/mvp4g/mvp4g2/processor/eventbus/debugAnnotationOnAMethod/DebugAnnotationOnAMethod.java"));
}
});
CompilationSubject.assertThat(compilation).failed();
CompilationSubject.assertThat(compilation).hadErrorContaining("@Debug can only be used on a type (interface)");
}
use of com.github.mvp4g.mvp4g2.core.eventbus.annotation.Debug in project mvp4g2 by mvp4g.
the class DebugTest method testDebugAnnotationOnAClass.
@Test
public void testDebugAnnotationOnAClass() {
Compilation compilation = javac().withProcessors(new Mvp4g2Processor()).compile(new ArrayList<JavaFileObject>() {
{
add(JavaFileObjects.forResource("com/github/mvp4g/mvp4g2/processor/eventbus/debugAnnotationOnAClass/DebugAnnotationOnAClass.java"));
}
});
CompilationSubject.assertThat(compilation).failed();
CompilationSubject.assertThat(compilation).hadErrorContaining("@Debug can only be used on a type (interface)");
}
use of com.github.mvp4g.mvp4g2.core.eventbus.annotation.Debug in project mvp4g2 by mvp4g.
the class DebugAnnotationScanner method scan.
public EventBusMetaModel scan(RoundEnvironment roundEnvironment) throws ProcessorException {
// do validation
DebugAnnotationValidator.builder().roundEnvironment(roundEnvironment).processingEnvironment(processingEnvironment).build().validate();
// handle debug-annotation
Debug debugAnnotation = eventBusTypeElement.getAnnotation(Debug.class);
if (!isNull(debugAnnotation)) {
this.eventBusMetaModel.setHasDebugAnnotation("true");
this.eventBusMetaModel.setDebugLogLevel(debugAnnotation.logLevel().toString());
if (!isNull(getLogger(debugAnnotation))) {
this.eventBusMetaModel.setDebugLogger(getLogger(debugAnnotation).getQualifiedName().toString());
}
} else {
this.eventBusMetaModel.setHasDebugAnnotation("false");
this.eventBusMetaModel.setDebugLogLevel("");
this.eventBusMetaModel.setDebugLogger("");
}
return this.eventBusMetaModel;
}
use of com.github.mvp4g.mvp4g2.core.eventbus.annotation.Debug in project mvp4g2 by mvp4g.
the class DebugAnnotationValidator method validate.
public void validate() throws ProcessorException {
// get elements annotated with Debug annotation
Set<? extends Element> elementsWithDebugAnnotation = this.roundEnvironment.getElementsAnnotatedWith(Debug.class);
// at least there should only one Application annotation!
if (elementsWithDebugAnnotation.size() > 1) {
throw new ProcessorException("There should be at least only one interface, that is annotated with @Debug");
}
for (Element element : elementsWithDebugAnnotation) {
if (element instanceof TypeElement) {
TypeElement typeElement = (TypeElement) element;
// @Debug can only be used on a interface
if (!typeElement.getKind().isInterface()) {
throw new ProcessorException("@Debug can only be used with an interface");
}
// @Debug 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("@Debug can only be used on interfaces that extends IsEventBus");
}
// the loggerinside the annotation must extends IsMvp4g2Logger!
TypeElement loggerElement = this.getLogger(typeElement.getAnnotation(Debug.class));
if (!this.processorUtils.extendsClassOrInterface(this.processingEnvironment.getTypeUtils(), loggerElement.asType(), this.processingEnvironment.getElementUtils().getTypeElement(IsMvp4g2Logger.class.getCanonicalName()).asType())) {
throw new ProcessorException("@Debug - the logger attribute needs class that extends IsMvp4g2Logger");
}
} else {
throw new ProcessorException("@Debug can only be used on a type (interface)");
}
}
}
use of com.github.mvp4g.mvp4g2.core.eventbus.annotation.Debug in project mvp4g2 by mvp4g.
the class DebugTest method testDebugAnnotationWithoutExtendsIsEventBus.
@Test
public void testDebugAnnotationWithoutExtendsIsEventBus() {
Compilation compilation = javac().withProcessors(new Mvp4g2Processor()).compile(new ArrayList<JavaFileObject>() {
{
add(JavaFileObjects.forResource("com/github/mvp4g/mvp4g2/processor/eventbus/debugAnnotationWithoutExtendsIsEventBus/DebugAnnotationWithoutExtendsIsEventBus.java"));
}
});
CompilationSubject.assertThat(compilation).failed();
CompilationSubject.assertThat(compilation).hadErrorContaining("@Debug can only be used with an interfaces annotated with @EventBus");
}
Aggregations