Search in sources :

Example 1 with Application

use of com.github.mvp4g.mvp4g2.core.application.annotation.Application in project mvp4g2 by mvp4g.

the class ApplicationTest method testApplicationAnnotationOnAClass.

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

        {
            add(JavaFileObjects.forResource("com/github/mvp4g/mvp4g2/processor/application/applicationAnnotationOnClass/ApplicationAnnotationInterfaceOnAClass.java"));
        }
    });
    CompilationSubject.assertThat(compilation).failed();
    CompilationSubject.assertThat(compilation).hadErrorContaining("@Application annotated must be used with an 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 Application

use of com.github.mvp4g.mvp4g2.core.application.annotation.Application in project mvp4g2 by mvp4g.

the class ApplicationTest method testApplicationAnnotationOkWithoutLoader.

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

        {
            add(JavaFileObjects.forResource("com/github/mvp4g/mvp4g2/processor/application/applicationAnnotationOkWithoutLoader/ApplicationAnnotationOkWithoutLoader.java"));
            add(JavaFileObjects.forResource("com/github/mvp4g/mvp4g2/processor/application/applicationAnnotationOkWithoutLoader/MockEventBus.java"));
            add(JavaFileObjects.forResource("com/github/mvp4g/mvp4g2/processor/application/applicationAnnotationOkWithoutLoader/MockOneEventHandler.java"));
            add(JavaFileObjects.forResource("com/github/mvp4g/mvp4g2/processor/application/applicationAnnotationOkWithoutLoader/MockShellPresenter.java"));
        }
    });
    CompilationSubject.assertThat(compilation).succeeded();
    JavaFileObjectSubject.assertThat(JavaFileObjects.forResource("com/github/mvp4g/mvp4g2/processor/application/applicationAnnotationOkWithoutLoader/ApplicationAnnotationOkWithoutLoaderImpl.java")).hasSourceEquivalentTo(JavaFileObjects.forResource("com/github/mvp4g/mvp4g2/processor/application/applicationAnnotationOkWithoutLoader/ApplicationAnnotationOkWithoutLoaderImpl.java"));
}
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 Application

use of com.github.mvp4g.mvp4g2.core.application.annotation.Application in project mvp4g2 by mvp4g.

the class ApplicationTest method testApplicationInterfaceWithoutExtendsIsApplication.

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

        {
            add(JavaFileObjects.forResource("com/github/mvp4g/mvp4g2/processor/application/applicationInterfaceWithoutExtendsIsApplication/ApplicationInterfaceWithoutExtendsIsApplication.java"));
        }
    });
    CompilationSubject.assertThat(compilation).failed();
    CompilationSubject.assertThat(compilation).hadErrorContaining("@Application must implement IsApplication 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 4 with Application

use of com.github.mvp4g.mvp4g2.core.application.annotation.Application in project mvp4g2 by mvp4g.

the class ApplicationTest method testApplicationAnnotationOkWithLoader.

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

        {
            add(JavaFileObjects.forResource("com/github/mvp4g/mvp4g2/processor/application/applicationAnnotationOkWithLoader/ApplicationAnnotationOkWithLoader.java"));
            add(JavaFileObjects.forResource("com/github/mvp4g/mvp4g2/processor/application/applicationAnnotationOkWithLoader/MockApplicationLoader.java"));
            add(JavaFileObjects.forResource("com/github/mvp4g/mvp4g2/processor/application/applicationAnnotationOkWithLoader/MockEventBus.java"));
            add(JavaFileObjects.forResource("com/github/mvp4g/mvp4g2/processor/application/applicationAnnotationOkWithLoader/MockOneEventHandler.java"));
            add(JavaFileObjects.forResource("com/github/mvp4g/mvp4g2/processor/application/applicationAnnotationOkWithLoader/MockShellPresenter.java"));
        }
    });
    CompilationSubject.assertThat(compilation).succeeded();
    JavaFileObjectSubject.assertThat(JavaFileObjects.forResource("com/github/mvp4g/mvp4g2/processor/application/applicationAnnotationOkWithLoader/ApplicationAnnotationOkWithLoaderImpl.java")).hasSourceEquivalentTo(JavaFileObjects.forResource("com/github/mvp4g/mvp4g2/processor/application/applicationAnnotationOkWithLoader/ApplicationAnnotationOkWithLoaderImpl.java"));
}
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 Application

use of com.github.mvp4g.mvp4g2.core.application.annotation.Application in project mvp4g2 by mvp4g.

the class ApplicationAnnotationScanner method scan.

public ApplicationMetaModel scan(RoundEnvironment roundEnvironment) throws ProcessorException {
    // First we try to read an already created resource ...
    ApplicationMetaModel model = this.restore();
    // Check if we have an element annotated with @Application
    if (!roundEnvironment.getElementsAnnotatedWith(Application.class).isEmpty()) {
        // check, whether we have o do something ...
        ApplicationAnnotationValidator validator = ApplicationAnnotationValidator.builder().roundEnvironment(roundEnvironment).processingEnvironment(this.processingEnvironment).build();
        validator.validate();
        // should only be one, so we can search for the first! ...
        Optional<? extends Element> optionalElement = this.roundEnvironment.getElementsAnnotatedWith(Application.class).stream().findFirst();
        if (optionalElement.isPresent()) {
            Element applicationAnnotationElement = optionalElement.get();
            validator.validate(applicationAnnotationElement);
            Application applicationAnnotation = applicationAnnotationElement.getAnnotation(Application.class);
            if (!isNull(applicationAnnotation)) {
                TypeElement eventBusTypeElement = this.getEventBusTypeElement(applicationAnnotation);
                TypeElement applicationLoaderTypeElement = this.getApplicationLoaderTypeElement(applicationAnnotation);
                model = new ApplicationMetaModel(applicationAnnotationElement.toString(), isNull(eventBusTypeElement) ? "" : eventBusTypeElement.toString(), isNull(applicationLoaderTypeElement) ? "" : applicationLoaderTypeElement.toString(), String.valueOf(applicationAnnotation.historyOnStart()));
                // let's store the updated model
                this.processorUtils.store(model, this.createRelativeFileName());
            }
        }
    }
    return model;
}
Also used : ApplicationMetaModel(com.github.mvp4g.mvp4g2.processor.model.ApplicationMetaModel) TypeElement(javax.lang.model.element.TypeElement) Element(javax.lang.model.element.Element) TypeElement(javax.lang.model.element.TypeElement) Application(com.github.mvp4g.mvp4g2.core.application.annotation.Application) ApplicationAnnotationValidator(com.github.mvp4g.mvp4g2.processor.scanner.validation.ApplicationAnnotationValidator)

Aggregations

Mvp4g2Processor (com.github.mvp4g.mvp4g2.processor.Mvp4g2Processor)8 Compilation (com.google.testing.compile.Compilation)8 JavaFileObject (javax.tools.JavaFileObject)8 Test (org.junit.Test)8 Element (javax.lang.model.element.Element)5 TypeElement (javax.lang.model.element.TypeElement)5 ProcessorException (com.github.mvp4g.mvp4g2.processor.ProcessorException)3 Application (com.github.mvp4g.mvp4g2.core.application.annotation.Application)1 Debug (com.github.mvp4g.mvp4g2.core.eventbus.annotation.Debug)1 EventBus (com.github.mvp4g.mvp4g2.core.eventbus.annotation.EventBus)1 History (com.github.mvp4g.mvp4g2.core.history.annotation.History)1 ApplicationMetaModel (com.github.mvp4g.mvp4g2.processor.model.ApplicationMetaModel)1 EventBusMetaModel (com.github.mvp4g.mvp4g2.processor.model.EventBusMetaModel)1 HistoryMetaModel (com.github.mvp4g.mvp4g2.processor.model.HistoryMetaModel)1 ApplicationAnnotationValidator (com.github.mvp4g.mvp4g2.processor.scanner.validation.ApplicationAnnotationValidator)1 EventBusAnnotationValidator (com.github.mvp4g.mvp4g2.processor.scanner.validation.EventBusAnnotationValidator)1 HistoryAnnotationValidator (com.github.mvp4g.mvp4g2.processor.scanner.validation.HistoryAnnotationValidator)1