Class Substitution
- java.lang.Object
-
- net.sourceforge.pmd.lang.java.types.Substitution
-
- All Implemented Interfaces:
Function<SubstVar,JTypeMirror>
public final class Substitution extends Object
A function fromSubstVar
s to types. Applying it to a type replaces the occurrences of some variables with other types. This can be done withTypeOps.subst(JTypeMirror, Function)
.
-
-
Field Summary
Fields Modifier and Type Field Description static Substitution
EMPTY
The empty substitution maps every type variable to itself.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Substitution
andThen(Substitution other)
Returns a composed substitution that first applies this substitution to its input, and then applies theafter
substitution to the result.@NonNull JTypeMirror
apply(@NonNull SubstVar var)
Returns the type with which the given variable should be replaced.static Substitution
erasing(List<? extends JTypeVar> tparams)
Returns a substitution that replaces the given type variables with their erasure.protected Map<T,R>
getMap()
boolean
isEmpty()
static boolean
isEmptySubst(Function<?,?> m)
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.Substitution
plus(SubstVar from, JTypeMirror to)
Maps the given variable to the given type.String
toString()
-
-
-
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 theafter
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 lengthsNullPointerException
- 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()
-
-