Search in sources :

Example 1 with ProcessorException

use of com.github.mvp4g.mvp4g2.processor.ProcessorException 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)

Example 2 with ProcessorException

use of com.github.mvp4g.mvp4g2.processor.ProcessorException in project mvp4g2 by mvp4g.

the class DebugAnnotationScanner method scan.

public EventBusMetaModel scan(RoundEnvironment roundEnvironment) throws ProcessorException {
    // do validation
    DebugAnnotationValidator.builder().roundEnvironment(roundEnvironment).processingEnvironment(processingEnvironment).build().validate();
    // handle debug-annotation
    Debug debugAnnotation = eventBusTypeElement.getAnnotation(Debug.class);
    if (!isNull(debugAnnotation)) {
        this.eventBusMetaModel.setHasDebugAnnotation("true");
        this.eventBusMetaModel.setDebugLogLevel(debugAnnotation.logLevel().toString());
        if (!isNull(getLogger(debugAnnotation))) {
            this.eventBusMetaModel.setDebugLogger(getLogger(debugAnnotation).getQualifiedName().toString());
        }
    } else {
        this.eventBusMetaModel.setHasDebugAnnotation("false");
        this.eventBusMetaModel.setDebugLogLevel("");
        this.eventBusMetaModel.setDebugLogger("");
    }
    return this.eventBusMetaModel;
}
Also used : Debug(com.github.mvp4g.mvp4g2.core.eventbus.annotation.Debug)

Example 3 with ProcessorException

use of com.github.mvp4g.mvp4g2.processor.ProcessorException in project mvp4g2 by mvp4g.

the class HistoryAnnotationScanner method scan.

public HistoryMetaModel scan(RoundEnvironment roundEnvironment) throws ProcessorException {
    // First we try to read an already created resource ...
    HistoryMetaModel model = this.restore();
    // Check if we have an element annotated with @Application
    if (!roundEnvironment.getElementsAnnotatedWith(History.class).isEmpty()) {
        // check annotation ...
        HistoryAnnotationValidator validator = HistoryAnnotationValidator.builder().roundEnvironment(roundEnvironment).processingEnvironment(this.processingEnvironment).build();
        // iterate over all history converters
        for (Element element : roundEnvironment.getElementsAnnotatedWith(History.class)) {
            // validate
            validator.validate(element);
            // process ...
            TypeElement typeElement = (TypeElement) element;
            History historyAnnotation = typeElement.getAnnotation(History.class);
            validator.validate(element);
            model.add(typeElement.getQualifiedName().toString(), historyAnnotation.type().toString());
        }
        // let's store the updated model
        this.processorUtils.store(model, this.createRelativeFileName());
    }
    return model;
}
Also used : HistoryMetaModel(com.github.mvp4g.mvp4g2.processor.model.HistoryMetaModel) TypeElement(javax.lang.model.element.TypeElement) Element(javax.lang.model.element.Element) TypeElement(javax.lang.model.element.TypeElement) HistoryAnnotationValidator(com.github.mvp4g.mvp4g2.processor.scanner.validation.HistoryAnnotationValidator) History(com.github.mvp4g.mvp4g2.core.history.annotation.History)

Example 4 with ProcessorException

use of com.github.mvp4g.mvp4g2.processor.ProcessorException in project mvp4g2 by mvp4g.

the class PresenterAnnotationScanner method scan.

public PresenterMetaModel scan(RoundEnvironment roundEnvironment) throws ProcessorException {
    // Validator
    PresenterAnnotationValidator validator = PresenterAnnotationValidator.builder().processingEnvironment(processingEnvironment).build();
    // read all already created model
    PresenterMetaModel model = this.restore();
    // iterate over Presenter
    for (Element element : roundEnvironment.getElementsAnnotatedWith(Presenter.class)) {
        TypeElement typeElement = (TypeElement) element;
        // validate
        validator.validate(typeElement, this.getViewClassTypeElement(typeElement.getAnnotation(Presenter.class)), this.getViewInterfaceTypeElement(typeElement.getAnnotation(Presenter.class)));
        // update model
        model.add(((TypeElement) element).getQualifiedName().toString(), typeElement.getAnnotation(Presenter.class).multiple() ? "true" : "false", this.processorUtils.extendsClassOrInterface(this.processingEnvironment.getTypeUtils(), typeElement.asType(), this.processingEnvironment.getElementUtils().getTypeElement(IsShell.class.getCanonicalName()).asType()) ? "true" : "false", this.getViewClassTypeElement(element.getAnnotation(Presenter.class)).getQualifiedName().toString(), this.getViewInterfaceTypeElement(element.getAnnotation(Presenter.class)).getQualifiedName().toString(), typeElement.getAnnotation(Presenter.class).viewCreator().toString(), this.processorUtils.createHandledEventArray(typeElement));
    }
    // let's store the updated model
    this.processorUtils.store(model, this.createRelativeFileName());
    return model;
}
Also used : IsShell(com.github.mvp4g.mvp4g2.core.ui.IsShell) PresenterMetaModel(com.github.mvp4g.mvp4g2.processor.model.PresenterMetaModel) TypeElement(javax.lang.model.element.TypeElement) Presenter(com.github.mvp4g.mvp4g2.core.ui.annotation.Presenter) Element(javax.lang.model.element.Element) TypeElement(javax.lang.model.element.TypeElement) PresenterAnnotationValidator(com.github.mvp4g.mvp4g2.processor.scanner.validation.PresenterAnnotationValidator)

Example 5 with ProcessorException

use of com.github.mvp4g.mvp4g2.processor.ProcessorException in project mvp4g2 by mvp4g.

the class ApplicationGenerator method generate.

public void generate(ApplicationMetaModel metaModel) throws ProcessorException {
    // check if element is existing (to avoid generating code for deleted items)
    if (!this.processorUtils.doesExist(metaModel.getApplication())) {
        return;
    }
    // generate code
    TypeSpec.Builder typeSpec = TypeSpec.classBuilder(metaModel.getApplication().getSimpleName() + ApplicationGenerator.IMPL_NAME).superclass(ParameterizedTypeName.get(ClassName.get(AbstractApplication.class), metaModel.getEventBus().getTypeName())).addModifiers(Modifier.PUBLIC, Modifier.FINAL).addSuperinterface(metaModel.getApplication().getTypeName());
    // constructor ...
    MethodSpec constructor = MethodSpec.constructorBuilder().addModifiers(Modifier.PUBLIC).addStatement("super()").addStatement("super.eventBus = new $N.$N()", metaModel.getEventBus().getPackage(), metaModel.getEventBus().getSimpleName() + ApplicationGenerator.IMPL_NAME).addStatement("super.historyOnStart = $L", metaModel.getHistoryOnStart()).build();
    typeSpec.addMethod(constructor);
    // method "getApplicaitonLoader"
    MethodSpec getApplicaitonLaoderMethod = MethodSpec.methodBuilder("getApplicationLoader").addModifiers(Modifier.PUBLIC).addAnnotation(Override.class).returns(IsApplicationLoader.class).addStatement("return new $T()", metaModel.getLoader().getTypeName()).build();
    typeSpec.addMethod(getApplicaitonLaoderMethod);
    JavaFile javaFile = JavaFile.builder(metaModel.getEventBus().getPackage(), typeSpec.build()).build();
    try {
        javaFile.writeTo(this.processingEnvironment.getFiler());
    } catch (IOException e) {
        throw new ProcessorException("Unable to write generated file: >>" + metaModel.getEventBus().getSimpleName() + ApplicationGenerator.IMPL_NAME + "<< -> exception: " + e.getMessage());
    }
}
Also used : ProcessorException(com.github.mvp4g.mvp4g2.processor.ProcessorException) MethodSpec(com.squareup.javapoet.MethodSpec) JavaFile(com.squareup.javapoet.JavaFile) IOException(java.io.IOException) TypeSpec(com.squareup.javapoet.TypeSpec)

Aggregations

ProcessorException (com.github.mvp4g.mvp4g2.processor.ProcessorException)13 TypeElement (javax.lang.model.element.TypeElement)12 Element (javax.lang.model.element.Element)10 JavaFile (com.squareup.javapoet.JavaFile)6 MethodSpec (com.squareup.javapoet.MethodSpec)6 TypeSpec (com.squareup.javapoet.TypeSpec)6 IOException (java.io.IOException)6 ClassNameModel (com.github.mvp4g.mvp4g2.processor.model.intern.ClassNameModel)4 ExecutableElement (javax.lang.model.element.ExecutableElement)4 Presenter (com.github.mvp4g.mvp4g2.core.ui.annotation.Presenter)3 EventMetaModel (com.github.mvp4g.mvp4g2.processor.model.EventMetaModel)3 HandlerMetaModel (com.github.mvp4g.mvp4g2.processor.model.HandlerMetaModel)3 PresenterMetaModel (com.github.mvp4g.mvp4g2.processor.model.PresenterMetaModel)3 ClassName (com.squareup.javapoet.ClassName)3 Debug (com.github.mvp4g.mvp4g2.core.eventbus.annotation.Debug)2 Event (com.github.mvp4g.mvp4g2.core.eventbus.annotation.Event)2 History (com.github.mvp4g.mvp4g2.core.history.annotation.History)2 InitHistory (com.github.mvp4g.mvp4g2.core.history.annotation.InitHistory)2 NotFoundHistory (com.github.mvp4g.mvp4g2.core.history.annotation.NotFoundHistory)2 HandlerMetaData (com.github.mvp4g.mvp4g2.core.internal.ui.HandlerMetaData)2