Search in sources :

Example 1 with HistoryMetaModel

use of com.github.mvp4g.mvp4g2.processor.model.HistoryMetaModel 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 2 with HistoryMetaModel

use of com.github.mvp4g.mvp4g2.processor.model.HistoryMetaModel in project mvp4g2 by mvp4g.

the class HistoryAnnotationScanner method restore.

private HistoryMetaModel restore() {
    Properties props = new Properties();
    try {
        FileObject resource = this.processingEnvironment.getFiler().getResource(StandardLocation.CLASS_OUTPUT, "", this.createRelativeFileName());
        props.load(resource.openInputStream());
        return new HistoryMetaModel(props);
    } catch (IOException e) {
    // every thing is ok -> no operation
    // this.processorUtils.createNoteMessage("no resource found for : >>" + this.createRelativeFileName() + "<<");
    }
    return new HistoryMetaModel();
}
Also used : HistoryMetaModel(com.github.mvp4g.mvp4g2.processor.model.HistoryMetaModel) FileObject(javax.tools.FileObject) IOException(java.io.IOException) Properties(java.util.Properties)

Example 3 with HistoryMetaModel

use of com.github.mvp4g.mvp4g2.processor.model.HistoryMetaModel in project mvp4g2 by mvp4g.

the class EventBusGenerator method generate.

public void generate(EventBusMetaModel eventBusMetaMetaModel, HandlerMetaModel handlerMetaModel, PresenterMetaModel presenterMetaModel, HistoryMetaModel historyMetaModel) throws ProcessorException {
    // check if element is existing (to avoid generating code for deleted items)
    if (!this.processorUtils.doesExist(eventBusMetaMetaModel.getEventBus())) {
        return;
    }
    ClassName abstractEventBusClassName = ClassName.get(AbstractEventBus.class);
    TypeSpec.Builder typeSpec = TypeSpec.classBuilder(eventBusMetaMetaModel.getEventBus().getSimpleName() + EventBusGenerator.IMPL_NAME).superclass(ParameterizedTypeName.get(abstractEventBusClassName, eventBusMetaMetaModel.getEventBus().getTypeName())).addModifiers(Modifier.PUBLIC, Modifier.FINAL).addSuperinterface(eventBusMetaMetaModel.getEventBus().getTypeName());
    MethodSpec constructor = MethodSpec.constructorBuilder().addModifiers(Modifier.PUBLIC).addStatement("super($S)", eventBusMetaMetaModel.getShell().getClassName()).build();
    typeSpec.addMethod(constructor);
    DebugGenerator.builder().eventBusMetaModel(eventBusMetaMetaModel).typeSpec(typeSpec).build().generate();
    FilterGenerator.builder().eventBusMetaModel(eventBusMetaMetaModel).typeSpec(typeSpec).build().generate();
    EventLoadMetaDataGenerator.builder().processingEnvironment(this.processingEnvironment).eventBusMetaModel(eventBusMetaMetaModel).typeSpec(typeSpec).build().generate();
    EventMetaDataGenerator.builder().processingEnvironment(this.processingEnvironment).eventBusMetaModel(eventBusMetaMetaModel).build().generate();
    EventHandlingMethodGenerator.builder().processorUtils(this.processorUtils).typeSpec(typeSpec).eventBusMetaModel(eventBusMetaMetaModel).historyMetaModel(historyMetaModel).presenterMetaModel(presenterMetaModel).handlerMetaModel(handlerMetaModel).build().generate();
    AddPresenterGenerator.builder().typeSpec(typeSpec).processingEnvironment(this.processingEnvironment).presenterMetaModel(presenterMetaModel).build().generate();
    HandlerAndPresenterRegristrationGenerator.builder().processingEnvironment(this.processingEnvironment).typeSpec(typeSpec).eventBusMetaModel(eventBusMetaMetaModel).presenterMetaModel(presenterMetaModel).handlerMetaModel(handlerMetaModel).build().generate();
    JavaFile javaFile = JavaFile.builder(eventBusMetaMetaModel.getEventBus().getPackage(), typeSpec.build()).build();
    // System.out.println(javaFile.toString());
    try {
        javaFile.writeTo(this.processingEnvironment.getFiler());
    } catch (IOException e) {
        throw new ProcessorException("Unable to write generated file: >>" + eventBusMetaMetaModel.getEventBus().getSimpleName() + EventBusGenerator.IMPL_NAME + "<< -> exception: " + e.getMessage());
    }
}
Also used : ProcessorException(com.github.mvp4g.mvp4g2.processor.ProcessorException) MethodSpec(com.squareup.javapoet.MethodSpec) ClassName(com.squareup.javapoet.ClassName) JavaFile(com.squareup.javapoet.JavaFile) IOException(java.io.IOException) TypeSpec(com.squareup.javapoet.TypeSpec)

Example 4 with HistoryMetaModel

use of com.github.mvp4g.mvp4g2.processor.model.HistoryMetaModel in project mvp4g2 by mvp4g.

the class HistoryGenerator method generate.

public void generate(HistoryMetaModel metaModel) throws ProcessorException {
    for (String historyConverterClassName : metaModel.getHistoryConverterClassNames()) {
        HistoryMetaModel.HistoryData historyData = metaModel.getHistoryData(historyConverterClassName);
        TypeSpec.Builder typeSpec = TypeSpec.classBuilder(this.processorUtils.createHistoryMetaDataClassName(historyData.getHistoryConverter().getClassName())).superclass(ClassName.get(HistoryMetaData.class)).addModifiers(Modifier.PUBLIC, Modifier.FINAL);
        // constructor ...
        MethodSpec constructor = MethodSpec.constructorBuilder().addModifiers(Modifier.PUBLIC).addStatement("super($S, $T.$L)", historyConverterClassName, ClassName.get(History.HistoryConverterType.class), historyData.getHistoryConverterType()).build();
        typeSpec.addMethod(constructor);
        JavaFile javaFile = JavaFile.builder(historyData.getHistoryConverter().getPackage(), typeSpec.build()).build();
        try {
            javaFile.writeTo(this.processingEnvironment.getFiler());
        } catch (IOException e) {
            throw new ProcessorException("Unable to write generated file: >>" + this.processorUtils.createHistoryMetaDataClassName(historyData.getHistoryConverter().getClassName()) + "<< -> exception: " + e.getMessage());
        }
    }
}
Also used : HistoryMetaModel(com.github.mvp4g.mvp4g2.processor.model.HistoryMetaModel) ProcessorException(com.github.mvp4g.mvp4g2.processor.ProcessorException) MethodSpec(com.squareup.javapoet.MethodSpec) JavaFile(com.squareup.javapoet.JavaFile) IOException(java.io.IOException) History(com.github.mvp4g.mvp4g2.core.history.annotation.History) TypeSpec(com.squareup.javapoet.TypeSpec)

Example 5 with HistoryMetaModel

use of com.github.mvp4g.mvp4g2.processor.model.HistoryMetaModel in project mvp4g2 by mvp4g.

the class PropertiesTest method testHistoryMetaModel.

@Test
public void testHistoryMetaModel() {
    Properties properties = new Properties();
    try {
        properties.load(ClassLoader.getSystemResourceAsStream("META-INF" + File.separator + "mvp4g2" + File.separator + "history.properties"));
    } catch (IOException e) {
        assert false : "IOException reading history.properties";
    }
    HistoryMetaModel metaModel = new HistoryMetaModel(properties);
    Properties newProperties = metaModel.createPropertes();
    assertEquals(properties, newProperties);
}
Also used : HistoryMetaModel(com.github.mvp4g.mvp4g2.processor.model.HistoryMetaModel) IOException(java.io.IOException) Properties(java.util.Properties) Test(org.junit.Test)

Aggregations

HistoryMetaModel (com.github.mvp4g.mvp4g2.processor.model.HistoryMetaModel)4 IOException (java.io.IOException)4 History (com.github.mvp4g.mvp4g2.core.history.annotation.History)2 ProcessorException (com.github.mvp4g.mvp4g2.processor.ProcessorException)2 JavaFile (com.squareup.javapoet.JavaFile)2 MethodSpec (com.squareup.javapoet.MethodSpec)2 TypeSpec (com.squareup.javapoet.TypeSpec)2 Properties (java.util.Properties)2 HistoryAnnotationValidator (com.github.mvp4g.mvp4g2.processor.scanner.validation.HistoryAnnotationValidator)1 ClassName (com.squareup.javapoet.ClassName)1 Element (javax.lang.model.element.Element)1 TypeElement (javax.lang.model.element.TypeElement)1 FileObject (javax.tools.FileObject)1 Test (org.junit.Test)1