Class VariableTypeInheritanceSearch


  • public class VariableTypeInheritanceSearch
    extends Object
    Search for type variable in inheritance hierarchy and resolve if possible.
    Author:
    Roman Grigoriadi
    • Constructor Detail

      • VariableTypeInheritanceSearch

        public VariableTypeInheritanceSearch()
    • Method Detail

      • searchParametrizedType

        public Type searchParametrizedType​(Type typeToSearch,
                                           TypeVariable<?> typeVar)
        Searches the hierarchy of classes to resolve a type variable. If typevar resolved value is another typevar redirection (propagated from wrapping class), this typevar is returned.
        
         Example 1: typevar is resolved
        
        
         class GenericClass <T> {
             private T genericField;
         }
         class ConcreteClass extends GenericClass<MyPojo> {
             //...
         }
        
         In above case when ConcreteClass type is passed as runtime type and <T> as type variable, T is resolved to MyPojo.
         
         Example 2: typevar is resolved to another propagated typevar
        
        
         class WrapperGenericClass<X> {
             private GenericClass<X> propagatedGenericField
         }
        
         class AnotherClass extends WrapperGenericClass<MyPojo> {
         }
        
        
         In second case when GenericClass ParameterizedType is passed as runtime type and <T> as type variable,
         T is resolved to propagated <X> by WrapperGenericClass.
        
         Resolution on <X> must be performed thereafter with AnotherClass runtime type.
         
        Parameters:
        typeToSearch - runtime type to search for typevar in, not null
        typeVar - type variable to resolve, not null
        Returns:
        resolved runtime type, or type variable