public class TypeArgumentMapper extends Object
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 and Description |
---|
TypeArgumentMapper() |
Modifier and Type | Method and Description |
---|---|
static Set<Pair<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.
|
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.
|
public static Set<Pair<Integer,Integer>> mapTypeArgumentIndices(TypeElement subtype, TypeElement supertype, Types types)
public static Map<TypeParameterElement,Set<TypeParameterElement>> mapTypeArguments(TypeElement subtype, TypeElement supertype, Types types)
e.g.,
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 ⇒ [])