Class TypeVariable
- java.lang.Object
-
- randoop.types.Type
-
- randoop.types.ReferenceType
-
- randoop.types.ParameterType
-
- randoop.types.TypeVariable
-
- All Implemented Interfaces:
Comparable<Type>
- Direct Known Subclasses:
CaptureTypeVariable
,ExplicitTypeVariable
public abstract class TypeVariable extends ParameterType
An abstract class representing type variables.
-
-
Constructor Summary
Constructors Constructor Description TypeVariable()
Creates a type variable withNullReferenceType
as the lower bound, and theObject
type as upper bound.TypeVariable(ParameterBound lowerBound, ParameterBound upperBound)
Creates a type variable with the given type bounds.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description (package private) boolean
canBeInstantiatedBy(ReferenceType otherType)
Indicates whether thisTypeVariable
can be instantiated by theReferenceType
.abstract TypeVariable
createCopyWithBounds(ParameterBound lowerBound, ParameterBound upperBound)
static TypeVariable
forType(Type type)
Creates aTypeVariable
object for a givenjava.lang.reflect.Type
reference, which must be ajava.lang.reflect.TypeVariable
.Type
getRawtype()
Returns the raw type for this type, which is this type except for generic types.private static Substitution
getSubstitution(TypeVariable variable, ReferenceType otherType)
Creates a substitution of the givenReferenceType
for theTypeVariable
.List<TypeVariable>
getTypeParameters()
Returns the type parameters in this type, which is this variable.boolean
isAssignableFrom(Type sourceType)
Indicates whether there is an assignment conversion from a sourceType
to this type.boolean
isInstantiationOf(ReferenceType otherType)
Indicates whether this type is an instantiation of a more general type.boolean
isSubtypeOf(Type otherType)
Test whether this type is a subtype of the given type according to transitive closure of definition of the direct supertype relation in section 4.10 of JLS for Java SE 8.boolean
isVariable()
Indicates whether this type is a type variable.ReferenceType
substitute(Substitution substitution)
Applies a substitution to aReferenceType
.-
Methods inherited from class randoop.types.ParameterType
equals, getCanonicalName, getLowerTypeBound, getRuntimeClass, getUpperTypeBound, hasCaptureVariable, hasGenericBound, hashCode, hasWildcard, setLowerBound, setUpperBound, toString
-
Methods inherited from class randoop.types.ReferenceType
applyCaptureConversion, forClass, getInstantiatingSubstitution, getInstantiatingSubstitutionforTypeVariable, isCaptureVariable, isReferenceType
-
Methods inherited from class randoop.types.Type
compareTo, forFullyQualifiedName, forName, forValue, getBinaryName, getFqName, getSimpleName, getTypeforFullyQualifiedName, getUnqualifiedBinaryName, isArray, isAssignableFromTypeOf, isBoxedPrimitive, isClass, isClassOrInterfaceType, isEnum, isGeneric, isGeneric, isInterface, isNonreceiverType, isObject, isParameterized, isPrimitive, isRawtype, isString, isVoid, runtimeClassIs
-
-
-
-
Constructor Detail
-
TypeVariable
TypeVariable()
Creates a type variable withNullReferenceType
as the lower bound, and theObject
type as upper bound.
-
TypeVariable
TypeVariable(ParameterBound lowerBound, ParameterBound upperBound)
Creates a type variable with the given type bounds. Assumes the bounds are consistent and does not check for the subtype relationship.- Parameters:
lowerBound
- the lower type bound on this variableupperBound
- the upper type bound on this variable
-
-
Method Detail
-
forType
public static TypeVariable forType(Type type)
Creates aTypeVariable
object for a givenjava.lang.reflect.Type
reference, which must be ajava.lang.reflect.TypeVariable
.- Parameters:
type
- the type reference- Returns:
- the
TypeVariable
for the given type
-
substitute
public ReferenceType substitute(Substitution substitution)
Description copied from class:ReferenceType
Applies a substitution to aReferenceType
. If the type is parameterized then replaces type variables that occur, otherwise returns this type.This abstract method forces typing of substitutions applied to
ReferenceType
objects without an explicit cast.- Specified by:
substitute
in classReferenceType
- Parameters:
substitution
- the type substitution- Returns:
- the type created by applying the substitution to this type
-
isAssignableFrom
public boolean isAssignableFrom(Type sourceType)
Indicates whether there is an assignment conversion from a sourceType
to this type. (In other words, a value of the source type can be assigned to an l-value of this type.) Returns true if this is a legal assignment conversion:Variablethis = Expressionsourcetype.
Based on the definition of assignment context in section 5.2 of the Java Language Specification, a value of one type is assignable to a variable of another type if the first type can be converted to the second by
- an identity conversion (section 5.1.1),
- a widening primitive conversion (section 5.1.2),
- a widening reference conversion (section 5.1.5),
- a boxing conversion (5.1.7), or
- an unboxing conversion (section 5.1.8) possibly followed by a widening conversion.
For assignment to
ReferenceType
, checks for widening reference conversion when the source type is also a reference type. See section JLS 5.1.5 for details.Returns false, since an uninstantiated type variable may not be assigned to.
- Overrides:
isAssignableFrom
in classReferenceType
- Parameters:
sourceType
- the type to test for assignability- Returns:
- true if this type can be assigned from the source type, and false otherwise
-
isInstantiationOf
public boolean isInstantiationOf(ReferenceType otherType)
Description copied from class:ReferenceType
Indicates whether this type is an instantiation of a more general type.For a general
ReferenceType
, this is only true if the other type is the same, or the other type is a type variable for which this type satisfies the bounds. Other cases are handled by the overriding implementationsClassOrInterfaceType.isInstantiationOf(ReferenceType)
,InstantiatedType.isInstantiationOf(ReferenceType)
, andisInstantiationOf(ReferenceType)
.- Overrides:
isInstantiationOf
in classReferenceType
- Parameters:
otherType
- the general reference type- Returns:
- true if this type instantiates the other reference type, false otherwise
-
isSubtypeOf
public boolean isSubtypeOf(Type otherType)
Description copied from class:ReferenceType
Test whether this type is a subtype of the given type according to transitive closure of definition of the direct supertype relation in section 4.10 of JLS for Java SE 8.For
ReferenceType
, returns true ifotherType
isObject
.- Overrides:
isSubtypeOf
in classReferenceType
- Parameters:
otherType
- the possible supertype- Returns:
- true if this type is a subtype of the given type, false otherwise
-
getSubstitution
private static Substitution getSubstitution(TypeVariable variable, ReferenceType otherType)
Creates a substitution of the givenReferenceType
for theTypeVariable
.- Parameters:
variable
- the variableotherType
- the replacement type- Returns:
- a substitution that replaces
variable
withotherType
-
isVariable
public boolean isVariable()
Description copied from class:Type
Indicates whether this type is a type variable.- Overrides:
isVariable
in classType
- Returns:
- true if this type is a type variable, false otherwise
-
canBeInstantiatedBy
boolean canBeInstantiatedBy(ReferenceType otherType)
Indicates whether thisTypeVariable
can be instantiated by theReferenceType
. Does not require that all bounds of this variable be instantiated.- Parameters:
otherType
- the possibly instantiating type, not a variable- Returns:
- true if the given type can instantiate this variable, false otherwise
-
getTypeParameters
public List<TypeVariable> getTypeParameters()
Returns the type parameters in this type, which is this variable.- Overrides:
getTypeParameters
in classParameterType
- Returns:
- this variable
-
createCopyWithBounds
public abstract TypeVariable createCopyWithBounds(ParameterBound lowerBound, ParameterBound upperBound)
-
getRawtype
public Type getRawtype()
Description copied from class:Type
Returns the raw type for this type, which is this type except for generic types.- Overrides:
getRawtype
in classType
- Returns:
- the raw type corresponding to this type
-
-