Search in sources :

Example 16 with Presenter

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

the class PresenterTest method testPresenterNotExtendingAbstractPresenter.

@Test
public void testPresenterNotExtendingAbstractPresenter() {
    Compilation compilation = javac().withProcessors(new Mvp4g2Processor()).compile(new ArrayList<JavaFileObject>() {

        {
            add(JavaFileObjects.forResource("com/github/mvp4g/mvp4g2/processor/eventhandler/presenterAnnotationNotExtendingAbstractPresenter/PresenterAnnotationNotExtendingAbstractPresenter.java"));
        }
    });
    CompilationSubject.assertThat(compilation).failed();
    CompilationSubject.assertThat(compilation).hadErrorContaining("@Presenter must extend AbstractPresenter.class");
}
Also used : JavaFileObject(javax.tools.JavaFileObject) Compilation(com.google.testing.compile.Compilation) Mvp4g2Processor(com.github.mvp4g.mvp4g2.processor.Mvp4g2Processor) Test(org.junit.Test)

Example 17 with Presenter

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

the class PresenterTest method testPresenterWithWrongImplementation01.

@Test
public void testPresenterWithWrongImplementation01() {
    Compilation compilation = javac().withProcessors(new Mvp4g2Processor()).compile(new ArrayList<JavaFileObject>() {

        {
            add(JavaFileObjects.forResource("com/github/mvp4g/mvp4g2/processor/eventhandler/presenterWithWrongImplementation01/EventBusHandlerWithNotImplementedEvent.java"));
            add(JavaFileObjects.forResource("com/github/mvp4g/mvp4g2/processor/eventhandler/presenterWithWrongImplementation01/MockShellPresenter01.java"));
            add(JavaFileObjects.forResource("com/github/mvp4g/mvp4g2/processor/eventhandler/presenterWithWrongImplementation01/IMockShellView01.java"));
            add(JavaFileObjects.forResource("com/github/mvp4g/mvp4g2/processor/eventhandler/presenterWithWrongImplementation01/MockShellView01.java"));
        }
    });
    CompilationSubject.assertThat(compilation).failed();
    CompilationSubject.assertThat(compilation).hadErrorContaining("event >>doSomething()<< is never handled by a presenter or handler");
}
Also used : JavaFileObject(javax.tools.JavaFileObject) Compilation(com.google.testing.compile.Compilation) Mvp4g2Processor(com.github.mvp4g.mvp4g2.processor.Mvp4g2Processor) Test(org.junit.Test)

Example 18 with Presenter

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

the class PresenterTest method testPresenterIsShellAndIsMultipleNotOk.

// a shell presenter can not implement is multiple!
@Test
public void testPresenterIsShellAndIsMultipleNotOk() {
    Compilation compilation = javac().withProcessors(new Mvp4g2Processor()).compile(new ArrayList<JavaFileObject>() {

        {
            add(JavaFileObjects.forResource("com/github/mvp4g/mvp4g2/processor/eventhandler/presenterIsShellAndIsMultipleNotOk/EventBusPresenterIsShellAndIsMultipleNotOk.java"));
            add(JavaFileObjects.forResource("com/github/mvp4g/mvp4g2/processor/eventhandler/presenterIsShellAndIsMultipleNotOk/MockShellPresenter01.java"));
            add(JavaFileObjects.forResource("com/github/mvp4g/mvp4g2/processor/eventhandler/presenterIsShellAndIsMultipleNotOk/IMockShellView01.java"));
            add(JavaFileObjects.forResource("com/github/mvp4g/mvp4g2/processor/eventhandler/presenterIsShellAndIsMultipleNotOk/MockShellView01.java"));
        }
    });
    CompilationSubject.assertThat(compilation).failed();
    CompilationSubject.assertThat(compilation).hadErrorContaining("IsShell interface can not be used on a presenter which is defiend as multiple = true");
}
Also used : JavaFileObject(javax.tools.JavaFileObject) Compilation(com.google.testing.compile.Compilation) Mvp4g2Processor(com.github.mvp4g.mvp4g2.processor.Mvp4g2Processor) Test(org.junit.Test)

Example 19 with Presenter

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

the class PresenterTest method testPresenterAnnotationAnnotatedOnAbstractClass.

@Test
public void testPresenterAnnotationAnnotatedOnAbstractClass() {
    Compilation compilation = javac().withProcessors(new Mvp4g2Processor()).compile(new ArrayList<JavaFileObject>() {

        {
            add(JavaFileObjects.forResource("com/github/mvp4g/mvp4g2/processor/eventhandler/presenterAnnotationAnnotatedOnAbstractClass" + "/PresenterAnnotationAnnotatedOnAbstractClass.java"));
        }
    });
    CompilationSubject.assertThat(compilation).failed();
    CompilationSubject.assertThat(compilation).hadErrorContaining("@Presenter can not be ABSTRACT");
}
Also used : JavaFileObject(javax.tools.JavaFileObject) Compilation(com.google.testing.compile.Compilation) Mvp4g2Processor(com.github.mvp4g.mvp4g2.processor.Mvp4g2Processor) Test(org.junit.Test)

Example 20 with Presenter

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

the class PresenterGenerator method generate.

public void generate(PresenterMetaModel metaModel) throws ProcessorException {
    ClassName presenterrMetaDataClassName = ClassName.get(PresenterMetaData.class);
    ClassName presenterMetaDataKindClassName = ClassName.get(HandlerMetaData.Kind.class);
    ClassName presenterViewCreationMethodClassName = ClassName.get(Presenter.VIEW_CREATION_METHOD.class);
    for (String presenter : metaModel.getPresenterKeys()) {
        // check if element is existing (to avoid generating code for deleted items)
        if (this.processorUtils.doesExist(new ClassNameModel(presenter))) {
            PresenterMetaModel.PresenterData data = metaModel.getPresenterData(presenter);
            String className = this.processorUtils.createFullClassName(data.getPresenter().getPackage(), data.getPresenter().getSimpleName() + ProcessorConstants.META_DATA);
            TypeSpec.Builder typeSpec = TypeSpec.classBuilder(this.processorUtils.setFirstCharacterToUpperCase(className)).superclass(ParameterizedTypeName.get(presenterrMetaDataClassName, data.getPresenter().getTypeName(), data.getViewInterface().getTypeName())).addModifiers(Modifier.PUBLIC, Modifier.FINAL);
            // constructor ...
            MethodSpec.Builder constructor = MethodSpec.constructorBuilder().addModifiers(Modifier.PUBLIC).addStatement("super($S, $T.PRESENTER, $N, $T.$L)", data.getPresenter().getClassName(), presenterMetaDataKindClassName, data.getIsMultiple(), presenterViewCreationMethodClassName, data.getViewCreationMethod());
            if (!metaModel.getPresenterData(presenter).isMultiple()) {
                constructor.addStatement("super.presenter = new $T()", data.getPresenter().getTypeName());
                if (Presenter.VIEW_CREATION_METHOD.FRAMEWORK.toString().equals(data.getViewCreationMethod())) {
                    constructor.addStatement("super.view = ($T) new $T()", data.getViewInterface().getTypeName(), data.getViewClass().getTypeName());
                } else {
                    constructor.addStatement("super.view = presenter.createView()");
                }
            }
            typeSpec.addMethod(constructor.build());
            JavaFile javaFile = JavaFile.builder(data.getPresenter().getPackage(), typeSpec.build()).build();
            try {
                javaFile.writeTo(this.processingEnvironment.getFiler());
            } catch (IOException e) {
                throw new ProcessorException("Unable to write generated file: >>" + data.getPresenter().getSimpleName() + ProcessorConstants.META_DATA + "<< -> exception: " + e.getMessage());
            }
        }
    }
}
Also used : HandlerMetaData(com.github.mvp4g.mvp4g2.core.internal.ui.HandlerMetaData) ProcessorException(com.github.mvp4g.mvp4g2.processor.ProcessorException) MethodSpec(com.squareup.javapoet.MethodSpec) IOException(java.io.IOException) Presenter(com.github.mvp4g.mvp4g2.core.ui.annotation.Presenter) PresenterMetaModel(com.github.mvp4g.mvp4g2.processor.model.PresenterMetaModel) ClassName(com.squareup.javapoet.ClassName) JavaFile(com.squareup.javapoet.JavaFile) ClassNameModel(com.github.mvp4g.mvp4g2.processor.model.intern.ClassNameModel) TypeSpec(com.squareup.javapoet.TypeSpec)

Aggregations

Mvp4g2Processor (com.github.mvp4g.mvp4g2.processor.Mvp4g2Processor)16 Compilation (com.google.testing.compile.Compilation)16 JavaFileObject (javax.tools.JavaFileObject)16 Test (org.junit.Test)16 Presenter (com.github.mvp4g.mvp4g2.core.ui.annotation.Presenter)3 ProcessorException (com.github.mvp4g.mvp4g2.processor.ProcessorException)3 PresenterMetaModel (com.github.mvp4g.mvp4g2.processor.model.PresenterMetaModel)3 ClassNameModel (com.github.mvp4g.mvp4g2.processor.model.intern.ClassNameModel)3 TypeElement (javax.lang.model.element.TypeElement)3 IsShell (com.github.mvp4g.mvp4g2.core.ui.IsShell)2 HandlerMetaData (com.github.mvp4g.mvp4g2.core.internal.ui.HandlerMetaData)1 AbstractPresenter (com.github.mvp4g.mvp4g2.core.ui.AbstractPresenter)1 IsViewCreator (com.github.mvp4g.mvp4g2.core.ui.IsViewCreator)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 PresenterAnnotationValidator (com.github.mvp4g.mvp4g2.processor.scanner.validation.PresenterAnnotationValidator)1 ClassName (com.squareup.javapoet.ClassName)1 JavaFile (com.squareup.javapoet.JavaFile)1