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:
parent
a4fa6a7a31
commit
7c84695333
|
@ -873,6 +873,12 @@ public class ResolvableType implements Serializable {
|
||||||
return forType(ownerType, this.variableResolver).resolveVariable(variable);
|
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) {
|
if (this.variableResolver != null) {
|
||||||
return this.variableResolver.resolveVariable(variable);
|
return this.variableResolver.resolveVariable(variable);
|
||||||
}
|
}
|
||||||
|
|
|
@ -688,6 +688,13 @@ class ResolvableTypeTests {
|
||||||
assertThat(type.resolve()).isEqualTo(CharSequence.class);
|
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
|
@Test
|
||||||
void resolveVariableNotFound() throws Exception {
|
void resolveVariableNotFound() throws Exception {
|
||||||
ResolvableType type = ResolvableType.forMethodReturnType(Methods.class.getMethod("typedReturn"));
|
ResolvableType type = ResolvableType.forMethodReturnType(Methods.class.getMethod("typedReturn"));
|
||||||
|
@ -1417,6 +1424,8 @@ class ResolvableTypeTests {
|
||||||
|
|
||||||
<R extends CharSequence & Serializable> R boundedTypeVaraibleResult();
|
<R extends CharSequence & Serializable> R boundedTypeVaraibleResult();
|
||||||
|
|
||||||
|
Map<String, ? extends List<? extends CharSequence>> boundedTypeVaraibleWildcardResult();
|
||||||
|
|
||||||
void nested(Map<Map<String, Integer>, Map<Byte, Long>> p);
|
void nested(Map<Map<String, Integer>, Map<Byte, Long>> p);
|
||||||
|
|
||||||
void typedParameter(T p);
|
void typedParameter(T p);
|
||||||
|
|
Loading…
Reference in New Issue