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 fromSubstVars 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 SubstitutionEMPTYThe empty substitution maps every type variable to itself.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description SubstitutionandThen(Substitution other)Returns a composed substitution that first applies this substitution to its input, and then applies theaftersubstitution to the result.@NonNull JTypeMirrorapply(@NonNull SubstVar var)Returns the type with which the given variable should be replaced.static Substitutionerasing(List<? extends JTypeVar> tparams)Returns a substitution that replaces the given type variables with their erasure.protected Map<T,R>getMap()booleanisEmpty()static booleanisEmptySubst(Function<?,?> m)static Substitutionmapping(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.Substitutionplus(SubstVar from, JTypeMirror to)Maps the given variable to the given type.StringtoString()
-
-
-
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 theaftersubstitution 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()
-
-