Search in sources :

Example 1 with IsViewCreator

use of com.github.mvp4g.mvp4g2.core.ui.IsViewCreator in project mvp4g2 by mvp4g.

the class PresenterTest method testPresenterWithViewCreationMethodPresenter03.

// IsViewCreator interface without generic
@Test
public void testPresenterWithViewCreationMethodPresenter03() {
    Compilation compilation = javac().withProcessors(new Mvp4g2Processor()).compile(new ArrayList<JavaFileObject>() {

        {
            add(JavaFileObjects.forResource("com/github/mvp4g/mvp4g2/processor/eventhandler/presenterWithViewCreationMethodPresenter03/EventBusPresenterWithViewCreationMethodPresenter03.java"));
            add(JavaFileObjects.forResource("com/github/mvp4g/mvp4g2/processor/eventhandler/presenterWithViewCreationMethodPresenter03/MockShellPresenter03.java"));
            add(JavaFileObjects.forResource("com/github/mvp4g/mvp4g2/processor/eventhandler/presenterWithViewCreationMethodPresenter03/IMockShellView03.java"));
            add(JavaFileObjects.forResource("com/github/mvp4g/mvp4g2/processor/eventhandler/presenterWithViewCreationMethodPresenter03/MockShellView03.java"));
            add(JavaFileObjects.forResource("com/github/mvp4g/mvp4g2/processor/eventhandler/presenterWithViewCreationMethodPresenter03/MockPresenter03.java"));
            add(JavaFileObjects.forResource("com/github/mvp4g/mvp4g2/processor/eventhandler/presenterWithViewCreationMethodPresenter03/IMockView03.java"));
            add(JavaFileObjects.forResource("com/github/mvp4g/mvp4g2/processor/eventhandler/presenterWithViewCreationMethodPresenter03/MockView03.java"));
        }
    });
    CompilationSubject.assertThat(compilation).failed();
    CompilationSubject.assertThat(compilation).hadErrorContaining("IsViewCreator interface needs a generic parameter");
}
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 IsViewCreator

use of com.github.mvp4g.mvp4g2.core.ui.IsViewCreator in project mvp4g2 by mvp4g.

the class PresenterTest method testPresenterWithViewCreationMethodPresenter01.

// missng IsViewCerator-interface
@Test
public void testPresenterWithViewCreationMethodPresenter01() {
    Compilation compilation = javac().withProcessors(new Mvp4g2Processor()).compile(new ArrayList<JavaFileObject>() {

        {
            add(JavaFileObjects.forResource("com/github/mvp4g/mvp4g2/processor/eventhandler/presenterWithViewCreationMethodPresenter01/EventBusPresenterWithViewCreationMethodPresenter01.java"));
            add(JavaFileObjects.forResource("com/github/mvp4g/mvp4g2/processor/eventhandler/presenterWithViewCreationMethodPresenter01/MockShellPresenter01.java"));
            add(JavaFileObjects.forResource("com/github/mvp4g/mvp4g2/processor/eventhandler/presenterWithViewCreationMethodPresenter01/IMockShellView01.java"));
            add(JavaFileObjects.forResource("com/github/mvp4g/mvp4g2/processor/eventhandler/presenterWithViewCreationMethodPresenter01/MockShellView01.java"));
            add(JavaFileObjects.forResource("com/github/mvp4g/mvp4g2/processor/eventhandler/presenterWithViewCreationMethodPresenter01/MockPresenter01.java"));
            add(JavaFileObjects.forResource("com/github/mvp4g/mvp4g2/processor/eventhandler/presenterWithViewCreationMethodPresenter01/IMockView01.java"));
            add(JavaFileObjects.forResource("com/github/mvp4g/mvp4g2/processor/eventhandler/presenterWithViewCreationMethodPresenter01/MockView01.java"));
        }
    });
    CompilationSubject.assertThat(compilation).failed();
    CompilationSubject.assertThat(compilation).hadErrorContaining("@Presenter must implement the IsViewCreator 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 IsViewCreator

use of com.github.mvp4g.mvp4g2.core.ui.IsViewCreator in project mvp4g2 by mvp4g.

the class PresenterAnnotationValidator method validate.

public void validate(Element element, TypeElement viewClassTypeElement, TypeElement viewInterfaceTypeElement) throws ProcessorException {
    if (element instanceof TypeElement) {
        TypeElement typeElement = (TypeElement) element;
        // check, that the presenter annotion is only used with classes
        if (!typeElement.getKind().isClass()) {
            throw new ProcessorException("Mvp4g2Processor:" + typeElement.getSimpleName().toString() + ": @Presenter can only be used with a class!");
        }
        // check, that the viewClass is a class
        if (!viewClassTypeElement.getKind().isClass()) {
            throw new ProcessorException("Mvp4g2Processor:" + typeElement.getSimpleName().toString() + ": the viewClass-attribute of a @Presenter must be a class!");
        }
        // chekc if the vioewInterface is a interface
        if (!viewInterfaceTypeElement.getKind().isInterface()) {
            throw new ProcessorException("Mvp4g2Processor:" + typeElement.getSimpleName().toString() + ": the viewInterface-attribute of a @Presenter must be a interface!");
        }
        // check, if viewClass is implementing viewInterface
        if (!this.processorUtils.implementsInterface(this.processingEnvironment, viewClassTypeElement, viewInterfaceTypeElement.asType())) {
            throw new ProcessorException("Mvp4g2Processor:" + typeElement.getSimpleName().toString() + ": the viewClass-attribute of a @Presenter must implement the viewInterface!");
        }
        // check, that the typeElement extends AbstractHandler
        if (!this.processorUtils.extendsClassOrInterface(this.processingEnvironment.getTypeUtils(), typeElement.asType(), this.processingEnvironment.getElementUtils().getTypeElement(AbstractPresenter.class.getCanonicalName()).asType())) {
            throw new ProcessorException(typeElement.getSimpleName().toString() + ": @Presenter must extend AbstractPresenter.class!");
        }
        // check if annotated class is abstract
        if (typeElement.getModifiers().contains(Modifier.ABSTRACT)) {
            throw new ProcessorException("Mvp4g2Processor:" + typeElement.getSimpleName().toString() + ": @Presenter can not be ABSTRACT");
        }
        // check if class attribute is not abstradt
        if (viewClassTypeElement.getModifiers().contains(Modifier.ABSTRACT)) {
            throw new ProcessorException(typeElement.getSimpleName().toString() + ": class-attribute of @Presenter can not be ABSTRACT");
        }
        // check if a shell presenter does not implememt the multiple feature
        TypeMirror isShellMirror = this.processorUtils.getFlattenedSupertype(this.processingEnvironment.getTypeUtils(), typeElement.asType(), this.processingEnvironment.getElementUtils().getTypeElement(IsShell.class.getCanonicalName()).asType());
        if (isShellMirror != null) {
            if (typeElement.getAnnotation(Presenter.class).multiple()) {
                throw new ProcessorException(typeElement.getSimpleName().toString() + ": IsShell interface can not be used on a presenter which is defiend as multiple = true");
            }
        }
        Presenter presenterAnnotation = typeElement.getAnnotation(Presenter.class);
        if (Presenter.VIEW_CREATION_METHOD.PRESENTER.equals(presenterAnnotation.viewCreator())) {
            // IsViewCreator interface!
            if (!this.processorUtils.extendsClassOrInterface(this.processingEnvironment.getTypeUtils(), typeElement.asType(), this.processingEnvironment.getElementUtils().getTypeElement(IsViewCreator.class.getCanonicalName()).asType())) {
                throw new ProcessorException(typeElement.getSimpleName().toString() + ": @Presenter must implement the IsViewCreator interface");
            }
            // check, if the viewCreator has a generic parameter
            if (!this.processorUtils.supertypeHasGeneric(this.processingEnvironment.getTypeUtils(), typeElement.asType(), this.processingEnvironment.getElementUtils().getTypeElement(IsViewCreator.class.getCanonicalName()).asType())) {
                throw new ProcessorException(typeElement.getSimpleName().toString() + ": IsViewCreator interface needs " + "a generic parameter (add: >>" + viewInterfaceTypeElement.toString() + "<< as generic to IsViewCreator)");
            } else {
                TypeMirror isViewCreatorTypeMirror = this.processorUtils.getFlattenedSupertype(this.processingEnvironment.getTypeUtils(), typeElement.asType(), this.processingEnvironment.getElementUtils().getTypeElement(IsViewCreator.class.getCanonicalName()).asType());
                ClassNameModel classNameModel = new ClassNameModel(viewInterfaceTypeElement.toString());
                if (!isViewCreatorTypeMirror.toString().contains(classNameModel.getSimpleName())) {
                    throw new ProcessorException(typeElement.getSimpleName().toString() + ": IsViewCreator interface only allows the generic parameter -> " + viewInterfaceTypeElement.toString());
                }
            }
        } else if (Presenter.VIEW_CREATION_METHOD.FRAMEWORK.equals(presenterAnnotation.viewCreator())) {
            // check, if a presenter implements IsViewCreator, that the viewCreation method is set to PRESENTER!
            if (this.processorUtils.extendsClassOrInterface(this.processingEnvironment.getTypeUtils(), typeElement.asType(), this.processingEnvironment.getElementUtils().getTypeElement(IsViewCreator.class.getCanonicalName()).asType())) {
                throw new ProcessorException(typeElement.getSimpleName().toString() + ": the IsViewCreator interface can only be used in case of viewCreator = Presenter.VIEW_CREATION_METHOD.PRESENTER");
            }
        }
    } else {
        throw new ProcessorException("Mvp4g2Processor: @Presenter can only be used on a type (class)");
    }
// TODo El Hoss: check, that @Event is only used inside a EventBus
}
Also used : IsShell(com.github.mvp4g.mvp4g2.core.ui.IsShell) ProcessorException(com.github.mvp4g.mvp4g2.processor.ProcessorException) TypeMirror(javax.lang.model.type.TypeMirror) TypeElement(javax.lang.model.element.TypeElement) AbstractPresenter(com.github.mvp4g.mvp4g2.core.ui.AbstractPresenter) Presenter(com.github.mvp4g.mvp4g2.core.ui.annotation.Presenter) IsViewCreator(com.github.mvp4g.mvp4g2.core.ui.IsViewCreator) ClassNameModel(com.github.mvp4g.mvp4g2.processor.model.intern.ClassNameModel)

Example 4 with IsViewCreator

use of com.github.mvp4g.mvp4g2.core.ui.IsViewCreator in project mvp4g2 by mvp4g.

the class PresenterTest method testPresenterWithViewCreationMethodPresenter05.

// IsViewCreator: check that the generic parameter is the view interface
@Test
public void testPresenterWithViewCreationMethodPresenter05() {
    Compilation compilation = javac().withProcessors(new Mvp4g2Processor()).compile(new ArrayList<JavaFileObject>() {

        {
            add(JavaFileObjects.forResource("com/github/mvp4g/mvp4g2/processor/eventhandler/presenterWithViewCreationMethodPresenter05/EventBusPresenterWithViewCreationMethodPresenter05.java"));
            add(JavaFileObjects.forResource("com/github/mvp4g/mvp4g2/processor/eventhandler/presenterWithViewCreationMethodPresenter05/MockShellPresenter05.java"));
            add(JavaFileObjects.forResource("com/github/mvp4g/mvp4g2/processor/eventhandler/presenterWithViewCreationMethodPresenter05/IMockShellView05.java"));
            add(JavaFileObjects.forResource("com/github/mvp4g/mvp4g2/processor/eventhandler/presenterWithViewCreationMethodPresenter05/MockShellView05.java"));
            add(JavaFileObjects.forResource("com/github/mvp4g/mvp4g2/processor/eventhandler/presenterWithViewCreationMethodPresenter05/MockPresenter05.java"));
            add(JavaFileObjects.forResource("com/github/mvp4g/mvp4g2/processor/eventhandler/presenterWithViewCreationMethodPresenter05/IMockView05.java"));
            add(JavaFileObjects.forResource("com/github/mvp4g/mvp4g2/processor/eventhandler/presenterWithViewCreationMethodPresenter05/MockView05.java"));
        }
    });
    CompilationSubject.assertThat(compilation).failed();
    CompilationSubject.assertThat(compilation).hadErrorContaining("IsViewCreator interface only allows the generic parameter ->");
}
Also used : JavaFileObject(javax.tools.JavaFileObject) Compilation(com.google.testing.compile.Compilation) Mvp4g2Processor(com.github.mvp4g.mvp4g2.processor.Mvp4g2Processor) Test(org.junit.Test)

Example 5 with IsViewCreator

use of com.github.mvp4g.mvp4g2.core.ui.IsViewCreator in project mvp4g2 by mvp4g.

the class PresenterTest method testPresenterWithViewCreationMethodPresenter04.

// IsViewCreator interface used without generic viewCreator = Presenter.VIEW_CREATION_METHOD.PRESENTER
@Test
public void testPresenterWithViewCreationMethodPresenter04() {
    Compilation compilation = javac().withProcessors(new Mvp4g2Processor()).compile(new ArrayList<JavaFileObject>() {

        {
            add(JavaFileObjects.forResource("com/github/mvp4g/mvp4g2/processor/eventhandler/presenterWithViewCreationMethodPresenter04/EventBusPresenterWithViewCreationMethodPresenter04.java"));
            add(JavaFileObjects.forResource("com/github/mvp4g/mvp4g2/processor/eventhandler/presenterWithViewCreationMethodPresenter04/MockShellPresenter04.java"));
            add(JavaFileObjects.forResource("com/github/mvp4g/mvp4g2/processor/eventhandler/presenterWithViewCreationMethodPresenter04/IMockShellView04.java"));
            add(JavaFileObjects.forResource("com/github/mvp4g/mvp4g2/processor/eventhandler/presenterWithViewCreationMethodPresenter04/MockShellView04.java"));
            add(JavaFileObjects.forResource("com/github/mvp4g/mvp4g2/processor/eventhandler/presenterWithViewCreationMethodPresenter04/MockPresenter04.java"));
            add(JavaFileObjects.forResource("com/github/mvp4g/mvp4g2/processor/eventhandler/presenterWithViewCreationMethodPresenter04/IMockView04.java"));
            add(JavaFileObjects.forResource("com/github/mvp4g/mvp4g2/processor/eventhandler/presenterWithViewCreationMethodPresenter04/MockView04.java"));
        }
    });
    CompilationSubject.assertThat(compilation).failed();
    CompilationSubject.assertThat(compilation).hadErrorContaining("the IsViewCreator interface can only be used in case of viewCreator = Presenter.VIEW_CREATION_METHOD.PRESENTER");
}
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)4 Compilation (com.google.testing.compile.Compilation)4 JavaFileObject (javax.tools.JavaFileObject)4 Test (org.junit.Test)4 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 ProcessorException (com.github.mvp4g.mvp4g2.processor.ProcessorException)1 ClassNameModel (com.github.mvp4g.mvp4g2.processor.model.intern.ClassNameModel)1 TypeElement (javax.lang.model.element.TypeElement)1 TypeMirror (javax.lang.model.type.TypeMirror)1