use of io.quarkus.arc.processor.Annotations in project quarkus by quarkusio.
the class MicrometerProcessor method registerAdditionalBeans.
@BuildStep(onlyIf = MicrometerEnabled.class)
UnremovableBeanBuildItem registerAdditionalBeans(CombinedIndexBuildItem indexBuildItem, BuildProducer<MicrometerRegistryProviderBuildItem> providerClasses, BuildProducer<ReflectiveClassBuildItem> reflectiveClasses, BuildProducer<AdditionalBeanBuildItem> additionalBeans, BuildProducer<InterceptorBindingRegistrarBuildItem> interceptorBindings) {
// Create and keep some basic Providers
additionalBeans.produce(AdditionalBeanBuildItem.builder().setUnremovable().addBeanClass(ClockProvider.class).addBeanClass(CompositeRegistryCreator.class).build());
// Add annotations and associated interceptors
additionalBeans.produce(AdditionalBeanBuildItem.builder().addBeanClass(MeterFilterConstraint.class).addBeanClass(MeterFilterConstraints.class).addBeanClass(TIMED_ANNOTATION.toString()).addBeanClass(TIMED_INTERCEPTOR.toString()).addBeanClass(COUNTED_ANNOTATION.toString()).addBeanClass(COUNTED_BINDING.toString()).addBeanClass(COUNTED_INTERCEPTOR.toString()).build());
// @Timed is registered as an additional interceptor binding
interceptorBindings.produce(new InterceptorBindingRegistrarBuildItem(new InterceptorBindingRegistrar() {
@Override
public List<InterceptorBinding> getAdditionalBindings() {
return List.of(InterceptorBinding.of(Timed.class, m -> true));
}
}));
IndexView index = indexBuildItem.getIndex();
reflectiveClasses.produce(createReflectiveBuildItem(COUNTED_ANNOTATION, index));
reflectiveClasses.produce(createReflectiveBuildItem(TIMED_ANNOTATION, index));
reflectiveClasses.produce(ReflectiveClassBuildItem.builder("org.HdrHistogram.Histogram", "org.HdrHistogram.DoubleHistogram", "org.HdrHistogram.ConcurrentHistogram").constructors(true).build());
return UnremovableBeanBuildItem.beanTypes(METER_REGISTRY, METER_BINDER, METER_FILTER, NAMING_CONVENTION);
}
use of io.quarkus.arc.processor.Annotations in project quarkus by quarkusio.
the class AnnotationHandler method transformAnnotations.
static AnnotationsTransformerBuildItem transformAnnotations(final IndexView index, DotName sourceAnnotation, DotName targetAnnotation) {
return new AnnotationsTransformerBuildItem(new AnnotationsTransformer() {
@Override
public void transform(TransformationContext ctx) {
final Collection<AnnotationInstance> annotations = ctx.getAnnotations();
AnnotationInstance annotation = Annotations.find(annotations, sourceAnnotation);
if (annotation == null) {
return;
}
AnnotationTarget target = ctx.getTarget();
ClassInfo classInfo = null;
MethodInfo methodInfo = null;
FieldInfo fieldInfo = null;
if (ctx.isMethod()) {
methodInfo = target.asMethod();
classInfo = methodInfo.declaringClass();
} else if (ctx.isField()) {
fieldInfo = target.asField();
classInfo = fieldInfo.declaringClass();
} else if (ctx.isClass()) {
classInfo = target.asClass();
// skip @Interceptor
if (target.asClass().classAnnotation(DotNames.INTERCEPTOR) != null) {
return;
}
}
// Ignore @Metric with @Produces
if (removeCountedWhenTimed(sourceAnnotation, target, classInfo, methodInfo) || removeMetricWhenProduces(sourceAnnotation, target, methodInfo, fieldInfo)) {
ctx.transform().remove(x -> x == annotation).done();
return;
}
// Make sure all attributes exist:
MetricAnnotationInfo annotationInfo = new MetricAnnotationInfo(annotation, index, classInfo, methodInfo, fieldInfo);
// Remove the existing annotation, and add a new one with all the fields
ctx.transform().remove(x -> x == annotation).add(targetAnnotation, annotationInfo.getAnnotationValues()).done();
}
});
}
Aggregations