Class Substitution

    • Field Detail

      • EMPTY

        public static final Substitution EMPTY
        The empty substitution maps every type variable to itself.
    • Method Detail

      • isEmptySubst

        public static boolean isEmptySubst​(Function<?,​?> m)
      • apply

        public @NonNull JTypeMirror apply​(@NonNull SubstVar var)
        Returns the type with which the given variable should be replaced.
      • andThen

        public Substitution andThen​(Substitution other)
        Returns a composed substitution that first applies this substitution to its input, and then applies the after substitution to the result.

        Given two substitutions S1, S2 and a type t:
        subst(subst(t, S1), S2) == subst(t, S1.andThen(S2))

        For example:

        
          S1 = [ T -> A<U> ]
          S2 = [ U -> B<V> ]
        
          subst(List<T>, S1)    = List<A<U>>
          subst(List<A<U>>, S2) = List<A<B<V>>>
        
          S1.andThen(S2) = [ T -> A<B<V>>, U -> B<V> ]
         
        Parameters:
        other - the function to apply after this function is applied
        Returns:
        a composed substitution
        Throws:
        NullPointerException - if other is null
      • plus

        public Substitution plus​(SubstVar from,
                                 JTypeMirror to)
        Maps the given variable to the given type. This does not apply this substitution to the type mirror.
      • mapping

        public static Substitution mapping​(List<? extends SubstVar> from,
                                           List<? extends JTypeMirror> to)
        Builds a substitution where the mapping from vars to types is defined by the correspondence between the two lists.

        If there are no vars to be mapped, then no substitution is returned even though some types might have been supplied.

        Throws:
        IllegalArgumentException - If the two lists are of different lengths
        NullPointerException - If any of the two lists is null
      • erasing

        public static Substitution erasing​(List<? extends JTypeVar> tparams)
        Returns a substitution that replaces the given type variables with their erasure.
        Parameters:
        tparams - Type variables to erase
      • getMap

        protected Map<T,​R> getMap()
      • isEmpty

        public boolean isEmpty()