Provide 'with implementationType' overloads

Provided overloaded versions of `forField` and `forMethodParameter` that
accept a `ResolvableType` implementation type (as opposed to a Class).

Primarily added to allow resolution against implementation types that
have been created programmatically using `forTypeWithGenerics`.

Issue: SPR-11218
This commit is contained in:
Phillip Webb
2014-01-17 11:45:11 -08:00
parent 7e6dbc24f6
commit 9076c70d47
2 changed files with 58 additions and 3 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2013 the original author or authors.
* Copyright 2002-2014 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -659,6 +659,16 @@ public class ResolvableTypeTests {
assertThat(type.getGeneric().resolve(), equalTo((Class) String.class));
}
@Test
public void resolveTypeVariableFromFieldTypeWithImplementsType() throws Exception {
ResolvableType implementationType = ResolvableType.forClassWithGenerics(
Fields.class, Integer.class);
ResolvableType type = ResolvableType.forField(
Fields.class.getField("parameterizedType"), implementationType);
assertThat(type.resolve(), equalTo((Class) List.class));
assertThat(type.getGeneric().resolve(), equalTo((Class) Integer.class));
}
@Test
public void resolveTypeVariableFromSuperType() throws Exception {
ResolvableType type = ResolvableType.forClass(ExtendsList.class);
@@ -735,6 +745,16 @@ public class ResolvableTypeTests {
assertThat(type.getType().toString(), equalTo("T"));
}
@Test
public void resolveTypeVariableFromMethodParameterTypeWithImplementsType() throws Exception {
Method method = Methods.class.getMethod("typedParameter", Object.class);
MethodParameter methodParameter = MethodParameter.forMethodOrConstructor(method, 0);
ResolvableType implementationType = ResolvableType.forClassWithGenerics(Methods.class, Integer.class);
ResolvableType type = ResolvableType.forMethodParameter(methodParameter, implementationType);
assertThat(type.resolve(), equalTo((Class) Integer.class));
assertThat(type.getType().toString(), equalTo("T"));
}
@Test
public void resolveTypeVariableFromMethodReturn() throws Exception {
Method method = Methods.class.getMethod("typedReturn");