Support variable resolution of wildcard types

Update `ResolvableType` so that variable referenced can be resolved
against wildcard types. Prior to this commit, given a type:

	Map<String, ? extends List<? extends CharSequence>>

Calling `type.getGeneric(1).asCollection().resolveGeneric()` would
return `null`. This was because the `List` variable `E` referenced a
wildcard type which `resolveVariable` did not support.

Closes gh-24145
This commit is contained in:
Phillip Webb 2019-12-05 13:17:41 -08:00 committed by Juergen Hoeller
parent a4fa6a7a31
commit 7c84695333
2 changed files with 15 additions and 0 deletions

View File

@ -873,6 +873,12 @@ public class ResolvableType implements Serializable {
return forType(ownerType, this.variableResolver).resolveVariable(variable);
}
}
if (this.type instanceof WildcardType) {
ResolvableType resolved = resolveType().resolveVariable(variable);
if (resolved != null) {
return resolved;
}
}
if (this.variableResolver != null) {
return this.variableResolver.resolveVariable(variable);
}

View File

@ -688,6 +688,13 @@ class ResolvableTypeTests {
assertThat(type.resolve()).isEqualTo(CharSequence.class);
}
@Test
void resolveBoundedTypeVariableWildcardResult() throws Exception {
ResolvableType type = ResolvableType.forMethodReturnType(Methods.class.getMethod("boundedTypeVaraibleWildcardResult"));
assertThat(type.getGeneric(1).asCollection().resolveGeneric()).isEqualTo(CharSequence.class);
}
@Test
void resolveVariableNotFound() throws Exception {
ResolvableType type = ResolvableType.forMethodReturnType(Methods.class.getMethod("typedReturn"));
@ -1417,6 +1424,8 @@ class ResolvableTypeTests {
<R extends CharSequence & Serializable> R boundedTypeVaraibleResult();
Map<String, ? extends List<? extends CharSequence>> boundedTypeVaraibleWildcardResult();
void nested(Map<Map<String, Integer>, Map<Byte, Long>> p);
void typedParameter(T p);