GenericMetadataSupport
Date: 2015-09-18

org.mockito.internal.util.reflection

## Class GenericMetadataSupport

- java.lang.Object
- - org.mockito.internal.util.reflection.GenericMetadataSupport

-     public abstract class GenericMetadataSupport
      extends java.lang.Object

  This class can retrieve generic meta-data that the compiler stores on classes and accessible members.

  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 :

  - A new instance representing the metadata is created using the `inferFrom(Type)` method from a real `Class` or from a `ParameterizedType`, other types are not yet supported.
  - Then from this metadata, we can extract meta-data for a generic return type of a method, using `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();
       }

  See Also:
    `inferFrom(Type)`, `resolveGenericReturnType(Method)`, `ReturnsDeepStubs`

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `static interface` | `GenericMetadataSupport.BoundedType` Type representing bounds of a type
    `static class` | `GenericMetadataSupport.TypeVarBoundedType` Type representing bounds of a type variable, allows to keep all bounds information.
    `static class` | `GenericMetadataSupport.WildCardBoundedType` Type representing bounds of a wildcard, allows to keep all bounds information.

  - ### Field Summary

    Fields
    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 Summary

    Constructors
    Constructor and Description
    `GenericMetadataSupport()`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `java.util.Map<java.lang.reflect.TypeVariable,java.lang.reflect.Type>` | `actualTypeArguments()`
    `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` | `registerTypeParametersOn(java.lang.reflect.TypeVariable[] typeParameters)`
    `protected void` | `registerTypeVariablesOn(java.lang.reflect.Type classType)`
    `GenericMetadataSupport` | `resolveGenericReturnType(java.lang.reflect.Method method)` Resolve current method generic return type to a `GenericMetadataSupport`.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### contextualActualTypeParameters

          protected java.util.Map<java.lang.reflect.TypeVariable,java.lang.reflect.Type> contextualActualTypeParameters

      Represents actual type variables resolved for current class.

  - ### Constructor Detail

    - #### GenericMetadataSupport

          public GenericMetadataSupport()

  - ### Method Detail

    - #### registerTypeVariablesOn

          protected void registerTypeVariablesOn(java.lang.reflect.Type classType)

    - #### registerTypeParametersOn

          protected void registerTypeParametersOn(java.lang.reflect.TypeVariable[] typeParameters)

    - #### rawType

          public abstract java.lang.Class<?> rawType()

      Returns:
        Raw type of the current instance.

    - #### extraInterfaces

          public java.util.List<java.lang.reflect.Type> extraInterfaces()

      Returns:
        Returns extra interfaces if relevant, otherwise empty List.

    - #### rawExtraInterfaces

          public java.lang.Class<?>[] rawExtraInterfaces()

      Returns:
        Returns an array with the raw types of `extraInterfaces()` if relevant.

    - #### hasRawExtraInterfaces

          public boolean hasRawExtraInterfaces()

      Returns:
        Returns true if metadata knows about extra-interfaces `extraInterfaces()` if relevant.

    - #### actualTypeArguments

          public java.util.Map<java.lang.reflect.TypeVariable,java.lang.reflect.Type> actualTypeArguments()

      Returns:
        Actual type arguments matching the type variables of the raw type represented by this `GenericMetadataSupport` instance.

    - #### getActualTypeArgumentFor

          protected java.lang.reflect.Type getActualTypeArgumentFor(java.lang.reflect.TypeVariable typeParameter)

    - #### resolveGenericReturnType

          public GenericMetadataSupport resolveGenericReturnType(java.lang.reflect.Method method)

      Resolve current method generic return type to a `GenericMetadataSupport`.
      Parameters:
        `method` - Method to resolve the return type.
      Returns:
        `GenericMetadataSupport` representing this generic return type.

    - #### inferFrom

          public static GenericMetadataSupport inferFrom(java.lang.reflect.Type type)

      Create an new instance of `GenericMetadataSupport` inferred from a `Type`.

      At the moment `type` can only be a `Class` or a `ParameterizedType`, otherwise it'll throw a `MockitoException`.

      Parameters:
        `type` - The class from which the `GenericMetadataSupport` should be built.
      Returns:
        The new `GenericMetadataSupport`.
      Throws:
        `MockitoException` - Raised if type is not a `Class` or a `ParameterizedType`.