public abstract class GenericMetadataSupport
extends java.lang.Object
The main idea of this code is to create a Map that will help to resolve return types. In order to actually work with nested generics, this map will have to be passed along new instances as a type context.
Hence :
inferFrom(Type) method from a real
Class or from a ParameterizedType, other types are not yet supported.resolveGenericReturnType(Method).For now this code support the following kind of generic declarations :
interface GenericsNest<K extends Comparable<K> & Cloneable> extends Map<K, Set<Number>> {
Set<Number> remove(Object key); // override with fixed ParameterizedType
List<? super Integer> returning_wildcard_with_class_lower_bound();
List<? super K> returning_wildcard_with_typeVar_lower_bound();
List<? extends K> returning_wildcard_with_typeVar_upper_bound();
K returningK();
<O extends K> List<O> paramType_with_type_params();
<S, T extends S> T two_type_params();
<O extends K> O typeVar_with_type_params();
Number returningNonGeneric();
}
| Modifier and Type | Class and Description |
|---|---|
static interface |
GenericMetadataSupport.BoundedType
Type representing bounds of a type
|
private static class |
GenericMetadataSupport.FromClassGenericMetadataSupport
Generic metadata implementation for
Class. |
private static class |
GenericMetadataSupport.FromParameterizedTypeGenericMetadataSupport
Generic metadata implementation for "standalone"
ParameterizedType. |
private static class |
GenericMetadataSupport.GenericArrayReturnType |
private static class |
GenericMetadataSupport.NotGenericReturnTypeSupport
Non-Generic metadata for
Class returned via Method.getGenericReturnType(). |
private static class |
GenericMetadataSupport.ParameterizedReturnType
Generic metadata specific to
ParameterizedType returned via Method.getGenericReturnType(). |
static class |
GenericMetadataSupport.TypeVarBoundedType
Type representing bounds of a type variable, allows to keep all bounds information.
|
private static class |
GenericMetadataSupport.TypeVariableReturnType
Generic metadata for
TypeVariable returned via Method.getGenericReturnType(). |
static class |
GenericMetadataSupport.WildCardBoundedType
Type representing bounds of a wildcard, allows to keep all bounds information.
|
| Modifier and Type | Field and Description |
|---|---|
protected java.util.Map<java.lang.reflect.TypeVariable<?>,java.lang.reflect.Type> |
contextualActualTypeParameters
Represents actual type variables resolved for current class.
|
| Constructor and Description |
|---|
GenericMetadataSupport() |
| Modifier and Type | Method and Description |
|---|---|
java.util.Map<java.lang.reflect.TypeVariable<?>,java.lang.reflect.Type> |
actualTypeArguments() |
private GenericMetadataSupport.BoundedType |
boundsOf(java.lang.reflect.TypeVariable<?> typeParameter) |
private GenericMetadataSupport.BoundedType |
boundsOf(java.lang.reflect.WildcardType wildCard) |
protected java.lang.Class<?> |
extractRawTypeOf(java.lang.reflect.Type type) |
java.util.List<java.lang.reflect.Type> |
extraInterfaces() |
protected java.lang.reflect.Type |
getActualTypeArgumentFor(java.lang.reflect.TypeVariable<?> typeParameter) |
boolean |
hasRawExtraInterfaces() |
static GenericMetadataSupport |
inferFrom(java.lang.reflect.Type type)
Create an new instance of
GenericMetadataSupport inferred from a Type. |
java.lang.Class<?>[] |
rawExtraInterfaces() |
abstract java.lang.Class<?> |
rawType() |
protected void |
registerAllTypeVariables(java.lang.reflect.Type classType)
Registers the type variables for the given type and all of its superclasses and superinterfaces.
|
protected void |
registerTypeParametersOn(java.lang.reflect.TypeVariable<?>[] typeParameters) |
private void |
registerTypeVariableIfNotPresent(java.lang.reflect.TypeVariable<?> typeVariable) |
protected void |
registerTypeVariablesOn(java.lang.reflect.Type classType) |
GenericMetadataSupport |
resolveGenericReturnType(java.lang.reflect.Method method)
Resolve current method generic return type to a
GenericMetadataSupport. |
private GenericMetadataSupport |
resolveGenericType(java.lang.reflect.Type type,
java.lang.reflect.Method method) |
protected java.util.Map<java.lang.reflect.TypeVariable<?>,java.lang.reflect.Type> contextualActualTypeParameters
protected void registerAllTypeVariables(java.lang.reflect.Type classType)
protected java.lang.Class<?> extractRawTypeOf(java.lang.reflect.Type type)
protected void registerTypeVariablesOn(java.lang.reflect.Type classType)
protected void registerTypeParametersOn(java.lang.reflect.TypeVariable<?>[] typeParameters)
private void registerTypeVariableIfNotPresent(java.lang.reflect.TypeVariable<?> typeVariable)
private GenericMetadataSupport.BoundedType boundsOf(java.lang.reflect.TypeVariable<?> typeParameter)
typeParameter - The TypeVariable parameterGenericMetadataSupport.BoundedType for easy bound information, if first bound is a TypeVariable
then retrieve BoundedType of this TypeVariableprivate GenericMetadataSupport.BoundedType boundsOf(java.lang.reflect.WildcardType wildCard)
wildCard - The WildCard typeGenericMetadataSupport.BoundedType for easy bound information, if first bound is a TypeVariable
then retrieve BoundedType of this TypeVariablepublic abstract java.lang.Class<?> rawType()
public java.util.List<java.lang.reflect.Type> extraInterfaces()
public java.lang.Class<?>[] rawExtraInterfaces()
extraInterfaces() if relevant.public boolean hasRawExtraInterfaces()
extraInterfaces() if relevant.public java.util.Map<java.lang.reflect.TypeVariable<?>,java.lang.reflect.Type> actualTypeArguments()
GenericMetadataSupport instance.protected java.lang.reflect.Type getActualTypeArgumentFor(java.lang.reflect.TypeVariable<?> typeParameter)
public GenericMetadataSupport resolveGenericReturnType(java.lang.reflect.Method method)
GenericMetadataSupport.method - Method to resolve the return type.GenericMetadataSupport representing this generic return type.private GenericMetadataSupport resolveGenericType(java.lang.reflect.Type type, java.lang.reflect.Method method)
public static GenericMetadataSupport inferFrom(java.lang.reflect.Type type)
GenericMetadataSupport inferred from a Type.
At the moment type can only be a Class or a ParameterizedType, otherwise
it'll throw a MockitoException.
type - The class from which the GenericMetadataSupport should be built.GenericMetadataSupport.MockitoException - Raised if type is not a Class or a ParameterizedType.