Class Substitution
java.lang.Object
net.sourceforge.pmd.lang.java.types.Substitution
- All Implemented Interfaces:
Function<SubstVar,JTypeMirror>
A function from
SubstVars to types. Applying it to a type
replaces the occurrences of some variables with other types. This
can be done with TypeOps.subst(JTypeMirror, Function).-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final SubstitutionThe empty substitution maps every type variable to itself. -
Method Summary
Modifier and TypeMethodDescriptionandThen(Substitution other) Returns a composed substitution that first applies this substitution to its input, and then applies theaftersubstitution to the result.@NonNull JTypeMirrorReturns the type with which the given variable should be replaced.static SubstitutionReturns a substitution that replaces the given type variables with their erasure.protected Map<@NonNull SubstVar, @NonNull JTypeMirror> 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.plus(SubstVar from, JTypeMirror to) Maps the given variable to the given type.toString()
-
Field Details
-
EMPTY
The empty substitution maps every type variable to itself.
-
-
Method Details
-
isEmptySubst
-
apply
Returns the type with which the given variable should be replaced. -
andThen
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
Maps the given variable to the given type. This does not apply this substitution to the type mirror. -
mapping
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
Returns a substitution that replaces the given type variables with their erasure.- Parameters:
tparams- Type variables to erase
-
getMap
-
isEmpty
public boolean isEmpty() -
toString
-