Search in sources :

Example 1 with AnnotationStore

use of io.quarkus.arc.processor.AnnotationStore in project quarkus by quarkusio.

the class SpringScheduledProcessor method collectScheduledMethods.

@BuildStep
void collectScheduledMethods(BeanRegistrationPhaseBuildItem beanRegistrationPhase, BuildProducer<ScheduledBusinessMethodItem> scheduledBusinessMethods) {
    AnnotationStore annotationStore = beanRegistrationPhase.getContext().get(BuildExtension.Key.ANNOTATION_STORE);
    for (BeanInfo bean : beanRegistrationPhase.getContext().beans().classBeans()) {
        ClassInfo classInfo = bean.getTarget().get().asClass();
        for (MethodInfo method : classInfo.methods()) {
            List<AnnotationInstance> schedules = null;
            AnnotationInstance scheduledAnnotation = annotationStore.getAnnotation(method, SPRING_SCHEDULED);
            if (scheduledAnnotation != null) {
                schedules = Collections.singletonList(scheduledAnnotation);
            } else {
                AnnotationInstance schedulesAnnotation = annotationStore.getAnnotation(method, SPRING_SCHEDULES);
                if (schedulesAnnotation != null) {
                    schedules = new ArrayList<>();
                    for (AnnotationInstance scheduledInstance : schedulesAnnotation.value().asNestedArray()) {
                        schedules.add(AnnotationInstance.create(scheduledInstance.name(), schedulesAnnotation.target(), scheduledInstance.values()));
                    }
                }
            }
            processSpringScheduledAnnotation(scheduledBusinessMethods, bean, method, schedules);
        }
    }
}
Also used : BeanInfo(io.quarkus.arc.processor.BeanInfo) MethodInfo(org.jboss.jandex.MethodInfo) AnnotationStore(io.quarkus.arc.processor.AnnotationStore) AnnotationInstance(org.jboss.jandex.AnnotationInstance) ClassInfo(org.jboss.jandex.ClassInfo) BuildStep(io.quarkus.deployment.annotations.BuildStep)

Example 2 with AnnotationStore

use of io.quarkus.arc.processor.AnnotationStore in project quarkus by quarkusio.

the class VertxProcessor method collectEventConsumers.

@BuildStep
void collectEventConsumers(BeanRegistrationPhaseBuildItem beanRegistrationPhase, BuildProducer<EventConsumerBusinessMethodItem> messageConsumerBusinessMethods, BuildProducer<BeanConfiguratorBuildItem> errors) {
    // We need to collect all business methods annotated with @ConsumeEvent first
    AnnotationStore annotationStore = beanRegistrationPhase.getContext().get(BuildExtension.Key.ANNOTATION_STORE);
    for (BeanInfo bean : beanRegistrationPhase.getContext().beans().classBeans()) {
        for (MethodInfo method : bean.getTarget().get().asClass().methods()) {
            AnnotationInstance consumeEvent = annotationStore.getAnnotation(method, CONSUME_EVENT);
            if (consumeEvent != null) {
                // Validate method params and return type
                List<Type> params = method.parameters();
                if (params.size() != 1) {
                    throw new IllegalStateException(String.format("An event consumer business method must accept exactly one parameter: %s [method: %s, bean:%s]", params, method, bean));
                }
                if (method.returnType().kind() != Kind.VOID && VertxConstants.isMessage(params.get(0).name())) {
                    throw new IllegalStateException(String.format("An event consumer business method that accepts io.vertx.core.eventbus.Message or io.vertx.mutiny.core.eventbus.Message must return void [method: %s, bean:%s]", method, bean));
                }
                messageConsumerBusinessMethods.produce(new EventConsumerBusinessMethodItem(bean, method, consumeEvent));
                LOGGER.debugf("Found event consumer business method %s declared on %s", method, bean);
            }
        }
    }
}
Also used : Type(org.jboss.jandex.Type) BeanInfo(io.quarkus.arc.processor.BeanInfo) MethodInfo(org.jboss.jandex.MethodInfo) AnnotationStore(io.quarkus.arc.processor.AnnotationStore) AnnotationInstance(org.jboss.jandex.AnnotationInstance) BuildStep(io.quarkus.deployment.annotations.BuildStep)

Aggregations

AnnotationStore (io.quarkus.arc.processor.AnnotationStore)2 BeanInfo (io.quarkus.arc.processor.BeanInfo)2 BuildStep (io.quarkus.deployment.annotations.BuildStep)2 AnnotationInstance (org.jboss.jandex.AnnotationInstance)2 MethodInfo (org.jboss.jandex.MethodInfo)2 ClassInfo (org.jboss.jandex.ClassInfo)1 Type (org.jboss.jandex.Type)1