Package randoop.types
Class ParameterBound
- java.lang.Object
-
- randoop.types.ParameterBound
-
- Direct Known Subclasses:
IntersectionTypeBound
,LazyParameterBound
,ReferenceBound
public abstract class ParameterBound extends Object
Represents a type bound on a type variable or wildcard occurring as a type parameter of a generic class, interface, method or constructor.Type bounds for explicitly defined type variables of generic declarations are defined in JLS section 8.1.2 as
TypeBound: extends TypeVariable extends ClassOrInterfaceType [ & InterfaceType ]
Type bounds for wildcards may be any reference type, which includes type variables, so theParameterBound
class hierarchy is simplified to use thisReferenceType
objects as bounds. Intersection types (which includes the greatest lower bound construction used in capture conversion) are explicitly represented. And, recursive type bounds are avoided by holding anyjava.lang.reflect.Type
with variables as aLazyParameterBound
.Type parameters only have upper bounds, but variables introduced by capture conversion can have lower bounds. This class and its subclasses can represent both, with the default lower bound being
JavaTypes.NULL_TYPE
, and the default upperbound beingJavaTypes.OBJECT_TYPE
.
-
-
Constructor Summary
Constructors Constructor Description ParameterBound()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract ParameterBound
applyCaptureConversion()
Applies a capture conversion to any wildcard arguments in the type of this bound.(package private) static ParameterBound
forType(Set<TypeVariable<?>> variableSet, Type type)
Creates aParameterBound
object from a singlejava.lang.reflect.Type
.static ParameterBound
forType(ReferenceType type)
Constructs a parameter bound given aReferenceType
.(package private) static ParameterBound
forTypes(Set<TypeVariable<?>> variableSet, Type[] bounds)
Creates a bound from the array of bounds of ajava.lang.reflect.TypeVariable
.abstract List<TypeVariable>
getTypeParameters()
Returns any type parameters in the type of this bound.(package private) abstract boolean
hasCaptureVariable()
Indicates whether the type of this bound has a capture variable.private static boolean
hasTypeVariable(Type type, Set<TypeVariable<?>> variableSet)
Indicates whether the given (reflection) type reference represents a type in which a type variable occurs.(package private) abstract boolean
hasWildcard()
Indicates whether the type of this bound has a wildcard type argument.(package private) boolean
isGeneric()
Indicates whether the type of this bound is generic.abstract boolean
isGeneric(boolean ignoreWildcards)
Indicates whether the type of this bound is generic.(package private) boolean
isLowerBound(ParameterBound bound, Substitution substitution)
Tests whether this is a lower bound on the type of a given bound with respect to a type substitution.abstract boolean
isLowerBound(Type argType, Substitution subst)
Indicates whether this bound is a lower bound of the given argument type.abstract boolean
isObject()
Indicate whether this bound isObject
.abstract boolean
isSubtypeOf(ParameterBound boundType)
Indicates whether the type of this bound is a subtype of the type of the given bound.(package private) static boolean
isTypeVariable(Type type)
Indicates whether the type is a type variable.(package private) abstract boolean
isUpperBound(ParameterBound bound, Substitution substitution)
Indicates whether this bound is an upper bound on the type of the given bound with respect to the type substitution.abstract boolean
isUpperBound(Type argType, Substitution subst)
Determines if this bound is an upper bound for the argument type.boolean
isVariable()
Indicates whether this bound is a type variable.abstract ParameterBound
substitute(Substitution substitution)
Applies the given substitution to this type bound by replacing type variables.
-
-
-
Method Detail
-
forType
public static ParameterBound forType(ReferenceType type)
Constructs a parameter bound given aReferenceType
.- Parameters:
type
- theReferenceType
- Returns:
- a
EagerReferenceBound
with the given type
-
forTypes
static ParameterBound forTypes(Set<TypeVariable<?>> variableSet, Type[] bounds)
Creates a bound from the array of bounds of ajava.lang.reflect.TypeVariable
.The bounds of a type parameter are restricted, but those of a wildcard may be any reference type. See JLS section 8.1.2.
- Parameters:
variableSet
- the set of variables affected by this boundbounds
- the type bounds- Returns:
- the
ParameterBound
for the given types
-
forType
static ParameterBound forType(Set<TypeVariable<?>> variableSet, Type type)
Creates aParameterBound
object from a singlejava.lang.reflect.Type
. Tests for types that are represented byClass
objects, orjava.lang.reflect.ParameterizedType
objects.- Parameters:
variableSet
- the set of type variables bound by this typetype
- the type for type bound- Returns:
- a type bound that ensures the given type is satisfied as an upper bound
-
substitute
public abstract ParameterBound substitute(Substitution substitution)
Applies the given substitution to this type bound by replacing type variables.- Parameters:
substitution
- the type substitution- Returns:
- this bound with the type after the substitution has been applied
-
applyCaptureConversion
public abstract ParameterBound applyCaptureConversion()
Applies a capture conversion to any wildcard arguments in the type of this bound.- Returns:
- this type with any wildcards replaced by capture conversion
- See Also:
ReferenceType.applyCaptureConversion()
-
getTypeParameters
public abstract List<TypeVariable> getTypeParameters()
Returns any type parameters in the type of this bound.- Returns:
- the list of
TypeVariable
objects in this bound
-
hasTypeVariable
private static boolean hasTypeVariable(Type type, Set<TypeVariable<?>> variableSet)
Indicates whether the given (reflection) type reference represents a type in which a type variable occurs.- Parameters:
type
- the reflection typevariableSet
- the set of variables- Returns:
- true if the type has a type variable, and false otherwise
-
isTypeVariable
static boolean isTypeVariable(Type type)
Indicates whether the type is a type variable.- Parameters:
type
- the type to test- Returns:
- true if the type is a type variable, false otherwise
-
hasWildcard
abstract boolean hasWildcard()
Indicates whether the type of this bound has a wildcard type argument.- Returns:
- true, if this bound has a wildcard argument, and false otherwise
-
hasCaptureVariable
abstract boolean hasCaptureVariable()
Indicates whether the type of this bound has a capture variable.- Returns:
- true iff this bound has a capture variable
-
isGeneric
final boolean isGeneric()
Indicates whether the type of this bound is generic.- Returns:
- true, if this bound type is generic, and false otherwise
-
isGeneric
public abstract boolean isGeneric(boolean ignoreWildcards)
Indicates whether the type of this bound is generic.- Parameters:
ignoreWildcards
- if true, ignore wildcards; that is, treat wildcards as not making the operation generic- Returns:
- true, if this bound type is generic, and false otherwise
-
isLowerBound
public abstract boolean isLowerBound(Type argType, Substitution subst)
Indicates whether this bound is a lower bound of the given argument type.- Parameters:
argType
- the concrete argument typesubst
- the substitution- Returns:
- true if this bound is a subtype of the given type
-
isLowerBound
boolean isLowerBound(ParameterBound bound, Substitution substitution)
Tests whether this is a lower bound on the type of a given bound with respect to a type substitution. The body is approximately:return this.substitute(substitution).isLowerBound(bound.substitute(substitution);
- Parameters:
bound
- the other boundsubstitution
- the type substitution- Returns:
- true iff this bound is a lower bound on the type of the given bound
-
isObject
public abstract boolean isObject()
Indicate whether this bound isObject
.- Returns:
- true if this bound is
Object
, false otherwise
-
isSubtypeOf
public abstract boolean isSubtypeOf(ParameterBound boundType)
Indicates whether the type of this bound is a subtype of the type of the given bound.- Parameters:
boundType
- the other bound- Returns:
- true if this type is a subtype of the other bound, false otherwise
-
isUpperBound
public abstract boolean isUpperBound(Type argType, Substitution subst)
Determines if this bound is an upper bound for the argument type.- Parameters:
argType
- the concrete argument typesubst
- the substitution- Returns:
- true if this bound is satisfied by the concrete type when the substitution is used on the bound, false otherwise
-
isUpperBound
abstract boolean isUpperBound(ParameterBound bound, Substitution substitution)
Indicates whether this bound is an upper bound on the type of the given bound with respect to the type substitution.- Parameters:
bound
- the other boundsubstitution
- the type substitution- Returns:
- true if this bound is an upper bound on the type of the given bound, false otherwise
-
isVariable
public boolean isVariable()
Indicates whether this bound is a type variable.- Returns:
- true if this bound is a type variable, false otherwise
-
-