diff --git a/extensions/resteasy-reactive/jaxrs-client-reactive/deployment/src/main/java/io/quarkus/jaxrs/client/reactive/deployment/JaxrsClientReactiveProcessor.java b/extensions/resteasy-reactive/jaxrs-client-reactive/deployment/src/main/java/io/quarkus/jaxrs/client/reactive/deployment/JaxrsClientReactiveProcessor.java index 6ee601bf8e874d..4cecf9feab2e9e 100644 --- a/extensions/resteasy-reactive/jaxrs-client-reactive/deployment/src/main/java/io/quarkus/jaxrs/client/reactive/deployment/JaxrsClientReactiveProcessor.java +++ b/extensions/resteasy-reactive/jaxrs-client-reactive/deployment/src/main/java/io/quarkus/jaxrs/client/reactive/deployment/JaxrsClientReactiveProcessor.java @@ -7,10 +7,13 @@ import static org.jboss.jandex.Type.Kind.PRIMITIVE; import static org.jboss.resteasy.reactive.client.impl.RestClientRequestContext.DEFAULT_CONTENT_TYPE_PROP; import static org.jboss.resteasy.reactive.common.processor.EndpointIndexer.extractProducesConsumesValues; +import static org.jboss.resteasy.reactive.common.processor.JandexUtil.*; +import static org.jboss.resteasy.reactive.common.processor.ResteasyReactiveDotNames.COLLECTION; import static org.jboss.resteasy.reactive.common.processor.ResteasyReactiveDotNames.COMPLETION_STAGE; import static org.jboss.resteasy.reactive.common.processor.ResteasyReactiveDotNames.CONSUMES; import static org.jboss.resteasy.reactive.common.processor.ResteasyReactiveDotNames.ENCODED; import static org.jboss.resteasy.reactive.common.processor.ResteasyReactiveDotNames.FORM_PARAM; +import static org.jboss.resteasy.reactive.common.processor.ResteasyReactiveDotNames.MAP; import static org.jboss.resteasy.reactive.common.processor.ResteasyReactiveDotNames.MULTI; import static org.jboss.resteasy.reactive.common.processor.ResteasyReactiveDotNames.OBJECT; import static org.jboss.resteasy.reactive.common.processor.ResteasyReactiveDotNames.PART_TYPE_NAME; @@ -2744,28 +2747,11 @@ private void addQueryParamToWebTarget(BytecodeCreator creator, ResultHandle para } private boolean isCollection(Type type, IndexView index) { - if (type.kind() == Type.Kind.PRIMITIVE) { - return false; - } - ClassInfo classInfo = index.getClassByName(type.name()); - if (classInfo == null) { - return false; - } - return classInfo.interfaceNames().stream().anyMatch(DotName.createSimple(Collection.class.getName())::equals); + return isAssignableFrom(COLLECTION, type.name(), index); } private boolean isMap(Type type, IndexView index) { - if (type.kind() == Type.Kind.PRIMITIVE) { - return false; - } - ClassInfo classInfo = index.getClassByName(type.name()); - if (classInfo == null) { - return false; - } - if (ResteasyReactiveDotNames.MAP.equals(classInfo.name())) { - return true; - } - return classInfo.interfaceNames().stream().anyMatch(DotName.createSimple(Map.class.getName())::equals); + return isAssignableFrom(MAP, type.name(), index); } private void addHeaderParam(BytecodeCreator invoBuilderEnricher, AssignableResultHandle invocationBuilder, diff --git a/extensions/resteasy-reactive/quarkus-resteasy-reactive-links/deployment/src/main/java/io/quarkus/resteasy/reactive/links/deployment/LinksContainerFactory.java b/extensions/resteasy-reactive/quarkus-resteasy-reactive-links/deployment/src/main/java/io/quarkus/resteasy/reactive/links/deployment/LinksContainerFactory.java index 9c4ddafd41688e..2a991448e49dff 100644 --- a/extensions/resteasy-reactive/quarkus-resteasy-reactive-links/deployment/src/main/java/io/quarkus/resteasy/reactive/links/deployment/LinksContainerFactory.java +++ b/extensions/resteasy-reactive/quarkus-resteasy-reactive-links/deployment/src/main/java/io/quarkus/resteasy/reactive/links/deployment/LinksContainerFactory.java @@ -1,5 +1,7 @@ package io.quarkus.resteasy.reactive.links.deployment; +import static org.jboss.resteasy.reactive.common.processor.JandexUtil.isAssignableFrom; +import static org.jboss.resteasy.reactive.common.processor.ResteasyReactiveDotNames.COLLECTION; import static org.jboss.resteasy.reactive.common.processor.ResteasyReactiveDotNames.COMPLETABLE_FUTURE; import static org.jboss.resteasy.reactive.common.processor.ResteasyReactiveDotNames.COMPLETION_STAGE; import static org.jboss.resteasy.reactive.common.processor.ResteasyReactiveDotNames.MULTI; @@ -17,8 +19,6 @@ import org.jboss.jandex.AnnotationInstance; import org.jboss.jandex.AnnotationValue; -import org.jboss.jandex.ClassInfo; -import org.jboss.jandex.DotName; import org.jboss.jandex.IndexView; import org.jboss.jandex.MethodInfo; import org.jboss.jandex.ParameterizedType; @@ -138,14 +138,7 @@ private String getAnnotationValue(AnnotationInstance annotationInstance, String } private boolean isCollection(Type type, IndexView index) { - if (type.kind() == Type.Kind.PRIMITIVE) { - return false; - } - ClassInfo classInfo = index.getClassByName(type.name()); - if (classInfo == null) { - return false; - } - return classInfo.interfaceNames().stream().anyMatch(DotName.createSimple(Collection.class.getName())::equals); + return isAssignableFrom(COLLECTION, type.name(), index); } private Type getNonAsyncReturnType(Type returnType) { diff --git a/independent-projects/resteasy-reactive/common/processor/src/main/java/org/jboss/resteasy/reactive/common/processor/JandexUtil.java b/independent-projects/resteasy-reactive/common/processor/src/main/java/org/jboss/resteasy/reactive/common/processor/JandexUtil.java index 8eb2a5d725bf9a..2c8f8c37833b3e 100644 --- a/independent-projects/resteasy-reactive/common/processor/src/main/java/org/jboss/resteasy/reactive/common/processor/JandexUtil.java +++ b/independent-projects/resteasy-reactive/common/processor/src/main/java/org/jboss/resteasy/reactive/common/processor/JandexUtil.java @@ -5,8 +5,10 @@ import java.lang.reflect.Modifier; import java.nio.file.Files; import java.nio.file.Path; +import java.util.ArrayDeque; import java.util.ArrayList; import java.util.Collections; +import java.util.Deque; import java.util.HashMap; import java.util.HashSet; import java.util.List; @@ -415,4 +417,42 @@ public static boolean isImplementorOf(IndexView index, ClassInfo info, DotName n return isImplementorOf(index, superClass, name, additionalIgnoredSuperClasses); } + public static boolean isAssignableFrom(DotName superType, DotName subType, IndexView index) { + // java.lang.Object is assignable from any type + if (superType.equals(DOTNAME_OBJECT)) { + return true; + } + // type1 is the same as type2 + if (superType.equals(subType)) { + return true; + } + // type1 is a superclass + return findSupertypes(subType, index).contains(superType); + } + + private static Set findSupertypes(DotName name, IndexView index) { + Set result = new HashSet<>(); + + Deque workQueue = new ArrayDeque<>(); + workQueue.add(name); + while (!workQueue.isEmpty()) { + DotName type = workQueue.poll(); + if (result.contains(type)) { + continue; + } + result.add(type); + + ClassInfo clazz = index.getClassByName(type); + if (clazz == null) { + continue; + } + if (clazz.superName() != null) { + workQueue.add(clazz.superName()); + } + workQueue.addAll(clazz.interfaceNames()); + } + + return result; + } + }