diff --git a/extensions/arc/deployment/src/main/java/io/quarkus/arc/deployment/TransformedAnnotationsBuildItem.java b/extensions/arc/deployment/src/main/java/io/quarkus/arc/deployment/TransformedAnnotationsBuildItem.java index 2e7bc1754e7cb2..45f91bbe407468 100644 --- a/extensions/arc/deployment/src/main/java/io/quarkus/arc/deployment/TransformedAnnotationsBuildItem.java +++ b/extensions/arc/deployment/src/main/java/io/quarkus/arc/deployment/TransformedAnnotationsBuildItem.java @@ -1,6 +1,7 @@ package io.quarkus.arc.deployment; import java.lang.annotation.Annotation; +import java.util.ArrayList; import java.util.Collection; import java.util.function.Function; @@ -27,11 +28,15 @@ public final class TransformedAnnotationsBuildItem extends SimpleBuildItem } public Collection getAnnotations(AnnotationTarget target) { - return beanDeployment.getAnnotations(target); + return queryAndConditionallyFilter(target); } public AnnotationInstance getAnnotation(AnnotationTarget target, DotName annotationName) { - return beanDeployment.getAnnotation(target, annotationName); + if (target.kind().equals(AnnotationTarget.Kind.METHOD_PARAMETER)) { + return queryForMethodParam(target, annotationName); + } else { + return beanDeployment.getAnnotation(target, annotationName); + } } public AnnotationInstance getAnnotation(AnnotationTarget target, Class annotationClass) { @@ -39,7 +44,11 @@ public AnnotationInstance getAnnotation(AnnotationTarget target, Class annotationClass) { @@ -48,7 +57,39 @@ public boolean hasAnnotation(AnnotationTarget target, Class apply(AnnotationTarget target) { - return beanDeployment.getAnnotations(target); + return queryAndConditionallyFilter(target); } + private Collection queryAndConditionallyFilter(AnnotationTarget target) { + if (target.kind().equals(AnnotationTarget.Kind.METHOD_PARAMETER)) { + // We cannot query Jandex for method param. annotation target, so we operate on the whole method + // and filter results accordingly + Collection result = new ArrayList<>(); + for (AnnotationInstance instance : beanDeployment.getAnnotations(target.asMethodParameter().method())) { + if (instance.target().kind().equals(AnnotationTarget.Kind.METHOD_PARAMETER) + && instance.target().asMethodParameter().position() == target.asMethodParameter().position()) { + result.add(instance); + } + } + return result; + } else { + return beanDeployment.getAnnotations(target); + } + } + + private AnnotationInstance queryForMethodParam(AnnotationTarget target, DotName annotationName) { + if (!target.kind().equals(AnnotationTarget.Kind.METHOD_PARAMETER)) { + throw new IllegalArgumentException( + "TransformedAnnotationsBuildItem#queryForMethodParam needs to operate on METHOD_PARAMETER AnnotationTarget"); + } + // We cannot query Jandex for method param. annotation target, so we operate on the whole method + // and filter results accordingly + AnnotationInstance instance = beanDeployment.getAnnotation(target.asMethodParameter().method(), annotationName); + if (instance.target().kind().equals(AnnotationTarget.Kind.METHOD_PARAMETER) + && instance.target().asMethodParameter().position() == target.asMethodParameter().position()) { + return instance; + } else { + return null; + } + } } diff --git a/extensions/smallrye-reactive-messaging/deployment/src/main/java/io/quarkus/smallrye/reactivemessaging/deployment/WiringHelper.java b/extensions/smallrye-reactive-messaging/deployment/src/main/java/io/quarkus/smallrye/reactivemessaging/deployment/WiringHelper.java index 4202be7d67d666..b42927e3277718 100644 --- a/extensions/smallrye-reactive-messaging/deployment/src/main/java/io/quarkus/smallrye/reactivemessaging/deployment/WiringHelper.java +++ b/extensions/smallrye-reactive-messaging/deployment/src/main/java/io/quarkus/smallrye/reactivemessaging/deployment/WiringHelper.java @@ -11,7 +11,6 @@ import org.eclipse.microprofile.config.ConfigProvider; import org.jboss.jandex.AnnotationInstance; -import org.jboss.jandex.AnnotationTarget; import org.jboss.jandex.AnnotationValue; import org.jboss.jandex.ClassInfo; import org.jboss.jandex.DotName; @@ -264,21 +263,13 @@ static boolean isSynthetic(MethodInfo method) { static Optional getAnnotation(TransformedAnnotationsBuildItem transformedAnnotations, InjectionPointInfo injectionPoint, DotName annotationName) { - // Query annotations for either field, or whole method - AnnotationTarget annotationTarget = injectionPoint.isField() ? injectionPoint.getAnnotationTarget() - : injectionPoint.getAnnotationTarget().asMethodParameter().method(); - Collection annotations = transformedAnnotations.getAnnotations(annotationTarget); + // For field IP -> set of field annotations + // For method param IP -> set of param annotations + Collection annotations = transformedAnnotations + .getAnnotations(injectionPoint.getAnnotationTarget()); for (AnnotationInstance annotation : annotations) { if (annotationName.equals(annotation.name())) { - // For method parameter we must check the position - if (annotation.target().kind() == AnnotationTarget.Kind.METHOD_PARAMETER - && injectionPoint.isParam() - && annotation.target().asMethodParameter().position() == injectionPoint.getPosition()) { - return Optional.of(annotation); - } else if (annotation.target().kind() != AnnotationTarget.Kind.METHOD_PARAMETER) { - // For other kind, no need to check anything else - return Optional.of(annotation); - } + return Optional.of(annotation); } } return Optional.empty();