Search in sources :

Example 6 with EventMetaModel

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

the class EventAnnotationScanner method restore.

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

Example 7 with EventMetaModel

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

the class EventAnnotationScanner method scan.

public EventBusMetaModel scan(RoundEnvironment roundEnvironment) throws ProcessorException {
    EventAnnotationValidator eventAnnotationValidator = EventAnnotationValidator.builder().roundEnvironment(roundEnvironment).processingEnvironment(processingEnvironment).eventBusMetaModel(this.eventBusMetaModel).eventBusTypeElement(eventBusTypeElement).build();
    // validate event bus
    eventAnnotationValidator.validate();
    // handle events
    for (Element element : roundEnvironment.getElementsAnnotatedWith(Event.class)) {
        // do validation
        EventAnnotationValidator.builder().roundEnvironment(roundEnvironment).processingEnvironment(processingEnvironment).eventBusMetaModel(this.eventBusMetaModel).eventBusTypeElement(eventBusTypeElement).build().validate(element);
        ExecutableElement executableElement = (ExecutableElement) element;
        // restore meta data (if there is one)
        // First we try to read an already created resource ...
        EventMetaModel model = this.restore(element);
        // get event annoation
        Event eventAnnotation = element.getAnnotation(Event.class);
        // scan for data
        // internal event name
        model.setEventInternalName(this.processorUtils.createInternalEventName(executableElement));
        // event name
        model.setEventName(executableElement.getSimpleName().toString());
        // history name of hte event
        model.setHistoryEventName(eventAnnotation.historyName());
        // navigation event
        model.setNavigationEvent(Boolean.toString(eventAnnotation.navigationEvent()));
        // passive
        model.setPassive(Boolean.toString(eventAnnotation.passive()));
        // handlers
        model.setHandlers(this.getElementsFromAnnotationAsList(executableElement, "handlers"));
        // List of binding handlers (full class names as String)
        model.setBindings(this.getElementsFromAnnotationAsList(executableElement, "bind"));
        // List of activate handlers (full class names as String)
        model.setActivateHandlers(this.getElementsFromAnnotationAsList(executableElement, "activate"));
        // List of deactivate handlers (full class names as String)
        model.setDeactivateHandlers(this.getElementsFromAnnotationAsList(executableElement, "deactivate"));
        // history converter
        model.setHistoryConverter(Objects.requireNonNull(this.getHistoryConverterTypeElement(eventAnnotation)).getQualifiedName().toString());
        // start event?
        model.setStartEvent(isNull(executableElement.getAnnotation(Start.class)) ? "false" : "true");
        // initHistory event?
        model.setInitHistory(isNull(executableElement.getAnnotation(InitHistory.class)) ? "false" : "true");
        // start event?
        model.setNotFoundHistory(isNull(executableElement.getAnnotation(NotFoundHistory.class)) ? "false" : "true");
        // parameters
        executableElement.getParameters().forEach(v -> model.addParameter(v.getSimpleName().toString(), v.asType().toString()));
        // let's store the updated model
        this.processorUtils.store(model, this.createRelativeFileName(element));
        // store the event meta data model in the eventbus meta data model
        this.eventBusMetaModel.add(model);
    }
    return this.eventBusMetaModel;
}
Also used : InitHistory(com.github.mvp4g.mvp4g2.core.history.annotation.InitHistory) NotFoundHistory(com.github.mvp4g.mvp4g2.core.history.annotation.NotFoundHistory) EventAnnotationValidator(com.github.mvp4g.mvp4g2.processor.scanner.validation.EventAnnotationValidator) Start(com.github.mvp4g.mvp4g2.core.eventbus.annotation.Start) TypeElement(javax.lang.model.element.TypeElement) ExecutableElement(javax.lang.model.element.ExecutableElement) Element(javax.lang.model.element.Element) ExecutableElement(javax.lang.model.element.ExecutableElement) Event(com.github.mvp4g.mvp4g2.core.eventbus.annotation.Event) EventMetaModel(com.github.mvp4g.mvp4g2.processor.model.EventMetaModel)

Example 8 with EventMetaModel

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

the class EventBusAnnotationScanner method restore.

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

Aggregations

EventMetaModel (com.github.mvp4g.mvp4g2.processor.model.EventMetaModel)8 IOException (java.io.IOException)5 EventBusMetaModel (com.github.mvp4g.mvp4g2.processor.model.EventBusMetaModel)4 Properties (java.util.Properties)4 Event (com.github.mvp4g.mvp4g2.core.eventbus.annotation.Event)2 EventMetaData (com.github.mvp4g.mvp4g2.core.internal.eventbus.EventMetaData)2 ProcessorException (com.github.mvp4g.mvp4g2.processor.ProcessorException)2 ProcessorUtils (com.github.mvp4g.mvp4g2.processor.ProcessorUtils)2 HandlerMetaModel (com.github.mvp4g.mvp4g2.processor.model.HandlerMetaModel)2 PresenterMetaModel (com.github.mvp4g.mvp4g2.processor.model.PresenterMetaModel)2 MethodSpec (com.squareup.javapoet.MethodSpec)2 TypeSpec (com.squareup.javapoet.TypeSpec)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 IntStream (java.util.stream.IntStream)2 ExecutableElement (javax.lang.model.element.ExecutableElement)2 TypeElement (javax.lang.model.element.TypeElement)2 FileObject (javax.tools.FileObject)2 Test (org.junit.Test)2 Start (com.github.mvp4g.mvp4g2.core.eventbus.annotation.Start)1