Search in sources :

Example 1 with Debug

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)");
}
Also used : JavaFileObject(javax.tools.JavaFileObject) Compilation(com.google.testing.compile.Compilation) Mvp4g2Processor(com.github.mvp4g.mvp4g2.processor.Mvp4g2Processor) Test(org.junit.Test)

Example 2 with Debug

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)");
}
Also used : JavaFileObject(javax.tools.JavaFileObject) Compilation(com.google.testing.compile.Compilation) Mvp4g2Processor(com.github.mvp4g.mvp4g2.processor.Mvp4g2Processor) Test(org.junit.Test)

Example 3 with Debug

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;
}
Also used : Debug(com.github.mvp4g.mvp4g2.core.eventbus.annotation.Debug)

Example 4 with Debug

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)");
        }
    }
}
Also used : ProcessorException(com.github.mvp4g.mvp4g2.processor.ProcessorException) TypeElement(javax.lang.model.element.TypeElement) Element(javax.lang.model.element.Element) TypeElement(javax.lang.model.element.TypeElement) Debug(com.github.mvp4g.mvp4g2.core.eventbus.annotation.Debug)

Example 5 with Debug

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");
}
Also used : JavaFileObject(javax.tools.JavaFileObject) Compilation(com.google.testing.compile.Compilation) Mvp4g2Processor(com.github.mvp4g.mvp4g2.processor.Mvp4g2Processor) Test(org.junit.Test)

Aggregations

Mvp4g2Processor (com.github.mvp4g.mvp4g2.processor.Mvp4g2Processor)3 Compilation (com.google.testing.compile.Compilation)3 JavaFileObject (javax.tools.JavaFileObject)3 Test (org.junit.Test)3 Debug (com.github.mvp4g.mvp4g2.core.eventbus.annotation.Debug)2 ProcessorException (com.github.mvp4g.mvp4g2.processor.ProcessorException)2 Element (javax.lang.model.element.Element)2 TypeElement (javax.lang.model.element.TypeElement)2 EventBus (com.github.mvp4g.mvp4g2.core.eventbus.annotation.EventBus)1 EventBusMetaModel (com.github.mvp4g.mvp4g2.processor.model.EventBusMetaModel)1 EventBusAnnotationValidator (com.github.mvp4g.mvp4g2.processor.scanner.validation.EventBusAnnotationValidator)1