Class GenericMetadataSupport

java.lang.Object
org.mockito.internal.util.reflection.GenericMetadataSupport
Direct Known Subclasses:
GenericMetadataSupport.FromClassGenericMetadataSupport, GenericMetadataSupport.FromParameterizedTypeGenericMetadataSupport, GenericMetadataSupport.GenericArrayReturnType, GenericMetadataSupport.NotGenericReturnTypeSupport, GenericMetadataSupport.ParameterizedReturnType, GenericMetadataSupport.TypeVariableReturnType

public abstract class GenericMetadataSupport extends 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:
  • Field Details

    • contextualActualTypeParameters

      protected Map<TypeVariable<?>,Type> contextualActualTypeParameters
      Represents actual type variables resolved for current class.
  • Constructor Details

    • GenericMetadataSupport

      public GenericMetadataSupport()
  • Method Details