public abstract class GenericTypeResolver extends Object
Mainly intended for usage within the framework, resolving method parameter types even when they are declared generically.
GenericCollectionTypeResolver
Constructor and Description |
---|
GenericTypeResolver() |
Modifier and Type | Method and Description |
---|---|
static Type |
getTargetType(MethodParameter methodParam)
Determine the target type for the given parameter specification.
|
static Map<TypeVariable,Type> |
getTypeVariableMap(Class<?> clazz)
|
static Class<?> |
resolveParameterType(MethodParameter methodParam,
Class<?> clazz)
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 Class<?> |
resolveReturnTypeForGenericMethod(Method method,
Object[] args)
Deprecated.
in favor of resolveReturnTypeForFactoryMethod in the internal
AutowireUtils class in the beans module; we do not expect other use of it!
|
static Class<?> |
resolveType(Type genericType,
Map<TypeVariable,Type> typeVariableMap)
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 Type getTargetType(MethodParameter methodParam)
methodParam
- the method parameter specificationpublic static Class<?> resolveParameterType(MethodParameter methodParam, Class<?> clazz)
methodParam
- the method parameter specificationclazz
- 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 againstresolveReturnTypeForGenericMethod(java.lang.reflect.Method, java.lang.Object[])
@Deprecated public static Class<?> resolveReturnTypeForGenericMethod(Method method, Object[] args)
For example, given a factory method with the following signature,
if resolveReturnTypeForGenericMethod()
is invoked with the reflected
method for creatProxy()
and an Object[]
array containing
MyService.class
, resolveReturnTypeForGenericMethod()
will
infer that the target return type is MyService
.
public static <T> T createProxy(Class<T> clazz)
method
does not declare any formal type variablesnull
, if the length of the given arguments array is shorter
than the length of the formal argument list for the given
methodmethod
- the method to introspect, never null
args
- the arguments that will be supplied to the method when it is
invoked, never null
null
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
.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 resolvablepublic static Class<?>[] resolveTypeArguments(Class<?> clazz, Class<?> genericIfc)
Note: In Spring 3.2, this method doesn't return null
in all scenarios
where it should. To be fixed in Spring 4.0; for client code, this just means it
might see null
in a few more cases then where it now sees an array with
a single Object
type.
clazz
- the target class to check againstgenericIfc
- the generic interface or superclass to resolve the type argument fromnull
if not resolvablepublic static Class<?> resolveType(Type genericType, Map<TypeVariable,Type> typeVariableMap)
genericType
- the generic type to resolvetypeVariableMap
- 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.