Search in sources :

Example 1 with Transformation

use of io.quarkus.arc.processor.Transformation in project camel-quarkus by apache.

the class ConsumeProcessor method annotationsTransformers.

@BuildStep
void annotationsTransformers(BuildProducer<AnnotationsTransformerBuildItem> annotationsTransformers) {
    annotationsTransformers.produce(new AnnotationsTransformerBuildItem(new AnnotationsTransformer() {

        public boolean appliesTo(org.jboss.jandex.AnnotationTarget.Kind kind) {
            return kind == Kind.CLASS;
        }

        @Override
        public void transform(TransformationContext ctx) {
            final ClassInfo classInfo = ctx.getTarget().asClass();
            if (hasConsumeMethod(classInfo)) {
                /* If there is @Consume on a method, make the declaring class a named injectable bean */
                String beanName = namedValue(classInfo);
                final Transformation transform = ctx.transform();
                if (!classInfo.annotations().keySet().stream().anyMatch(BEAN_DEFINING_ANNOTATIONS::contains)) {
                    /* Only add @Singleton if there is no other bean defining annotation yet */
                    transform.add(Singleton.class);
                }
                if (beanName == null) {
                    beanName = ConsumeProcessor.uniqueBeanName(classInfo);
                    transform.add(Named.class, AnnotationValue.createStringValue("value", beanName));
                }
                transform.done();
            }
        }
    }));
}
Also used : AnnotationsTransformerBuildItem(io.quarkus.arc.deployment.AnnotationsTransformerBuildItem) Transformation(io.quarkus.arc.processor.Transformation) AnnotationsTransformer(io.quarkus.arc.processor.AnnotationsTransformer) Kind(org.jboss.jandex.AnnotationTarget.Kind) ClassInfo(org.jboss.jandex.ClassInfo) BuildStep(io.quarkus.deployment.annotations.BuildStep)

Aggregations

AnnotationsTransformerBuildItem (io.quarkus.arc.deployment.AnnotationsTransformerBuildItem)1 AnnotationsTransformer (io.quarkus.arc.processor.AnnotationsTransformer)1 Transformation (io.quarkus.arc.processor.Transformation)1 BuildStep (io.quarkus.deployment.annotations.BuildStep)1 Kind (org.jboss.jandex.AnnotationTarget.Kind)1 ClassInfo (org.jboss.jandex.ClassInfo)1