diff --git a/extensions/arc/deployment/src/main/java/io/quarkus/arc/deployment/ConfigBuildStep.java b/extensions/arc/deployment/src/main/java/io/quarkus/arc/deployment/ConfigBuildStep.java index e553cca9386e58..2e4343ed1d1da4 100644 --- a/extensions/arc/deployment/src/main/java/io/quarkus/arc/deployment/ConfigBuildStep.java +++ b/extensions/arc/deployment/src/main/java/io/quarkus/arc/deployment/ConfigBuildStep.java @@ -14,7 +14,7 @@ import static org.jboss.jandex.AnnotationInstance.create; import static org.jboss.jandex.AnnotationTarget.Kind.CLASS; import static org.jboss.jandex.AnnotationTarget.Kind.FIELD; -import static org.jboss.jandex.AnnotationTarget.Kind.METHOD; +import static org.jboss.jandex.AnnotationTarget.Kind.METHOD_PARAMETER; import static org.jboss.jandex.AnnotationValue.createStringValue; import java.util.ArrayList; @@ -42,6 +42,7 @@ import org.jboss.jandex.DotName; import org.jboss.jandex.FieldInfo; import org.jboss.jandex.MethodInfo; +import org.jboss.jandex.MethodParameterInfo; import org.jboss.jandex.Type; import org.jboss.jandex.Type.Kind; @@ -174,12 +175,12 @@ void configPropertyInjectionPoints( } else { // org.acme.Foo.config if (injectionPoint.isField()) { - FieldInfo field = injectionPoint.getTarget().asField(); + FieldInfo field = injectionPoint.getAnnotationTarget().asField(); propertyName = getPropertyName(field.name(), field.declaringClass()); } else if (injectionPoint.isParam()) { - MethodInfo method = injectionPoint.getTarget().asMethod(); - propertyName = getPropertyName(method.parameterName(injectionPoint.getPosition()), - method.declaringClass()); + MethodParameterInfo methodParameterInfo = injectionPoint.getAnnotationTarget().asMethodParameter(); + propertyName = getPropertyName(methodParameterInfo.name(), + methodParameterInfo.method().declaringClass()); } else { throw new IllegalStateException("Unsupported injection point target: " + injectionPoint); } @@ -205,8 +206,8 @@ void configPropertyInjectionPoints( propertyDefaultValue = defaultValue.asString(); } - if (injectionPoint.getTarget().kind().equals(METHOD) - && observerMethods.contains(injectionPoint.getTarget().asMethod())) { + if (injectionPoint.getAnnotationTarget().kind().equals(METHOD_PARAMETER) + && observerMethods.contains(injectionPoint.getAnnotationTarget().asMethodParameter().method())) { configProperties .produce(ConfigPropertyBuildItem.staticInit(propertyName, injectedType, propertyDefaultValue)); } @@ -405,19 +406,17 @@ void validateConfigMappingsInjectionPoints( Type type = Type.create(injectionPoint.getRequiredType().name(), Type.Kind.CLASS); ConfigClassBuildItem configClass = configMappingTypes.get(type); if (configClass != null) { - AnnotationTarget target = injectionPoint.getTarget(); + AnnotationTarget target = injectionPoint.getAnnotationTarget(); AnnotationInstance mapping = null; if (target.kind().equals(FIELD)) { mapping = target.asField().annotation(CONFIG_MAPPING_NAME); - } else if (target.kind().equals(METHOD)) { - List parameters = target.asMethod().parameterTypes(); - for (int i = 0; i < parameters.size(); i++) { - Type parameter = parameters.get(i); - if (parameter.name().equals(type.name())) { - Set parameterAnnotations = getParameterAnnotations( - validationPhase.getBeanProcessor().getBeanDeployment(), target.asMethod(), i); - mapping = Annotations.find(parameterAnnotations, CONFIG_MAPPING_NAME); - } + } else if (target.kind().equals(METHOD_PARAMETER)) { + MethodParameterInfo methodParameterInfo = target.asMethodParameter(); + if (methodParameterInfo.type().name().equals(type.name())) { + Set parameterAnnotations = getParameterAnnotations( + validationPhase.getBeanProcessor().getBeanDeployment(), + target.asMethodParameter().method(), methodParameterInfo.position()); + mapping = Annotations.find(parameterAnnotations, CONFIG_MAPPING_NAME); } } diff --git a/extensions/grpc/deployment/src/main/java/io/quarkus/grpc/deployment/GrpcClientProcessor.java b/extensions/grpc/deployment/src/main/java/io/quarkus/grpc/deployment/GrpcClientProcessor.java index e66fef8f2e7ef4..7ebe1ee1821931 100644 --- a/extensions/grpc/deployment/src/main/java/io/quarkus/grpc/deployment/GrpcClientProcessor.java +++ b/extensions/grpc/deployment/src/main/java/io/quarkus/grpc/deployment/GrpcClientProcessor.java @@ -346,22 +346,17 @@ public void transform(TransformationContext ctx) { AnnotationInstance clientAnnotation = Annotations.find(ctx.getQualifiers(), GrpcDotNames.GRPC_CLIENT); if (clientAnnotation != null && clientAnnotation.value() == null) { String clientName = null; - AnnotationTarget annotationTarget = ctx.getTarget(); - if (ctx.getTarget().kind() == Kind.FIELD) { + AnnotationTarget annotationTarget = ctx.getAnnotationTarget(); + if (ctx.getAnnotationTarget().kind() == Kind.FIELD) { clientName = clientAnnotation.target().asField().name(); - } else if (ctx.getTarget().kind() == Kind.METHOD - && clientAnnotation.target().kind().equals(Kind.METHOD_PARAMETER)) { + } else if (annotationTarget.kind() == Kind.METHOD_PARAMETER) { MethodParameterInfo param = clientAnnotation.target().asMethodParameter(); - annotationTarget = param; // We don't need to check if parameter names are recorded - that's validated elsewhere clientName = param.method().parameterName(param.position()); } if (clientName != null) { ctx.transform().remove(GrpcDotNames::isGrpcClient) - .add(AnnotationInstance.builder(GrpcDotNames.GRPC_CLIENT) - .value(clientName) - .buildWithTarget(annotationTarget)) - .done(); + .add(GrpcDotNames.GRPC_CLIENT, AnnotationValue.createStringValue("value", clientName)).done(); } } } diff --git a/extensions/qute/deployment/src/main/java/io/quarkus/qute/deployment/QuteProcessor.java b/extensions/qute/deployment/src/main/java/io/quarkus/qute/deployment/QuteProcessor.java index 67282afd1c3dbc..39b225344a89dc 100644 --- a/extensions/qute/deployment/src/main/java/io/quarkus/qute/deployment/QuteProcessor.java +++ b/extensions/qute/deployment/src/main/java/io/quarkus/qute/deployment/QuteProcessor.java @@ -3341,10 +3341,10 @@ static void collectNamespaceExpressions(Expression expression, Set n public static String getName(InjectionPointInfo injectionPoint) { if (injectionPoint.isField()) { - return injectionPoint.getTarget().asField().name(); + return injectionPoint.getAnnotationTarget().asField().name(); } else if (injectionPoint.isParam()) { - String name = injectionPoint.getTarget().asMethod().parameterName(injectionPoint.getPosition()); - return name == null ? injectionPoint.getTarget().asMethod().name() : name; + String name = injectionPoint.getAnnotationTarget().asMethodParameter().name(); + return name == null ? injectionPoint.getAnnotationTarget().asMethodParameter().method().name() : name; } throw new IllegalArgumentException(); } diff --git a/extensions/security-jpa/deployment/src/main/java/io/quarkus/security/jpa/deployment/QuarkusSecurityJpaProcessor.java b/extensions/security-jpa/deployment/src/main/java/io/quarkus/security/jpa/deployment/QuarkusSecurityJpaProcessor.java index a3a892bfe8399d..39960d1f3188c2 100644 --- a/extensions/security-jpa/deployment/src/main/java/io/quarkus/security/jpa/deployment/QuarkusSecurityJpaProcessor.java +++ b/extensions/security-jpa/deployment/src/main/java/io/quarkus/security/jpa/deployment/QuarkusSecurityJpaProcessor.java @@ -99,8 +99,8 @@ public boolean appliesTo(Type requiredType) { } public void transform(TransformationContext context) { - if (context.getTarget().kind() == AnnotationTarget.Kind.FIELD) { - var declaringClassName = context.getTarget().asField().declaringClass().name(); + if (context.getAnnotationTarget().kind() == AnnotationTarget.Kind.FIELD) { + var declaringClassName = context.getAnnotationTarget().asField().declaringClass().name(); if (JPA_IDENTITY_PROVIDER_NAME.equals(declaringClassName) || JPA_TRUSTED_IDENTITY_PROVIDER_NAME.equals(declaringClassName)) { context.transform() diff --git a/extensions/smallrye-context-propagation/deployment/src/main/java/io/quarkus/smallrye/context/deployment/SmallRyeContextPropagationProcessor.java b/extensions/smallrye-context-propagation/deployment/src/main/java/io/quarkus/smallrye/context/deployment/SmallRyeContextPropagationProcessor.java index 341986949891a2..fc6c4d6597fd0a 100644 --- a/extensions/smallrye-context-propagation/deployment/src/main/java/io/quarkus/smallrye/context/deployment/SmallRyeContextPropagationProcessor.java +++ b/extensions/smallrye-context-propagation/deployment/src/main/java/io/quarkus/smallrye/context/deployment/SmallRyeContextPropagationProcessor.java @@ -3,7 +3,6 @@ import java.io.IOException; import java.lang.reflect.InvocationTargetException; import java.util.ArrayList; -import java.util.Collection; import java.util.HashMap; import java.util.HashSet; import java.util.List; @@ -135,67 +134,40 @@ public void transform(TransformationContext transformationContext) { && !ann.name().equals(io.quarkus.arc.processor.DotNames.DEFAULT))) { return; } - AnnotationTarget target = transformationContext.getTarget(); + AnnotationTarget target = transformationContext.getAnnotationTarget(); + AnnotationInstance meConfigInstance = Annotations.find( + transformationContext.getAllAnnotationTargetAnnotations(), + DotNames.MANAGED_EXECUTOR_CONFIG); + AnnotationInstance tcConfigInstance = Annotations.find( + transformationContext.getAllAnnotationTargetAnnotations(), + DotNames.THREAD_CONTEXT_CONFIG); + String mpConfigIpName = null; if (target.kind().equals(AnnotationTarget.Kind.FIELD)) { - AnnotationInstance meConfigInstance = Annotations.find(transformationContext.getAllAnnotations(), - DotNames.MANAGED_EXECUTOR_CONFIG); - AnnotationInstance tcConfigInstance = Annotations.find(transformationContext.getAllAnnotations(), - DotNames.THREAD_CONTEXT_CONFIG); - if (meConfigInstance != null || tcConfigInstance != null) { // create a unique name based on the injection point - String mpConfigIpName = target.asField().declaringClass().name().toString() + mpConfigIpName = target.asField().declaringClass().name().toString() + NAME_DELIMITER + target.asField().name(); - - // add @NamedInstance with the generated name - transformationContext.transform() - .add(DotNames.NAMED_INSTANCE, AnnotationValue.createStringValue("value", mpConfigIpName)) - .done(); } - } else if (target.kind().equals(AnnotationTarget.Kind.METHOD)) { - // If it's method, we can have multiple parameters that we might need to configure and - // each injection point needs its own unique @NamedInstance. - // Finally, we register these annotation instance with the transformer. Note that when creating - // each annotation instance, we have to use AnnotationTarget of the _method parameter_ - Collection annotationsToAdd = new ArrayList<>(); - createRequiredAnnotationInstances(Annotations.getAnnotations(AnnotationTarget.Kind.METHOD_PARAMETER, - DotNames.MANAGED_EXECUTOR_CONFIG, transformationContext.getAllAnnotations()), - transformationContext.getQualifiers(), annotationsToAdd); - createRequiredAnnotationInstances(Annotations.getAnnotations(AnnotationTarget.Kind.METHOD_PARAMETER, - DotNames.THREAD_CONTEXT_CONFIG, transformationContext.getAllAnnotations()), - transformationContext.getQualifiers(), annotationsToAdd); - transformationContext.transform().addAll(annotationsToAdd).done(); + } else if (target.kind().equals(AnnotationTarget.Kind.METHOD_PARAMETER)) { + if (meConfigInstance != null || tcConfigInstance != null) { + // create a unique name based on the injection point + mpConfigIpName = target.asMethodParameter().method().declaringClass().name().toString() + + NAME_DELIMITER + + target.asMethodParameter().method().name() + + NAME_DELIMITER + + (target.asMethodParameter().position() + 1); + } } - } - }); - } - - private void createRequiredAnnotationInstances(Collection configAnnotationInstances, - Collection knownQualifiers, - Collection instancesToAdd) { - for (AnnotationInstance annotationInstance : configAnnotationInstances) { - if (annotationInstance.target().kind().equals(AnnotationTarget.Kind.METHOD_PARAMETER)) { - MethodParameterInfo methodParameterInfo = annotationInstance.target().asMethodParameter(); - // skip if the method param injection point has custom qualifiers on it (including @NamedInstance) - if (methodParameterInfo.annotations().stream() - .anyMatch(ann -> knownQualifiers.contains(ann) - && !ann.name().equals(io.quarkus.arc.processor.DotNames.ANY) - && !ann.name().equals(io.quarkus.arc.processor.DotNames.DEFAULT))) { - continue; + if (mpConfigIpName != null) { + // add @NamedInstance with the generated name + transformationContext.transform() + .add(DotNames.NAMED_INSTANCE, AnnotationValue.createStringValue("value", mpConfigIpName)) + .done(); } - String mpConfigIpName = methodParameterInfo.method().declaringClass().name().toString() - + NAME_DELIMITER - + methodParameterInfo.method().name() - + NAME_DELIMITER - + (methodParameterInfo.position() + 1); - // create a new AnnotationInstance with annotation target set to the respective _method parameter_ - instancesToAdd.add(AnnotationInstance.builder(DotNames.NAMED_INSTANCE) - .value(mpConfigIpName) - .buildWithTarget(methodParameterInfo)); } - } + }); } @BuildStep @@ -207,7 +179,7 @@ void createSynthBeansForConfiguredInjectionPoints(BuildProducer threadContextMap = new HashMap<>(); Set unconfiguredContextIPs = new HashSet<>(); for (InjectionPointInfo ipInfo : bdFinishedBuildItem.getInjectionPoints()) { - if (AnnotationTarget.Kind.FIELD.equals(ipInfo.getTarget().kind())) { + if (AnnotationTarget.Kind.FIELD.equals(ipInfo.getAnnotationTarget().kind())) { AnnotationInstance namedAnnotation = ipInfo.getRequiredQualifier(DotNames.NAMED_INSTANCE); // only look for IP with @NamedInstance on it because the IP transformation made sure it's there if (namedAnnotation == null) { @@ -220,9 +192,9 @@ void createSynthBeansForConfiguredInjectionPoints(BuildProducer cleared = providersToStringSet(plan.clearedProviders); assertTrue(propagated.isEmpty()); assertTrue(cleared.contains(ThreadContext.CDI)); + + exec = unwrapExecutor(ctorExecutor3); + assertEquals(2, exec.getMaxAsync()); + assertEquals(-1, exec.getMaxQueued()); // default value } } 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 f54afe684ac43e..4202be7d67d666 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 @@ -264,7 +264,10 @@ static boolean isSynthetic(MethodInfo method) { static Optional getAnnotation(TransformedAnnotationsBuildItem transformedAnnotations, InjectionPointInfo injectionPoint, DotName annotationName) { - Collection annotations = transformedAnnotations.getAnnotations(injectionPoint.getTarget()); + // Query annotations for either field, or whole method + AnnotationTarget annotationTarget = injectionPoint.isField() ? injectionPoint.getAnnotationTarget() + : injectionPoint.getAnnotationTarget().asMethodParameter().method(); + Collection annotations = transformedAnnotations.getAnnotations(annotationTarget); for (AnnotationInstance annotation : annotations) { if (annotationName.equals(annotation.name())) { // For method parameter we must check the position diff --git a/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/AnnotationsTransformation.java b/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/AnnotationsTransformation.java index 43c58c0593824e..dd47d992a9cf3d 100644 --- a/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/AnnotationsTransformation.java +++ b/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/AnnotationsTransformation.java @@ -46,6 +46,7 @@ public interface AnnotationsTransformation annotationType, AnnotationValue... values); + // TODO this isn't really right for IP transformations anymore? /** * NOTE: The annotation target is derived from the transformation context.. If you need to add an annotation instance * to a method parameter use methods consuming {@link AnnotationInstance} directly and supply the correct diff --git a/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/BeanGenerator.java b/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/BeanGenerator.java index 4f93c4bed7548c..2e41703a0e0028 100644 --- a/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/BeanGenerator.java +++ b/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/BeanGenerator.java @@ -1795,7 +1795,7 @@ void implementCreateForClassBean(ClassOutput classOutput, ClassCreator beanCreat // We cannot use injectionPoint.getRequiredType() because it might be a resolved parameterize type and we could get NoSuchFieldError tryBlock.writeInstanceField( FieldDescriptor.of(injectedField.declaringClass().name().toString(), injectedField.name(), - DescriptorUtils.typeToString(injectionPoint.getTarget().asField().type())), + DescriptorUtils.typeToString(injectionPoint.getAnnotationTarget().asField().type())), instanceHandle, referenceHandle); } CatchBlockCreator catchBlock = tryBlock.addCatch(RuntimeException.class); @@ -2288,13 +2288,13 @@ public static ResultHandle getJavaMemberHandle(MethodCreator bytecode, Injection if (injectionPoint.isSynthetic()) { javaMemberHandle = bytecode.loadNull(); } else if (injectionPoint.isField()) { - FieldInfo field = injectionPoint.getTarget().asField(); + FieldInfo field = injectionPoint.getAnnotationTarget().asField(); javaMemberHandle = bytecode.invokeStaticMethod(MethodDescriptors.REFLECTIONS_FIND_FIELD, bytecode.loadClass(field.declaringClass().name().toString()), bytecode.load(field.name())); reflectionRegistration.registerField(field); } else { - MethodInfo method = injectionPoint.getTarget().asMethod(); + MethodInfo method = injectionPoint.getAnnotationTarget().asMethodParameter().method(); reflectionRegistration.registerMethod(method); if (method.name().equals(Methods.INIT)) { // Reflections.findConstructor(org.foo.SimpleBean.class,java.lang.String.class) @@ -2333,11 +2333,11 @@ public static ResultHandle collectInjectionPointAnnotations(BeanDeployment beanD } ResultHandle annotationsHandle = bytecode.newInstance(MethodDescriptor.ofConstructor(HashSet.class)); Collection annotations; - if (Kind.FIELD.equals(injectionPoint.getTarget().kind())) { - FieldInfo field = injectionPoint.getTarget().asField(); + if (Kind.FIELD.equals(injectionPoint.getAnnotationTarget().kind())) { + FieldInfo field = injectionPoint.getAnnotationTarget().asField(); annotations = beanDeployment.getAnnotations(field); } else { - MethodInfo method = injectionPoint.getTarget().asMethod(); + MethodInfo method = injectionPoint.getAnnotationTarget().asMethodParameter().method(); annotations = Annotations.getParameterAnnotations(beanDeployment, method, injectionPoint.getPosition()); } diff --git a/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/BuiltinBean.java b/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/BuiltinBean.java index f8f3c8865f9088..46f2029b164e71 100644 --- a/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/BuiltinBean.java +++ b/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/BuiltinBean.java @@ -371,9 +371,9 @@ private static void generateListBytecode(GeneratorContext ctx) { // Register injection point for reflection InjectionPointInfo injectionPoint = ctx.injectionPoint; if (injectionPoint.isField()) { - ctx.reflectionRegistration.registerField(injectionPoint.getTarget().asField()); + ctx.reflectionRegistration.registerField(injectionPoint.getAnnotationTarget().asField()); } else { - ctx.reflectionRegistration.registerMethod(injectionPoint.getTarget().asMethod()); + ctx.reflectionRegistration.registerMethod(injectionPoint.getAnnotationTarget().asMethodParameter().method()); } MethodCreator mc = ctx.constructor; @@ -464,9 +464,9 @@ private static void validateList(InjectionTargetInfo injectionTarget, InjectionP if (typeParam.kind() == Type.Kind.WILDCARD_TYPE) { ClassInfo declaringClass; if (injectionPoint.isField()) { - declaringClass = injectionPoint.getTarget().asField().declaringClass(); + declaringClass = injectionPoint.getAnnotationTarget().asField().declaringClass(); } else { - declaringClass = injectionPoint.getTarget().asMethod().declaringClass(); + declaringClass = injectionPoint.getAnnotationTarget().asMethodParameter().method().declaringClass(); } if (isKotlinClass(declaringClass)) { errors.accept( diff --git a/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/Injection.java b/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/Injection.java index 8fd934b1b255bb..76daa01ec79853 100644 --- a/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/Injection.java +++ b/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/Injection.java @@ -90,18 +90,18 @@ private static void validateInjections(InjectionPointInfo injectionPointInfo, Be && injectionPointInfo.getRequiredType().asParameterizedType().arguments().size() == 1 && injectionPointInfo.hasDefaultedQualifier()) { Type actualType = injectionPointInfo.getRequiredType().asParameterizedType().arguments().get(0); - AnnotationTarget ipTarget = injectionPointInfo.getTarget(); + AnnotationTarget ipTarget = injectionPointInfo.getAnnotationTarget(); DotName expectedType = null; if (ipTarget.kind() == Kind.FIELD) { // field injection derives this from the class expectedType = ipTarget.asField().declaringClass().name(); - } else if (ipTarget.kind() == Kind.METHOD) { + } else if (ipTarget.kind() == Kind.METHOD_PARAMETER) { // the injection point is a producer method parameter then the type parameter of the injected Bean // must be the same as the producer method return type if (beanType == BeanType.PRODUCER_METHOD) { - expectedType = ipTarget.asMethod().returnType().name(); + expectedType = ipTarget.asMethodParameter().method().returnType().name(); } else { - expectedType = ipTarget.asMethod().declaringClass().name(); + expectedType = ipTarget.asMethodParameter().method().declaringClass().name(); } } if (expectedType != null @@ -137,12 +137,12 @@ private static void validateInjections(InjectionPointInfo injectionPointInfo, Be && injectionPointInfo.getRequiredType().kind() == Type.Kind.PARAMETERIZED_TYPE && injectionPointInfo.getRequiredType().asParameterizedType().arguments().size() == 1) { Type actualType = injectionPointInfo.getRequiredType().asParameterizedType().arguments().get(0); - AnnotationTarget ipTarget = injectionPointInfo.getTarget(); + AnnotationTarget ipTarget = injectionPointInfo.getAnnotationTarget(); DotName expectedType = null; if (ipTarget.kind() == Kind.FIELD) { expectedType = ipTarget.asField().declaringClass().name(); - } else if (ipTarget.kind() == Kind.METHOD) { - expectedType = ipTarget.asMethod().declaringClass().name(); + } else if (ipTarget.kind() == Kind.METHOD_PARAMETER) { + expectedType = ipTarget.asMethodParameter().method().declaringClass().name(); } if (expectedType != null // This is very rudimentary check, might need to be expanded? diff --git a/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/Types.java b/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/Types.java index f38cc68397816b..3960051e04b96c 100644 --- a/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/Types.java +++ b/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/Types.java @@ -713,10 +713,10 @@ static Set getDelegateTypeClosure(InjectionPointInfo delegateInjectionPoin throw new IllegalArgumentException("Delegate type not found in index: " + delegateType); } if (Kind.CLASS.equals(delegateType.kind())) { - types = getTypeClosure(delegateTypeClass, delegateInjectionPoint.getTarget(), Collections.emptyMap(), + types = getTypeClosure(delegateTypeClass, delegateInjectionPoint.getAnnotationTarget(), Collections.emptyMap(), beanDeployment, null, unrestrictedBeanTypes); } else if (Kind.PARAMETERIZED_TYPE.equals(delegateType.kind())) { - types = getTypeClosure(delegateTypeClass, delegateInjectionPoint.getTarget(), + types = getTypeClosure(delegateTypeClass, delegateInjectionPoint.getAnnotationTarget(), buildResolvedMap(delegateType.asParameterizedType().arguments(), delegateTypeClass.typeParameters(), Collections.emptyMap(), beanDeployment.getBeanArchiveIndex()), beanDeployment, null, unrestrictedBeanTypes); diff --git a/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/bcextensions/InjectionPointInfoImpl.java b/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/bcextensions/InjectionPointInfoImpl.java index a4f99e34b50aa7..433fa0d6351e42 100644 --- a/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/bcextensions/InjectionPointInfoImpl.java +++ b/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/bcextensions/InjectionPointInfoImpl.java @@ -35,14 +35,11 @@ public Collection qualifiers() { @Override public DeclarationInfo declaration() { if (arcInjectionPointInfo.isField()) { - org.jboss.jandex.FieldInfo jandexField = arcInjectionPointInfo.getTarget().asField(); + org.jboss.jandex.FieldInfo jandexField = arcInjectionPointInfo.getAnnotationTarget().asField(); return new FieldInfoImpl(jandexIndex, annotationOverlay, jandexField); } else if (arcInjectionPointInfo.isParam()) { - org.jboss.jandex.MethodInfo jandexMethod = arcInjectionPointInfo.getTarget().asMethod(); - int parameterPosition = arcInjectionPointInfo.getPosition(); - org.jboss.jandex.MethodParameterInfo jandexParameter = org.jboss.jandex.MethodParameterInfo.create( - jandexMethod, (short) parameterPosition); - return new ParameterInfoImpl(jandexIndex, annotationOverlay, jandexParameter); + return new ParameterInfoImpl(jandexIndex, annotationOverlay, + arcInjectionPointInfo.getAnnotationTarget().asMethodParameter()); } else { throw new IllegalStateException("Unknown injection point: " + arcInjectionPointInfo); } diff --git a/independent-projects/arc/tests/src/test/java/io/quarkus/arc/test/buildextension/injectionPoints/InjectionPointTransformerTest.java b/independent-projects/arc/tests/src/test/java/io/quarkus/arc/test/buildextension/injectionPoints/InjectionPointTransformerTest.java index 807773e9b7948f..e66e1a8fca1abc 100644 --- a/independent-projects/arc/tests/src/test/java/io/quarkus/arc/test/buildextension/injectionPoints/InjectionPointTransformerTest.java +++ b/independent-projects/arc/tests/src/test/java/io/quarkus/arc/test/buildextension/injectionPoints/InjectionPointTransformerTest.java @@ -54,6 +54,7 @@ public void testQualifierWasAddedToInjectionPoint() { Arc.container().beanManager().getEvent().select(Integer.class).fire(42); CasualObserver observer = arc.instance(CasualObserver.class).get(); assertEquals("bar", observer.getChangedString()); + assertEquals("foo", observer.getChanged2String()); assertEquals("foo", observer.getUnchangedString()); } @@ -103,11 +104,14 @@ public String getFoo() { static class CasualObserver { String changeMe; + String changeMe2; String dontChangeMe; // there is no String with qualifier @AnotherQualifier, we will remove it - public void observe(@Observes Integer payload, @AnotherQualifier String changeMe, @MyQualifier String dontChangeMe) { + public void observe(@Observes Integer payload, @AnotherQualifier String changeMe, @MyQualifier String dontChangeMe, + String changeMe2) { this.changeMe = changeMe; + this.changeMe2 = changeMe2; this.dontChangeMe = dontChangeMe; } @@ -115,6 +119,10 @@ public String getChangedString() { return changeMe; } + public String getChanged2String() { + return changeMe2; + } + public String getUnchangedString() { return dontChangeMe; } @@ -130,25 +138,29 @@ public boolean appliesTo(Type requiredType) { @Override public void transform(TransformationContext transformationContext) { - AnnotationTarget.Kind kind = transformationContext.getTarget().kind(); + AnnotationTarget.Kind kind = transformationContext.getAnnotationTarget().kind(); if (AnnotationTarget.Kind.FIELD.equals(kind)) { - FieldInfo fieldInfo = transformationContext.getTarget().asField(); + FieldInfo fieldInfo = transformationContext.getAnnotationTarget().asField(); // with this we should be able to filter out only fields we want to affect if (fieldInfo.declaringClass().name().equals(DotName.createSimple(SimpleConsumer.class.getName())) && fieldInfo.name().equals("foo")) { transformationContext.transform().add(MyQualifier.class).done(); } - } else if (AnnotationTarget.Kind.METHOD.equals(kind)) { - MethodInfo methodInfo = transformationContext.getTarget().asMethod(); + } else if (AnnotationTarget.Kind.METHOD_PARAMETER.equals(kind)) { + MethodInfo methodInfo = transformationContext.getAnnotationTarget().asMethodParameter().method(); DotName anotherQualifierDotName = DotName.createSimple(AnotherQualifier.class.getName()); if (methodInfo.declaringClass().name() - .equals(DotName.createSimple(CasualObserver.class.getName())) - && transformationContext.getAllAnnotations().stream() - .anyMatch(p -> p.name().equals(anotherQualifierDotName))) { - transformationContext.transform() - .remove(annotationInstance -> annotationInstance.name().equals(anotherQualifierDotName)) - .done(); + .equals(DotName.createSimple(CasualObserver.class.getName()))) { + if (transformationContext.getAllAnnotationTargetAnnotations().stream() + .anyMatch(p -> p.name().equals(anotherQualifierDotName))) { + transformationContext.transform() + .remove(annotationInstance -> annotationInstance.name().equals(anotherQualifierDotName)) + .done(); + } else if (transformationContext.getAllAnnotationTargetAnnotations().isEmpty()) { + transformationContext.transform().add(MyQualifier.class).done(); + } + } } else { throw new IllegalStateException("Unexpected injection point kind: " + kind); diff --git a/independent-projects/arc/tests/src/test/java/io/quarkus/arc/test/buildextension/validator/BeanDeploymentValidatorTest.java b/independent-projects/arc/tests/src/test/java/io/quarkus/arc/test/buildextension/validator/BeanDeploymentValidatorTest.java index 44b5407a80a7ff..768f48cfa8ed0b 100644 --- a/independent-projects/arc/tests/src/test/java/io/quarkus/arc/test/buildextension/validator/BeanDeploymentValidatorTest.java +++ b/independent-projects/arc/tests/src/test/java/io/quarkus/arc/test/buildextension/validator/BeanDeploymentValidatorTest.java @@ -62,8 +62,8 @@ static class TestValidator implements BeanDeploymentValidator { @Override public void validate(ValidationContext context) { assertTrue(context.getInjectionPoints().stream().filter(InjectionPointInfo::isProgrammaticLookup) - .filter(ip -> ip.getTarget().kind() == org.jboss.jandex.AnnotationTarget.Kind.FIELD - && ip.getTarget().asField().name().equals("foo")) + .filter(ip -> ip.getAnnotationTarget().kind() == org.jboss.jandex.AnnotationTarget.Kind.FIELD + && ip.getAnnotationTarget().asField().name().equals("foo")) .findFirst().isPresent()); assertFalse(context.removedBeans().withBeanClass(UselessBean.class).isEmpty()); diff --git a/independent-projects/arc/tests/src/test/java/io/quarkus/arc/test/injection/resource/ResourceInjectionTest.java b/independent-projects/arc/tests/src/test/java/io/quarkus/arc/test/injection/resource/ResourceInjectionTest.java index ecef3af79b7fa9..bfd685e082258c 100644 --- a/independent-projects/arc/tests/src/test/java/io/quarkus/arc/test/injection/resource/ResourceInjectionTest.java +++ b/independent-projects/arc/tests/src/test/java/io/quarkus/arc/test/injection/resource/ResourceInjectionTest.java @@ -62,7 +62,7 @@ public boolean appliesTo(org.jboss.jandex.Type requiredType) { @Override public void transform(TransformationContext transformationContext) { - if (transformationContext.getAllAnnotations() + if (transformationContext.getAllAnnotationTargetAnnotations() .stream() .anyMatch(it -> it.name().toString().equals(Dummy.class.getName()))) { // pretend that the injection point has an annotation whose class is missing