Search in sources :

Example 76 with Mvp4g2Processor

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)");
        }
    }
}
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)

Example 77 with Mvp4g2Processor

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();
}
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)72 Compilation (com.google.testing.compile.Compilation)72 Test (org.junit.Test)72 JavaFileObject (javax.tools.JavaFileObject)69 ProcessorException (com.github.mvp4g.mvp4g2.processor.ProcessorException)5 TypeElement (javax.lang.model.element.TypeElement)5 Element (javax.lang.model.element.Element)3 ExecutableElement (javax.lang.model.element.ExecutableElement)3 ClassNameModel (com.github.mvp4g.mvp4g2.processor.model.intern.ClassNameModel)2 Event (com.github.mvp4g.mvp4g2.core.eventbus.annotation.Event)1 InitHistory (com.github.mvp4g.mvp4g2.core.history.annotation.InitHistory)1 NotFoundHistory (com.github.mvp4g.mvp4g2.core.history.annotation.NotFoundHistory)1 AbstractPresenter (com.github.mvp4g.mvp4g2.core.ui.AbstractPresenter)1 IsShell (com.github.mvp4g.mvp4g2.core.ui.IsShell)1 IsViewCreator (com.github.mvp4g.mvp4g2.core.ui.IsViewCreator)1 Presenter (com.github.mvp4g.mvp4g2.core.ui.annotation.Presenter)1 ProcessorUtils (com.github.mvp4g.mvp4g2.processor.ProcessorUtils)1 EventBusMetaModel (com.github.mvp4g.mvp4g2.processor.model.EventBusMetaModel)1 EventMetaModel (com.github.mvp4g.mvp4g2.processor.model.EventMetaModel)1 HandlerMetaModel (com.github.mvp4g.mvp4g2.processor.model.HandlerMetaModel)1