|
20 | 20 | import org.jboss.jandex.IndexView; |
21 | 21 | import org.jboss.jandex.MethodInfo; |
22 | 22 | import org.jboss.jandex.Type; |
| 23 | +import org.jboss.jandex.TypeVariable; |
23 | 24 | import org.springframework.data.domain.Pageable; |
24 | 25 | import org.springframework.data.domain.Sort; |
25 | 26 |
|
26 | 27 | import io.quarkus.deployment.bean.JavaBeanUtil; |
| 28 | +import io.quarkus.deployment.util.JandexUtil; |
27 | 29 | import io.quarkus.gizmo.ClassCreator; |
28 | 30 | import io.quarkus.gizmo.ClassOutput; |
29 | 31 | import io.quarkus.gizmo.FieldDescriptor; |
@@ -169,7 +171,8 @@ public void add(ClassCreator classCreator, FieldDescriptor entityClassFieldDescr |
169 | 171 | methodCreator.readInstanceField(entityClassFieldDescriptor, methodCreator.getThis()), |
170 | 172 | methodCreator.load(finalQuery), sort, paramsArray); |
171 | 173 |
|
172 | | - Type resultType = verifyQueryResultType(method.returnType(), index); |
| 174 | + Type resultType = extractResultType(repositoryClassInfo, method); |
| 175 | + |
173 | 176 | DotName customResultTypeName = resultType.name(); |
174 | 177 |
|
175 | 178 | if (customResultTypeName.equals(entityClassInfo.name()) |
@@ -287,6 +290,25 @@ public void add(ClassCreator classCreator, FieldDescriptor entityClassFieldDescr |
287 | 290 | } |
288 | 291 | } |
289 | 292 |
|
| 293 | + private Type extractResultType(ClassInfo repositoryClassInfo, MethodInfo method) { |
| 294 | + Type resultType = verifyQueryResultType(method.returnType(), index); |
| 295 | + if (resultType.kind() == Type.Kind.TYPE_VARIABLE) { |
| 296 | + // we can handle the generic result type case where interface only declares one generic type that is the same as the method result type uses (TODO: look into enhancing) |
| 297 | + // this is accomplished by resolving the generic type from the interface we are actually implementing |
| 298 | + TypeVariable resultTypeVariable = resultType.asTypeVariable(); |
| 299 | + List<TypeVariable> interfaceTypeVariables = method.declaringClass().typeParameters(); |
| 300 | + if (interfaceTypeVariables.size() == 1 && interfaceTypeVariables.get(0) |
| 301 | + .equals(resultTypeVariable)) { |
| 302 | + List<Type> resolveTypeParameters = JandexUtil.resolveTypeParameters(repositoryClassInfo.name(), |
| 303 | + method.declaringClass().name(), index); |
| 304 | + if (resolveTypeParameters.size() == 1) { |
| 305 | + return resolveTypeParameters.get(0); |
| 306 | + } |
| 307 | + } |
| 308 | + } |
| 309 | + return resultType; |
| 310 | + } |
| 311 | + |
290 | 312 | private void addAllMethodOfIntermediateRepository(DotName interfaceDotName, Set<MethodInfo> result) { |
291 | 313 | if (GenerationUtil.isIntermediateRepository(interfaceDotName, index)) { |
292 | 314 | ClassInfo classInfo = index.getClassByName(interfaceDotName); |
|
0 commit comments