Search in sources :

Example 21 with EventHandler

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

the class PresenterTest method testEventHandlingMethodDoesNotReturnVoid03.

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

        {
            add(JavaFileObjects.forResource("com/github/mvp4g/mvp4g2/processor/eventhandler/eventHandlingMethodDoesNotReturnVoid03/EventBusEventHandlingMethodDoesNotReturnVoid.java"));
            add(JavaFileObjects.forResource("com/github/mvp4g/mvp4g2/processor/eventhandler/eventHandlingMethodDoesNotReturnVoid03/MockShellPresenter01.java"));
            add(JavaFileObjects.forResource("com/github/mvp4g/mvp4g2/processor/eventhandler/eventHandlingMethodDoesNotReturnVoid03/IMockShellView01.java"));
            add(JavaFileObjects.forResource("com/github/mvp4g/mvp4g2/processor/eventhandler/eventHandlingMethodDoesNotReturnVoid03/MockShellView01.java"));
        }
    });
    CompilationSubject.assertThat(compilation).failed();
    CompilationSubject.assertThat(compilation).hadErrorContaining("Mvp4g2Processor: >>com.github.mvp4g.mvp4g2.processor.eventhandler.eventHandlingMethodDoesNotReturnVoid03.MockShellPresenter01<< -> EventElement: >>onDoSomething()<< must return 'void'");
}
Also used : JavaFileObject(javax.tools.JavaFileObject) Compilation(com.google.testing.compile.Compilation) Mvp4g2Processor(com.github.mvp4g.mvp4g2.processor.Mvp4g2Processor) Test(org.junit.Test)

Example 22 with EventHandler

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

the class PresenterTest method testEventHandlingMethodDoesNotReturnVoid04.

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

        {
            add(JavaFileObjects.forResource("com/github/mvp4g/mvp4g2/processor/eventhandler/eventHandlingMethodDoesNotReturnVoid04/EventBusEventHandlingMethodDoesNotReturnVoid.java"));
            add(JavaFileObjects.forResource("com/github/mvp4g/mvp4g2/processor/eventhandler/eventHandlingMethodDoesNotReturnVoid04/MockShellPresenter01.java"));
            add(JavaFileObjects.forResource("com/github/mvp4g/mvp4g2/processor/eventhandler/eventHandlingMethodDoesNotReturnVoid04/IMockShellView01.java"));
            add(JavaFileObjects.forResource("com/github/mvp4g/mvp4g2/processor/eventhandler/eventHandlingMethodDoesNotReturnVoid04/MockShellView01.java"));
        }
    });
    CompilationSubject.assertThat(compilation).failed();
    CompilationSubject.assertThat(compilation).hadErrorContaining("Mvp4g2Processor: >>com.github.mvp4g.mvp4g2.processor.eventhandler.eventHandlingMethodDoesNotReturnVoid04.MockShellPresenter01<< -> EventElement: >>onDoSomething()<< must return 'void'");
}
Also used : JavaFileObject(javax.tools.JavaFileObject) Compilation(com.google.testing.compile.Compilation) Mvp4g2Processor(com.github.mvp4g.mvp4g2.processor.Mvp4g2Processor) Test(org.junit.Test)

Example 23 with EventHandler

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

the class HandlerGenerator method generate.

public void generate(HandlerMetaModel metaModel) throws ProcessorException {
    ClassName eventHandlerMetaDataClassName = ClassName.get(HandlerMetaData.class);
    ClassName eventHandlerMetaDataKindClassName = ClassName.get(HandlerMetaData.Kind.class);
    for (String eventHandler : metaModel.getHandlerKeys()) {
        // check if element is existing (to avoid generating code for deleted items)
        if (this.processorUtils.doesExist(new ClassNameModel(eventHandler))) {
            HandlerMetaModel.HandlerData data = metaModel.getHandlerData(eventHandler);
            String className = this.processorUtils.createFullClassName(data.getHandler().getPackage(), data.getHandler().getSimpleName() + ProcessorConstants.META_DATA);
            TypeSpec.Builder typeSpec = TypeSpec.classBuilder(this.processorUtils.setFirstCharacterToUpperCase(className)).superclass(ParameterizedTypeName.get(eventHandlerMetaDataClassName, data.getHandler().getTypeName())).addModifiers(Modifier.PUBLIC, Modifier.FINAL);
            // constructor ...
            MethodSpec.Builder constructor = MethodSpec.constructorBuilder().addModifiers(Modifier.PUBLIC).addStatement("super($S, $T.EVENT_HANDLER, new $T())", data.getHandler().getClassName(), eventHandlerMetaDataKindClassName, data.getHandler().getTypeName());
            typeSpec.addMethod(constructor.build());
            JavaFile javaFile = JavaFile.builder(data.getHandler().getPackage(), typeSpec.build()).build();
            try {
                javaFile.writeTo(this.processingEnvironment.getFiler());
            } catch (IOException e) {
                throw new ProcessorException("Unable to write generated file: >>" + data.getHandler().getSimpleName() + ProcessorConstants.META_DATA + "<< -> exception: " + e.getMessage());
            }
        }
    }
}
Also used : HandlerMetaData(com.github.mvp4g.mvp4g2.core.internal.ui.HandlerMetaData) HandlerMetaModel(com.github.mvp4g.mvp4g2.processor.model.HandlerMetaModel) ProcessorException(com.github.mvp4g.mvp4g2.processor.ProcessorException) MethodSpec(com.squareup.javapoet.MethodSpec) IOException(java.io.IOException) ClassName(com.squareup.javapoet.ClassName) JavaFile(com.squareup.javapoet.JavaFile) ClassNameModel(com.github.mvp4g.mvp4g2.processor.model.intern.ClassNameModel) TypeSpec(com.squareup.javapoet.TypeSpec)

Example 24 with EventHandler

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

the class HandlerTest method testHandlerWithWrongImplementation03.

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

        {
            add(JavaFileObjects.forResource("com/github/mvp4g/mvp4g2/processor/eventhandler/handlerWithWrongImplementation03/EventBusHandlerWithNotImplementedEvent.java"));
            add(JavaFileObjects.forResource("com/github/mvp4g/mvp4g2/processor/eventhandler/handlerWithWrongImplementation03/MockOneEventHandler.java"));
            add(JavaFileObjects.forResource("com/github/mvp4g/mvp4g2/processor/eventhandler/handlerWithWrongImplementation03/MockShellPresenter01.java"));
            add(JavaFileObjects.forResource("com/github/mvp4g/mvp4g2/processor/eventhandler/handlerWithWrongImplementation03/IMockShellView01.java"));
            add(JavaFileObjects.forResource("com/github/mvp4g/mvp4g2/processor/eventhandler/handlerWithWrongImplementation03/MockShellView01.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)

Example 25 with EventHandler

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

the class HandlerTest method testEventHandlerWithNotImplementedEvent.

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

        {
            add(JavaFileObjects.forResource("com/github/mvp4g/mvp4g2/processor/eventhandler/handlerWithNotImplementedEvent/EventBusHandlerWithNotImplementedEvent.java"));
            add(JavaFileObjects.forResource("com/github/mvp4g/mvp4g2/processor/eventhandler/handlerWithNotImplementedEvent/MockOneEventHandler.java"));
            add(JavaFileObjects.forResource("com/github/mvp4g/mvp4g2/processor/eventhandler/handlerWithNotImplementedEvent/MockShellPresenter01.java"));
            add(JavaFileObjects.forResource("com/github/mvp4g/mvp4g2/processor/eventhandler/handlerWithNotImplementedEvent/IMockShellView01.java"));
            add(JavaFileObjects.forResource("com/github/mvp4g/mvp4g2/processor/eventhandler/handlerWithNotImplementedEvent/MockShellView01.java"));
        }
    });
    CompilationSubject.assertThat(compilation).failed();
    CompilationSubject.assertThat(compilation).hadErrorContaining("event >>doSomethingInHandler()<< 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)

Aggregations

Mvp4g2Processor (com.github.mvp4g.mvp4g2.processor.Mvp4g2Processor)32 Compilation (com.google.testing.compile.Compilation)32 Test (org.junit.Test)32 JavaFileObject (javax.tools.JavaFileObject)29 EventHandler (com.github.mvp4g.mvp4g2.core.ui.annotation.EventHandler)3 Person (de.gishmo.gwt.example.mvp4g2.simpleapplication.client.data.model.dto.Person)2 HandlerMetaData (com.github.mvp4g.mvp4g2.core.internal.ui.HandlerMetaData)1 ProcessorException (com.github.mvp4g.mvp4g2.processor.ProcessorException)1 HandlerMetaModel (com.github.mvp4g.mvp4g2.processor.model.HandlerMetaModel)1 ClassNameModel (com.github.mvp4g.mvp4g2.processor.model.intern.ClassNameModel)1 ClassName (com.squareup.javapoet.ClassName)1 JavaFile (com.squareup.javapoet.JavaFile)1 MethodSpec (com.squareup.javapoet.MethodSpec)1 TypeSpec (com.squareup.javapoet.TypeSpec)1 PersonSearch (de.gishmo.gwt.example.mvp4g2.simpleapplication.client.data.model.dto.PersonSearch)1 PersonNotFoundException (de.gishmo.gwt.example.mvp4g2.simpleapplication.client.data.model.exception.PersonNotFoundException)1 Person (de.gishmo.gwt.example.mvp4g2.springboot.client.data.model.dto.Person)1 PersonSearch (de.gishmo.gwt.example.mvp4g2.springboot.client.data.model.dto.PersonSearch)1 IOException (java.io.IOException)1 List (java.util.List)1