public final class GenericTypeResolver extends Object
Mainly intended for usage within the framework, resolving method parameter types even when they are declared generically.
Modifier and Type | Method and Description |
---|---|
static Map<TypeVariable,Type> |
getTypeVariableMap(Class<?> clazz)
|
static Class<?> |
resolveParameterType(MethodParameter methodParameter,
Class<?> implementationClass)
Determine the target type for the given generic parameter type.
|
static Class<?> |
resolveReturnType(Method method,
Class<?> clazz)
Determine the target type for the generic return type of the given method,
where formal type variables are declared on the given class.
|
static Class<?> |
resolveReturnTypeArgument(Method method,
Class<?> genericIfc)
Resolve the single type argument of the given generic interface against the given
target method which is assumed to return the given interface or an implementation
of it.
|
static Type |
resolveType(Type genericType,
Class<?> contextClass)
Resolve the given generic type against the given context class,
substituting type variables as far as possible.
|
static Class<?> |
resolveType(Type genericType,
Map<TypeVariable,Type> map)
Resolve the specified generic type against the given TypeVariable map.
|
static Class<?> |
resolveTypeArgument(Class<?> clazz,
Class<?> genericIfc)
Resolve the single type argument of the given generic interface against
the given target class which is assumed to implement the generic interface
and possibly declare a concrete type for its type variable.
|
static Class<?>[] |
resolveTypeArguments(Class<?> clazz,
Class<?> genericIfc)
Resolve the type arguments of the given generic interface against the given
target class which is assumed to implement the generic interface and possibly
declare concrete types for its type variables.
|
public static Class<?> resolveParameterType(MethodParameter methodParameter, Class<?> implementationClass)
methodParameter
- the method parameter specificationimplementationClass
- the class to resolve type variables againstpublic static Class<?> resolveReturnType(Method method, Class<?> clazz)
method
- the method to introspectclazz
- the class to resolve type variables against@Nullable public static Class<?> resolveReturnTypeArgument(Method method, Class<?> genericIfc)
method
- the target method to check the return type ofgenericIfc
- the generic interface or superclass to resolve the type argument fromnull
if not resolvable or if the single argument is of type WildcardType
.@Nullable public static Class<?> resolveTypeArgument(Class<?> clazz, Class<?> genericIfc)
clazz
- the target class to check againstgenericIfc
- the generic interface or superclass to resolve the type argument fromnull
if not resolvable@Nullable public static Class<?>[] resolveTypeArguments(Class<?> clazz, Class<?> genericIfc)
clazz
- the target class to check againstgenericIfc
- the generic interface or superclass to resolve the type argument fromnull
if not resolvablepublic static Type resolveType(Type genericType, @Nullable Class<?> contextClass)
genericType
- the (potentially) generic typecontextClass
- a context class for the target type, for example a class
in which the target type appears in a method signature (can be null
)public static Class<?> resolveType(Type genericType, Map<TypeVariable,Type> map)
Used by Spring Data.
genericType
- the generic type to resolvemap
- the TypeVariable Map to resolved againstObject.class
otherwisepublic static Map<TypeVariable,Type> getTypeVariableMap(Class<?> clazz)
TypeVariable names
to
concrete classes
for the specified Class
.
Searches all super types, enclosing types and interfaces.resolveType(Type, Map)