Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ArC fixes for spec compatibility, round 3 #30924

Merged
merged 12 commits into from
Feb 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import static io.quarkus.deployment.annotations.ExecutionTime.RUNTIME_INIT;
import static io.quarkus.deployment.annotations.ExecutionTime.STATIC_INIT;

import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
Expand Down Expand Up @@ -949,11 +950,13 @@ public void registerField(FieldInfo fieldInfo) {
injectionPoint.getTargetBean().isPresent()
? mc.load(injectionPoint.getTargetBean().get().getIdentifier())
: mc.loadNull());
boolean isTransient = injectionPoint.isField()
&& Modifier.isTransient(injectionPoint.getTarget().asField().flags());

ResultHandle ret = mc.invokeStaticMethod(instancesMethod, targetBean,
injectionPointType, requiredType, requiredQualifiers, mc.getMethodParam(0),
injectionPointAnnotations,
javaMember, mc.load(injectionPoint.getPosition()));
javaMember, mc.load(injectionPoint.getPosition()), mc.load(isTransient));
mc.returnValue(ret);
});
configurator.done();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,17 +111,23 @@ private Collection<AnnotationInstance> transform(AnnotationTargetKey key) {
}

private Collection<AnnotationInstance> getOriginalAnnotations(AnnotationTarget target) {
Collection<AnnotationInstance> annotations;
switch (target.kind()) {
case CLASS:
return target.asClass().classAnnotations();
annotations = target.asClass().classAnnotations();
break;
case METHOD:
// Note that the returning collection also contains method params annotations
return target.asMethod().annotations();
annotations = target.asMethod().annotations();
break;
case FIELD:
return target.asField().annotations();
annotations = target.asField().annotations();
break;
default:
throw new IllegalArgumentException("Unsupported annotation target");
}

return Annotations.onlyRuntimeVisible(annotations);
}

private List<AnnotationsTransformer> initTransformers(Kind kind, Collection<AnnotationsTransformer> transformers) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package io.quarkus.arc.processor;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.function.Function;

Expand Down Expand Up @@ -106,6 +108,17 @@ public static Set<AnnotationInstance> getAnnotations(Kind kind, DotName name, Co
return ret;
}

/**
*
* @param beanDeployment
* @param method
* @param name
* @return whether given method has a parameter that has an annotation with given name
*/
public static boolean hasParameterAnnotation(BeanDeployment beanDeployment, MethodInfo method, DotName name) {
return contains(getParameterAnnotations(beanDeployment, method), name);
}

/**
*
* @param beanDeployment
Expand Down Expand Up @@ -173,4 +186,14 @@ public static AnnotationInstance getParameterAnnotation(MethodInfo method, DotNa
return null;
}

public static Collection<AnnotationInstance> onlyRuntimeVisible(Collection<AnnotationInstance> annotations) {
List<AnnotationInstance> result = new ArrayList<>(annotations.size());
for (AnnotationInstance annotation : annotations) {
if (annotation.runtimeVisible()) {
result.add(annotation);
}
}
return result;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,17 @@ public void done() {

String name = this.name;
if (name == null) {
name = Beans.initStereotypeName(stereotypes, implClass);
name = Beans.initStereotypeName(stereotypes, implClass, beanDeployment);
}

Boolean alternative = this.alternative;
if (alternative == null) {
alternative = Beans.initStereotypeAlternative(stereotypes);
alternative = Beans.initStereotypeAlternative(stereotypes, beanDeployment);
}

Integer priority = this.priority;
if (priority == null) {
priority = Beans.initStereotypeAlternativePriority(stereotypes);
priority = Beans.initStereotypeAlternativePriority(stereotypes, implClass, beanDeployment);
}

beanConsumer.accept(new BeanInfo.Builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,8 @@ public THIS name(String name) {
}

/**
* Unlike for the {@link #name(String)} method a new {@link jakarta.inject.Named} qualifier with the specified value is
* added
* to the configured bean.
* Unlike the {@link #name(String)} method, a new {@link jakarta.inject.Named} qualifier with the specified value
* is added to the configured bean.
*
* @param name
* @return self
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import static io.quarkus.arc.processor.IndexClassLookupUtils.getClassByName;

import java.lang.annotation.Annotation;
import java.lang.annotation.Retention;
import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.Arrays;
Expand Down Expand Up @@ -602,17 +603,18 @@ Collection<AnnotationInstance> extractInterceptorBindings(AnnotationInstance ann

private static Collection<AnnotationInstance> extractAnnotations(AnnotationInstance annotation,
Map<DotName, ClassInfo> singulars, Map<DotName, ClassInfo> repeatables) {
if (!annotation.runtimeVisible()) {
return Collections.emptyList();
}
DotName annotationName = annotation.name();
if (singulars.get(annotationName) != null) {
return Collections.singleton(annotation);
} else if (repeatables.get(annotationName) != null) {
// repeatable, we need to extract actual annotations
return Annotations.onlyRuntimeVisible(Arrays.asList(annotation.value().asNestedArray()));
} else {
if (repeatables.get(annotationName) != null) {
// repeatable, we need to extract actual annotations
return new ArrayList<>(Arrays.asList(annotation.value().asNestedArray()));
} else {
// neither singular nor repeatable, return empty collection
return Collections.emptyList();
}
// neither singular nor repeatable, return empty collection
return Collections.emptyList();
}
}

Expand Down Expand Up @@ -695,10 +697,18 @@ private void buildContextPut(String key, Object value) {
}
}

private boolean isRuntimeAnnotationType(ClassInfo annotationType) {
AnnotationInstance retention = annotationType.declaredAnnotation(Retention.class);
return retention != null && "RUNTIME".equals(retention.value().asEnum());
}

private Map<DotName, ClassInfo> findQualifiers() {
Map<DotName, ClassInfo> qualifiers = new HashMap<>();
for (AnnotationInstance qualifier : beanArchiveImmutableIndex.getAnnotations(DotNames.QUALIFIER)) {
ClassInfo qualifierClass = qualifier.target().asClass();
if (!isRuntimeAnnotationType(qualifierClass)) {
continue;
}
if (isExcluded(qualifierClass)) {
continue;
}
Expand All @@ -725,6 +735,9 @@ private Map<DotName, ClassInfo> findInterceptorBindings() {
// Note: doesn't use AnnotationStore, this will operate on classes without applying annotation transformers
for (AnnotationInstance binding : beanArchiveImmutableIndex.getAnnotations(DotNames.INTERCEPTOR_BINDING)) {
ClassInfo bindingClass = binding.target().asClass();
if (!isRuntimeAnnotationType(bindingClass)) {
continue;
}
if (isExcluded(bindingClass)) {
continue;
}
Expand Down Expand Up @@ -787,6 +800,9 @@ private Map<DotName, StereotypeInfo> findStereotypes(Map<DotName, ClassInfo> int
for (DotName stereotypeName : stereotypeNames) {
ClassInfo stereotypeClass = getClassByName(getBeanArchiveIndex(), stereotypeName);
if (stereotypeClass != null && !isExcluded(stereotypeClass)) {
if (!isRuntimeAnnotationType(stereotypeClass)) {
continue;
}

boolean isAlternative = false;
Integer alternativePriority = null;
Expand Down Expand Up @@ -954,7 +970,8 @@ private List<BeanInfo> findBeans(Collection<DotName> beanDefiningAnnotations, Li
beanClass);
beanClasses.add(beanClass);
}
} else if (annotationStore.hasAnnotation(method, DotNames.DISPOSES)) {
}
if (annotationStore.hasAnnotation(method, DotNames.DISPOSES)) {
// Disposers are not inherited
disposerMethods.add(method);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1929,14 +1929,17 @@ private ResultHandle wrapCurrentInjectionPoint(ClassOutput classOutput, ClassCre
ResultHandle annotationsHandle = collectInjectionPointAnnotations(classOutput, beanCreator, bean.getDeployment(),
constructor, injectionPoint, annotationLiterals, injectionPointAnnotationsPredicate);
ResultHandle javaMemberHandle = getJavaMemberHandle(constructor, injectionPoint, reflectionRegistration);
boolean isTransient = injectionPoint.isField() && Modifier.isTransient(injectionPoint.getTarget().asField().flags());

return constructor.newInstance(
MethodDescriptor.ofConstructor(CurrentInjectionPointProvider.class, InjectableBean.class,
Supplier.class, java.lang.reflect.Type.class,
Set.class, Set.class, Member.class, int.class),
Set.class, Set.class, Member.class, int.class, boolean.class),
constructor.getThis(), constructor.getMethodParam(paramIdx),
Types.getTypeHandle(constructor, injectionPoint.getType(), tccl),
requiredQualifiersHandle, annotationsHandle, javaMemberHandle, constructor.load(injectionPoint.getPosition()));
requiredQualifiersHandle, annotationsHandle, javaMemberHandle,
constructor.load(injectionPoint.getPosition()),
constructor.load(isTransient));
}

private void initializeProxy(BeanInfo bean, String baseName, ClassCreator beanCreator) {
Expand Down Expand Up @@ -2024,9 +2027,6 @@ public static ResultHandle collectInjectionPointAnnotations(ClassOutput classOut
annotationHandle = constructor
.readStaticField(FieldDescriptor.of(InjectLiteral.class, "INSTANCE", InjectLiteral.class));
} else {
if (!annotation.runtimeVisible()) {
continue;
}
ClassInfo annotationClass = getClassByName(beanDeployment.getBeanArchiveIndex(), annotation.name());
if (annotationClass == null) {
continue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -277,15 +277,22 @@ boolean boundsMatch(List<Type> bounds, List<Type> stricterBounds) {
bounds = getUppermostBounds(bounds);
stricterBounds = getUppermostBounds(stricterBounds);
for (Type bound : bounds) {
for (Type stricterBound : stricterBounds) {
if (!beanDeployment.getAssignabilityCheck().isAssignableFrom(bound, stricterBound)) {
return false;
}
if (!isAssignableFromAtLeastOne(bound, stricterBounds)) {
return false;
}
}
return true;
}

boolean isAssignableFromAtLeastOne(Type type1, List<Type> types2) {
for (Type type2 : types2) {
if (beanDeployment.getAssignabilityCheck().isAssignableFrom(type1, type2)) {
return true;
}
}
return false;
}

boolean lowerBoundsOfWildcardMatch(Type parameter, WildcardType requiredParameter) {
return lowerBoundsOfWildcardMatch(singletonList(parameter), requiredParameter);
}
Expand Down
Loading