Class TypeArgumentMapper


  • public class TypeArgumentMapper
    extends java.lang.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
     
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.util.Set<org.plumelib.util.IPair<java.lang.Integer,​java.lang.Integer>> mapTypeArgumentIndices​(javax.lang.model.element.TypeElement subtype, javax.lang.model.element.TypeElement supertype, javax.lang.model.util.Types types)
      Returns a mapping from subtype's type parameter indices to the indices of corresponding type parameters in supertype.
      static java.util.Map<javax.lang.model.element.TypeParameterElement,​java.util.Set<javax.lang.model.element.TypeParameterElement>> mapTypeArguments​(javax.lang.model.element.TypeElement subtype, javax.lang.model.element.TypeElement supertype, javax.lang.model.util.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.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • TypeArgumentMapper

        public TypeArgumentMapper()
    • Method Detail

      • mapTypeArgumentIndices

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

        public static java.util.Map<javax.lang.model.element.TypeParameterElement,​java.util.Set<javax.lang.model.element.TypeParameterElement>> mapTypeArguments​(javax.lang.model.element.TypeElement subtype,
                                                                                                                                                                       javax.lang.model.element.TypeElement supertype,
                                                                                                                                                                       javax.lang.model.util.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.

        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 => [])
        Returns:
        a mapping from the type parameters of subtype to the supertype type parameter's that to which they are a type argument