Class CaptureTypeVariable
- java.lang.Object
-
- randoop.types.Type
-
- randoop.types.ReferenceType
-
- randoop.types.ParameterType
-
- randoop.types.TypeVariable
-
- randoop.types.CaptureTypeVariable
-
- All Implemented Interfaces:
Comparable<Type>
class CaptureTypeVariable extends TypeVariable
Represents a type variable introduced by capture conversion over a wildcard type argument.A
CaptureTypeVariable
has both an upper and lower bound determined by combining the wildcard bound with theParameterBound
on the type parameter. An object is constructed from a wildcard using the wildcard bound to determine the initial upper or lower bound. Theconvert(TypeVariable, Substitution)
method is then used to update the bounds to match the definition in JLS section 5.1.10, Capture Conversion.
-
-
Field Summary
Fields Modifier and Type Field Description private static int
count
The ID counter for capture conversion variables.private int
varID
The integer ID of this capture variable.private WildcardArgument
wildcard
The wildcard.
-
Constructor Summary
Constructors Modifier Constructor Description private
CaptureTypeVariable(int varID, WildcardArgument wildcard, ParameterBound lowerBound, ParameterBound upperBound)
Creates aCaptureTypeVariable
with explicitly givenID
, wildcard, and bounds.(package private)
CaptureTypeVariable(WildcardArgument wildcard)
Creates aCaptureTypeVariable
for the given wildcard.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
convert(TypeVariable typeParameter, Substitution substitution)
Converts the bounds on thisCaptureTypeVariable
by including those of the formal type parameters of the generic type, and applying the implied substitution between the type parameters and capture conversion argument list.TypeVariable
createCopyWithBounds(ParameterBound lowerBound, ParameterBound upperBound)
boolean
equals(Object obj)
String
getBinaryName()
Returns the binary name of this type, including type arguments if this is a parameterized type (so, it isn't really a binary name).String
getFqName()
Returns the fully-qualified name of this type, including type arguments if this is a parameterized type.String
getSimpleName()
Returns the name of this type without type arguments or package qualifiers.(package private) WildcardArgument
getWildcard()
Returns the wildcard.boolean
hasCaptureVariable()
Indicates whether thisReferenceType
has a capture variable.int
hashCode()
boolean
isCaptureVariable()
Indicates whether this type is a capture type variable as constructed byInstantiatedType.applyCaptureConversion()
.boolean
isGeneric(boolean ignoreWildcards)
Indicate whether this type is generic.ReferenceType
substitute(Substitution substitution)
Applies a substitution to aReferenceType
.String
toString()
-
Methods inherited from class randoop.types.TypeVariable
canBeInstantiatedBy, forType, getRawtype, getTypeParameters, isAssignableFrom, isInstantiationOf, isSubtypeOf, isVariable
-
Methods inherited from class randoop.types.ParameterType
getCanonicalName, getLowerTypeBound, getRuntimeClass, getUpperTypeBound, hasGenericBound, hasWildcard, setLowerBound, setUpperBound
-
Methods inherited from class randoop.types.ReferenceType
applyCaptureConversion, forClass, getInstantiatingSubstitution, getInstantiatingSubstitutionforTypeVariable, isReferenceType
-
Methods inherited from class randoop.types.Type
compareTo, forFullyQualifiedName, forName, forValue, getTypeforFullyQualifiedName, getUnqualifiedBinaryName, isArray, isAssignableFromTypeOf, isBoxedPrimitive, isClass, isClassOrInterfaceType, isEnum, isGeneric, isInterface, isNonreceiverType, isObject, isParameterized, isPrimitive, isRawtype, isString, isVoid, runtimeClassIs
-
-
-
-
Field Detail
-
count
private static int count
The ID counter for capture conversion variables.
-
varID
private final int varID
The integer ID of this capture variable.
-
wildcard
private final WildcardArgument wildcard
The wildcard.
-
-
Constructor Detail
-
CaptureTypeVariable
CaptureTypeVariable(WildcardArgument wildcard)
Creates aCaptureTypeVariable
for the given wildcard. Created object is not complete untilconvert(TypeVariable, Substitution)
is run.- Parameters:
wildcard
- the wildcard argument
-
CaptureTypeVariable
private CaptureTypeVariable(int varID, WildcardArgument wildcard, ParameterBound lowerBound, ParameterBound upperBound)
Creates aCaptureTypeVariable
with explicitly givenID
, wildcard, and bounds.- Parameters:
varID
- the variable ID for the created variablewildcard
- the wildcard for the created variablelowerBound
- the lower type bound of the variableupperBound
- the upper type bound of the variable
-
-
Method Detail
-
getWildcard
WildcardArgument getWildcard()
Returns the wildcard.- Returns:
- the wildcard
-
equals
public boolean equals(Object obj)
- Overrides:
equals
in classParameterType
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classParameterType
-
toString
public String toString()
- Overrides:
toString
in classParameterType
-
convert
public void convert(TypeVariable typeParameter, Substitution substitution)
Converts the bounds on thisCaptureTypeVariable
by including those of the formal type parameters of the generic type, and applying the implied substitution between the type parameters and capture conversion argument list. Implements the clauses of the JLS section 5.1.10, Capture Conversion.Creates an upper bound on a type variable resulting from a capture conversion (JLS section 5.1.10) in the case that a wildcard has an upper bound other than Object. In particular, each object represents a bound on a variable
Si
in a parameterized typeC<S1,...,Sn>
defined asglb(Bi, Ui[Ai:=Si])
whereUi
is the upper bound on the type variableAi
in the declared classC<A1,...,An>
,glb(S, T)
for typesS
andT
is the intersection typeS & T
.
S
andT
are both class types not related as subtypes, then the greatest lower bound of the two types is a compiler error. Technically it is the null type.- Parameters:
typeParameter
- the formal type parameter of the generic typesubstitution
- the capture conversion substitution
-
getFqName
public String getFqName()
Description copied from class:Type
Returns the fully-qualified name of this type, including type arguments if this is a parameterized type. Forjava.util.List<T>
return"java.util.List<T>"
.
-
getBinaryName
public String getBinaryName()
Description copied from class:Type
Returns the binary name of this type, including type arguments if this is a parameterized type (so, it isn't really a binary name). Forjava.util.List<T>
return"java.util.List<T>"
.- Specified by:
getBinaryName
in classType
- Returns:
- the binary name for this type
-
getSimpleName
public String getSimpleName()
Description copied from class:Type
Returns the name of this type without type arguments or package qualifiers. Forjava.util.List<T>
, returns"List"
.- Specified by:
getSimpleName
in classType
- Returns:
- the name of this type without type arguments
-
isCaptureVariable
public boolean isCaptureVariable()
Description copied from class:ReferenceType
Indicates whether this type is a capture type variable as constructed byInstantiatedType.applyCaptureConversion()
. A capture type variable can only occur as a type argument in anInstantiatedType
constructed byInstantiatedType.applyCaptureConversion()
.- Overrides:
isCaptureVariable
in classReferenceType
- Returns:
- true if this type is a capture type variable, false otherwise
-
hasCaptureVariable
public boolean hasCaptureVariable()
Description copied from class:Type
Indicates whether thisReferenceType
has a capture variable.- Overrides:
hasCaptureVariable
in classParameterType
- Returns:
- true iff this type has a capture variable
-
isGeneric
public boolean isGeneric(boolean ignoreWildcards)
Description copied from class:Type
Indicate whether this type is generic. A type is generic if it has one or more type variables.
-
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.- Overrides:
substitute
in classTypeVariable
- Parameters:
substitution
- the type substitution- Returns:
- the type created by applying the substitution to this type
-
createCopyWithBounds
public TypeVariable createCopyWithBounds(ParameterBound lowerBound, ParameterBound upperBound)
- Specified by:
createCopyWithBounds
in classTypeVariable
-
-