Browse Source

Polish "Polish GenericTypeResolver Javadoc"

See gh-31663
pull/31679/head
Stéphane Nicoll 2 years ago
parent
commit
85aa4b65dc
  1. 8
      spring-core/src/main/java/org/springframework/core/GenericTypeResolver.java
  2. 15
      spring-core/src/test/java/org/springframework/core/GenericTypeResolverTests.java

8
spring-core/src/main/java/org/springframework/core/GenericTypeResolver.java

@ -83,7 +83,7 @@ public final class GenericTypeResolver { @@ -83,7 +83,7 @@ public final class GenericTypeResolver {
/**
* Resolve the single type argument of the given generic type against the given
* target method which is assumed to return the given interface or an implementation
* target method which is assumed to return the given type or an implementation
* of it.
* @param method the target method to check the return type of
* @param genericType the generic interface or superclass to resolve the type argument from
@ -102,7 +102,7 @@ public final class GenericTypeResolver { @@ -102,7 +102,7 @@ public final class GenericTypeResolver {
/**
* Resolve the single type argument of the given generic type against
* the given target class which is assumed to implement the generic interface
* the given target class which is assumed to implement the given type
* and possibly declare a concrete type for its type variable.
* @param clazz the target class to check against
* @param genericType the generic interface or superclass to resolve the type argument from
@ -128,8 +128,8 @@ public final class GenericTypeResolver { @@ -128,8 +128,8 @@ public final class GenericTypeResolver {
/**
* Resolve the type arguments of the given generic type against the given
* target class which is assumed to implement the generic interface and possibly
* declare concrete types for its type variables.
* target class which is assumed to implement or extend from the given type
* and possibly declare concrete types for its type variables.
* @param clazz the target class to check against
* @param genericType the generic interface or superclass to resolve the type argument from
* @return the resolved type of each argument, with the array size matching the

15
spring-core/src/test/java/org/springframework/core/GenericTypeResolverTests.java

@ -72,6 +72,7 @@ class GenericTypeResolverTests { @@ -72,6 +72,7 @@ class GenericTypeResolverTests {
void methodReturnTypes() {
assertThat(resolveReturnTypeArgument(findMethod(MyTypeWithMethods.class, "integer"), MyInterfaceType.class)).isEqualTo(Integer.class);
assertThat(resolveReturnTypeArgument(findMethod(MyTypeWithMethods.class, "string"), MyInterfaceType.class)).isEqualTo(String.class);
assertThat(resolveReturnTypeArgument(findMethod(MyTypeWithMethods.class, "character"), MyAbstractType.class)).isEqualTo(Character.class);
assertThat(resolveReturnTypeArgument(findMethod(MyTypeWithMethods.class, "raw"), MyInterfaceType.class)).isNull();
assertThat(resolveReturnTypeArgument(findMethod(MyTypeWithMethods.class, "object"), MyInterfaceType.class)).isNull();
}
@ -137,6 +138,12 @@ class GenericTypeResolverTests { @@ -137,6 +138,12 @@ class GenericTypeResolverTests {
assertThat(x).isEqualTo(Long.class);
}
@Test
void resolveTypeArgumentsOfAbstractType() {
Class<?>[] resolved = GenericTypeResolver.resolveTypeArguments(MyConcreteType.class, MyAbstractType.class);
assertThat(resolved).containsExactly(Character.class);
}
@Test // SPR-11030
void getGenericsCannotBeResolved() throws Exception {
Class<?>[] resolved = GenericTypeResolver.resolveTypeArguments(List.class, Iterable.class);
@ -240,6 +247,12 @@ class GenericTypeResolverTests { @@ -240,6 +247,12 @@ class GenericTypeResolverTests {
public class MyCollectionInterfaceType implements MyInterfaceType<Collection<String>> {
}
public abstract class MyAbstractType<T> implements MyInterfaceType<T> {
}
public class MyConcreteType extends MyAbstractType<Character> {
}
public abstract class MySuperclassType<T> {
public void upperBound(List<? extends T> list) {
@ -274,6 +287,8 @@ class GenericTypeResolverTests { @@ -274,6 +287,8 @@ class GenericTypeResolverTests {
return null;
}
public MyConcreteType character() { return null; }
public Object object() {
return null;
}

Loading…
Cancel
Save