public class TypeInstantiator
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
private static boolean |
debug
Whether to log information about instantiation.
|
private java.util.Set<Type> |
inputTypes
The set of input types for this model.
|
Constructor and Description |
---|
TypeInstantiator(java.util.Set<Type> inputTypes)
Creates a
TypeInstantiator object using the given types to construct instantiating
substitutions. |
Modifier and Type | Method and Description |
---|---|
private java.util.List<Substitution> |
allExtendingSubstitutions(java.util.List<TypeVariable> typeParameters,
Substitution substitution)
Returns all substitutions that extend a substitution for the given type parameters.
|
private java.util.List<Substitution> |
allSubstitutions(java.util.List<TypeVariable> parameters,
Substitution initialSubstitution,
BoundsCheck boundsCheck)
Adds instantiating substitutions for the given parameters to the list if satisfies the given
type check predicate.
|
private java.util.List<java.util.List<ReferenceType>> |
candidateTypes(java.util.List<TypeVariable> parameters)
Constructs the list of lists of candidate types for the given type parameters.
|
private java.util.List<ReferenceType> |
candidateTypes(TypeVariable argument)
Returns all input types that potentially satisfy the bounds on the argument.
|
private ParameterBound |
getLowerBound(TypeVariable argument)
Gets the lower bound of the given argument to be tested in
candidateTypes(TypeVariable) . |
private ParameterBound |
getUpperBound(TypeVariable argument)
Gets the upper bound of the given argument to test in
candidateTypes(TypeVariable) . |
@Nullable TypedClassOperation |
instantiate(TypedClassOperation operation)
Instantiate the given operation by choosing type arguments for its type parameters.
|
private @Nullable Substitution |
instantiateClass(ClassOrInterfaceType type)
Chooses an instantiating substitution for the given class.
|
private TypedClassOperation |
instantiateOperationTypes(TypedClassOperation operation)
Selects an instantiation of the generic types of an operation, and returns a new operation with
the types instantiated.
|
private Substitution |
instantiateSortedSetType(TypedClassOperation operation)
Returns a substitution that instantiates the
SortedSet type of the given constructor. |
private Substitution |
selectSubstitution(ClassOrInterfaceType type)
Selects an existing type that instantiates the given generic declaring type and returns the
instantiating substitution.
|
private Substitution |
selectSubstitution(ClassOrInterfaceType type,
ClassOrInterfaceType patternType)
Returns a substitution that instantiates both
type and patternType to an
existing type. |
private Substitution |
selectSubstitution(java.util.List<TypeVariable> typeParameters)
Selects an instantiating substitution for the given list of type variables.
|
private Substitution |
selectSubstitution(java.util.List<TypeVariable> typeParameters,
Substitution substitution)
Extends the given substitution by instantiations for the given list of type variables.
|
private Substitution |
selectSubstitutionForSortedSet(GenericClassType searchType,
TypeVariable typeParameter)
Select a substitution for the type parameter of SortedSet.
|
private Substitution |
selectSubstitutionIndependently(java.util.List<TypeVariable> parameters,
Substitution substitution)
Selects types independently for a list of type parameters, and extends the given substitution
by the substitution of the selected types for the parameters.
|
private static final boolean debug
private final java.util.Set<Type> inputTypes
public TypeInstantiator(java.util.Set<Type> inputTypes)
TypeInstantiator
object using the given types to construct instantiating
substitutions.inputTypes
- the ground types for instantiationspublic @Nullable TypedClassOperation instantiate(TypedClassOperation operation)
operation
- the generic operation to instantiateprivate Substitution instantiateSortedSetType(TypedClassOperation operation)
SortedSet
type of the given constructor. A
SortedSet
may be built so that the element type E
is ordered either explicitly
with a Comparator<E>
, or the element type satisfies E implements Comparable<E>
.operation
- a constructor to be instantiated, for a class that implements SortedSet
SortedSet
typeprivate Substitution selectSubstitutionForSortedSet(GenericClassType searchType, TypeVariable typeParameter)
searchType
- one of Comparator, Comparable, or SortedSettypeParameter
- the type parameter to create an instantiation forprivate @Nullable Substitution instantiateClass(ClassOrInterfaceType type)
type
- the type to be instantiatedprivate Substitution selectSubstitution(ClassOrInterfaceType type, ClassOrInterfaceType patternType)
type
and patternType
to an
existing type. The pattern type makes it possible to select matches for partial instantiations
of a generic type.type
- the generic type for which an instantiation is to be foundpatternType
- an instantiation of type
; only further instantiations of it are
consideredtype
's type parameters to existing types; null if
no such substitution existsprivate Substitution selectSubstitution(ClassOrInterfaceType type)
type
- the generic type for which an instantiation is to be foundprivate TypedClassOperation instantiateOperationTypes(TypedClassOperation operation)
operation
- the operationprivate Substitution selectSubstitution(java.util.List<TypeVariable> typeParameters)
typeParameters
- the type variables to be instantiatedselectSubstitution(List, Substitution)
private Substitution selectSubstitution(java.util.List<TypeVariable> typeParameters, Substitution substitution)
typeParameters
- the type variables to be instantiatedsubstitution
- the substitution to extendprivate java.util.List<Substitution> allExtendingSubstitutions(java.util.List<TypeVariable> typeParameters, Substitution substitution)
typeParameters
- the type parameters to be instantiatedsubstitution
- the substitution to be extendedprivate Substitution selectSubstitutionIndependently(java.util.List<TypeVariable> parameters, Substitution substitution)
IMPORTANT: Should only be used for parameters that have non-generic bounds.
parameters
- a list of independent type parameterssubstitution
- the substitution to extendprivate java.util.List<Substitution> allSubstitutions(java.util.List<TypeVariable> parameters, Substitution initialSubstitution, BoundsCheck boundsCheck)
parameters
- the list of parameters to instantiateinitialSubstitution
- the substitution to be extended by new substitutionsboundsCheck
- the predicate to type check a substitutionprivate java.util.List<java.util.List<ReferenceType>> candidateTypes(java.util.List<TypeVariable> parameters)
parameters
, as determined by
candidateTypes(TypeVariable)
.parameters
- the list of type parametersprivate java.util.List<ReferenceType> candidateTypes(TypeVariable argument)
allSubstitutions(java.util.List<randoop.types.TypeVariable>, randoop.types.Substitution, randoop.types.BoundsCheck)
will ensure that the final substitution is consistent.argument
- the type argumentprivate ParameterBound getUpperBound(TypeVariable argument)
candidateTypes(TypeVariable)
. If
the bound contains a type parameter other than the given argument, then returns Object
as the bound.argument
- the type argumentObject
bound otherwiseprivate ParameterBound getLowerBound(TypeVariable argument)
candidateTypes(TypeVariable)
. If the bound has a type parameter other than the given
argument, then returns JavaTypes.NULL_TYPE
as the bound.argument
- the type argumentJavaTypes.NULL_TYPE
otherwise