Class TypeArgumentMapper


public class TypeArgumentMapper extends Object
Records any mapping between the type parameters of a subtype to the corresponding type parameters of a supertype. For example, suppose we have the following classes:

 class Map<M1,M2>
 class HashMap<H1, H2> extends Map<H1,H2>
And we pass HashMap and Map to mapTypeArguments, the result would be:

 Map(H1 => M1, H2 => M2)
Note, a single type argument in the subtype can map to multiple type parameters in the supertype. e.g.,

 class OneTypeMap<O1> extends Map<O1,O1>
would have the result:

 Map(O1 => [M1,M2])
This utility only maps between corresponding type parameters, so the following class:

 class StringMap extends Map<String,String>
would have an empty map as a result:

 Map() // there are no type argument relationships between the two types
  • Constructor Details

    • TypeArgumentMapper

      public TypeArgumentMapper()
  • Method Details

    • mapTypeArgumentIndices

      public static Set<org.plumelib.util.IPair<Integer,Integer>> mapTypeArgumentIndices(TypeElement subtype, TypeElement supertype, Types types)
      Returns a mapping from subtype's type parameter indices to the indices of corresponding type parameters in supertype.
    • mapTypeArguments

      public static Map<TypeParameterElement,Set<TypeParameterElement>> mapTypeArguments(TypeElement subtype, TypeElement supertype, Types types)
      Returns a mapping from the type parameters of subtype to a list of the type parameters in supertype that must be the same type as subtype.


       class A<A1,A2,A3>
       class B<B1,B2,B3,B4> extends A<B1,B1,B3> {}
      results in a Map(B1 => [A1,A2], B2 => [], B3 => [A3], B4 => [])
      a mapping from the type parameters of subtype to the supertype type parameter's that to which they are a type argument