|
46 | 46 | * @author Stephane Nicoll |
47 | 47 | * @author Phillip Webb |
48 | 48 | * @author Pavel Anisimov |
| 49 | + * @author Dmytro Nosan |
49 | 50 | */ |
50 | 51 | class TypeUtils { |
51 | 52 |
|
@@ -217,7 +218,7 @@ private TypeKind getPrimitiveFor(TypeMirror type) { |
217 | 218 | return WRAPPER_TO_PRIMITIVE.get(type.toString()); |
218 | 219 | } |
219 | 220 |
|
220 | | - TypeDescriptor resolveTypeDescriptor(TypeElement element) { |
| 221 | + private TypeDescriptor resolveTypeDescriptor(TypeElement element) { |
221 | 222 | if (this.typeDescriptors.containsKey(element)) { |
222 | 223 | return this.typeDescriptors.get(element); |
223 | 224 | } |
@@ -318,22 +319,22 @@ private String determineQualifiedName(DeclaredType type, TypeElement enclosingEl |
318 | 319 | } |
319 | 320 |
|
320 | 321 | @Override |
321 | | - public String visitTypeVariable(TypeVariable t, TypeDescriptor descriptor) { |
322 | | - TypeMirror typeMirror = descriptor.resolveGeneric(t); |
323 | | - if (typeMirror != null) { |
324 | | - if (typeMirror instanceof TypeVariable typeVariable) { |
| 322 | + public String visitTypeVariable(TypeVariable typeVariable, TypeDescriptor descriptor) { |
| 323 | + TypeMirror resolvedGeneric = descriptor.resolveGeneric(typeVariable); |
| 324 | + if (resolvedGeneric != null) { |
| 325 | + if (resolvedGeneric instanceof TypeVariable resolveTypeVariable) { |
325 | 326 | // Still unresolved, let's use the upper bound, checking first if |
326 | 327 | // a cycle may exist |
327 | | - if (!hasCycle(typeVariable)) { |
328 | | - return visit(typeVariable.getUpperBound(), descriptor); |
| 328 | + if (!hasCycle(resolveTypeVariable)) { |
| 329 | + return visit(resolveTypeVariable.getUpperBound(), descriptor); |
329 | 330 | } |
330 | 331 | } |
331 | 332 | else { |
332 | | - return visit(typeMirror, descriptor); |
| 333 | + return visit(resolvedGeneric, descriptor); |
333 | 334 | } |
334 | 335 | } |
335 | 336 | // Fallback to simple representation of the upper bound |
336 | | - return defaultAction(t.getUpperBound(), descriptor); |
| 337 | + return defaultAction(typeVariable.getUpperBound(), descriptor); |
337 | 338 | } |
338 | 339 |
|
339 | 340 | private boolean hasCycle(TypeVariable variable) { |
@@ -394,20 +395,11 @@ static class TypeDescriptor { |
394 | 395 | private final Map<TypeVariable, TypeMirror> generics = new HashMap<>(); |
395 | 396 |
|
396 | 397 | TypeMirror resolveGeneric(TypeVariable typeVariable) { |
397 | | - if (this.generics.containsKey(typeVariable)) { |
398 | | - TypeMirror resolvedType = this.generics.get(typeVariable); |
399 | | - // Unresolved <T> -> <T> |
400 | | - if (resolvedType == typeVariable) { |
401 | | - return resolvedType; |
402 | | - } |
403 | | - // <T> -> <T1> -> <T2> |
404 | | - if (resolvedType instanceof TypeVariable) { |
405 | | - return resolveGeneric((TypeVariable) resolvedType); |
406 | | - } |
407 | | - // Resolved e.g. java.lang.String |
408 | | - return resolvedType; |
| 398 | + TypeMirror resolved = this.generics.get(typeVariable); |
| 399 | + if (resolved != typeVariable && resolved instanceof TypeVariable resolvedTypeVariable) { |
| 400 | + return resolveGeneric(resolvedTypeVariable); |
409 | 401 | } |
410 | | - return null; |
| 402 | + return resolved; |
411 | 403 | } |
412 | 404 |
|
413 | 405 | private void registerIfNecessary(TypeMirror variable, TypeMirror resolution) { |
|
0 commit comments