Search in sources :

Example 1 with ApplicationAnnotationValidator

use of com.github.mvp4g.mvp4g2.processor.scanner.validation.ApplicationAnnotationValidator 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

Application (com.github.mvp4g.mvp4g2.core.application.annotation.Application)1 ApplicationMetaModel (com.github.mvp4g.mvp4g2.processor.model.ApplicationMetaModel)1 ApplicationAnnotationValidator (com.github.mvp4g.mvp4g2.processor.scanner.validation.ApplicationAnnotationValidator)1 Element (javax.lang.model.element.Element)1 TypeElement (javax.lang.model.element.TypeElement)1