Package randoop.types
Class Substitution
- java.lang.Object
-
- randoop.types.Substitution
-
public class Substitution extends Object
A substitution maps type parameters/variables (including wildcards) to concrete types. It represents the instantiation of a generic class to a parameterized type.
-
-
Field Summary
Fields Modifier and Type Field Description private Map<TypeVariable,ReferenceType>
map
The map from type variables to concrete types.private Map<Type,ReferenceType>
rawMap
Map on reflection types - used for testing bounds.private static BiFunction<ReferenceType,ReferenceType,ReferenceType>
requireSameEntry
Throws an exception if its arguments are different non-null values.
-
Constructor Summary
Constructors Constructor Description Substitution()
Create an empty substitution.Substitution(List<TypeVariable> parameters, List<ReferenceType> arguments)
Create a substitution from the type parameters to the corresponding type arguments.Substitution(List<TypeVariable> parameters, ReferenceType... arguments)
Create a substitution from the type parameters to the corresponding type arguments.Substitution(Substitution substitution)
Make a copy of the given substitution.Substitution(TypeVariable parameter, ReferenceType argument)
Create a substitution that maps the given type parameter to the given type argument.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
equals(Object obj)
Substitution
extend(List<TypeVariable> parameters, List<ReferenceType> arguments)
Creates a new substitution that contains the mappings of this substitution, extended by the given mappings.Substitution
extend(Substitution other)
Creates a new substitution that contains the entries of two substitutions.ReferenceType
get(Type parameter)
Returns the value for the givenType
ReferenceType
get(TypeVariable parameter)
Returns the concrete type mapped from the type variable by this substitution.ReferenceType
getOrDefault(TypeVariable parameter, ReferenceType defaultValue)
Returns the concrete type mapped from the type variable by this substitution.int
hashCode()
boolean
isConsistentWith(Substitution substitution)
Two substitutions are consistent if their type variables are disjoint or, if they both map the same type variable, they map it to the same type.boolean
isEmpty()
Indicates whether this substitution is empty.Set<TypeVariable>
keySet()
Returns the type variables mapped from by this.void
print()
Print the entries of this substitution to standard out on multiple lines.private void
put(TypeVariable typeParameter, ReferenceType type)
Add a type variable to concrete type mapping to the substitution.String
toString()
-
-
-
Field Detail
-
map
private Map<TypeVariable,ReferenceType> map
The map from type variables to concrete types.
-
rawMap
private Map<Type,ReferenceType> rawMap
Map on reflection types - used for testing bounds. Its keys are a subset of the keys ofmap
: those that are type parameters as opposed to other type variables such as wildcards.
-
requireSameEntry
private static BiFunction<ReferenceType,ReferenceType,ReferenceType> requireSameEntry
Throws an exception if its arguments are different non-null values.
-
-
Constructor Detail
-
Substitution
public Substitution()
Create an empty substitution.
-
Substitution
public Substitution(Substitution substitution)
Make a copy of the given substitution.- Parameters:
substitution
- the substitution to copy
-
Substitution
public Substitution(TypeVariable parameter, ReferenceType argument)
Create a substitution that maps the given type parameter to the given type argument.- Parameters:
parameter
- the type parameterargument
- the type argument
-
Substitution
public Substitution(List<TypeVariable> parameters, ReferenceType... arguments)
Create a substitution from the type parameters to the corresponding type arguments.- Parameters:
parameters
- the type parametersarguments
- the type arguments
-
Substitution
public Substitution(List<TypeVariable> parameters, List<ReferenceType> arguments)
Create a substitution from the type parameters to the corresponding type arguments.- Parameters:
parameters
- the type parametersarguments
- the type arguments
-
-
Method Detail
-
equals
public boolean equals(Object obj)
-
isConsistentWith
public boolean isConsistentWith(Substitution substitution)
Two substitutions are consistent if their type variables are disjoint or, if they both map the same type variable, they map it to the same type. This is the test for whether this substitution can be extended by the other substitution usingextend(Substitution)
.- Parameters:
substitution
- the other substitution to check for consistency with this substitution- Returns:
- true if the substitutions are consistent, false otherwise
-
extend
public Substitution extend(List<TypeVariable> parameters, List<ReferenceType> arguments)
Creates a new substitution that contains the mappings of this substitution, extended by the given mappings. If this and the additional mappings contain the same type variable, both must map it to the same type.- Parameters:
parameters
- the type parametersarguments
- the type arguments- Returns:
- a new substitution that is this substitution extended by the given mappings
-
extend
public Substitution extend(Substitution other)
Creates a new substitution that contains the entries of two substitutions. If both substitutions contain the same type variable, they must map to the same type.- Parameters:
other
- the substitution to add to this substitution- Returns:
- a new substitution that is this substitution extended by the given substitution
-
get
public ReferenceType get(TypeVariable parameter)
Returns the concrete type mapped from the type variable by this substitution. Returns null if the variable is not in the substitution.- Parameters:
parameter
- the variable- Returns:
- the concrete type mapped from the variable in this substitution, or null if there is no type for the variable
-
getOrDefault
public ReferenceType getOrDefault(TypeVariable parameter, ReferenceType defaultValue)
Returns the concrete type mapped from the type variable by this substitution. Returns the given default value if the variable is not in the substitution.- Parameters:
parameter
- the variabledefaultValue
- the default value to return if the variable is not in the substitution- Returns:
- the concrete type mapped from the variable in this substitution, or
default
if there is no type for the variable
-
get
public ReferenceType get(Type parameter)
Returns the value for the givenType
- Parameters:
parameter
- the type variable- Returns:
- the value for the type variable, or null if there is none
-
keySet
public Set<TypeVariable> keySet()
Returns the type variables mapped from by this.- Returns:
- the type variables mapped from by this
-
print
public void print()
Print the entries of this substitution to standard out on multiple lines.
-
put
private void put(TypeVariable typeParameter, ReferenceType type)
Add a type variable to concrete type mapping to the substitution.- Parameters:
typeParameter
- the type variabletype
- the concrete type
-
isEmpty
public boolean isEmpty()
Indicates whether this substitution is empty.- Returns:
- true if this has no substitution pairs, false otherwise
-
-