Class GenericClassType
- java.lang.Object
-
- randoop.types.Type
-
- randoop.types.ReferenceType
-
- randoop.types.ClassOrInterfaceType
-
- randoop.types.ParameterizedType
-
- randoop.types.GenericClassType
-
- All Implemented Interfaces:
Comparable<Type>
public class GenericClassType extends ParameterizedType
Represents the type of a generic class. Related to concreteInstantiatedType
by instantiating with aSubstitution
.
-
-
Field Summary
Fields Modifier and Type Field Description private List<TypeVariable>
parameters
The type parameters of the generic class.private Class<?>
rawType
The rawtype of the generic class.-
Fields inherited from class randoop.types.ClassOrInterfaceType
enclosingType
-
-
Constructor Summary
Constructors Constructor Description GenericClassType(Class<?> rawType)
Creates aGenericClassType
for the given raw type.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description GenericClassType
applyCaptureConversion()
Applies a capture conversion to this type.boolean
equals(Object obj)
GenericClassType
getGenericClassType()
Returns theGenericClassType
for this parameterized type.List<ClassOrInterfaceType>
getInterfaces()
Returns the interface types directly implemented by this class or interface type.(package private) List<ClassOrInterfaceType>
getInterfaces(Substitution substitution)
Return the directly-implemented interface types for this generic class type, instantiated by the given typeSubstitution
.NonParameterizedType
getRawtype()
Returns the rawtypeType
for this generic class.Class<?>
getRuntimeClass()
Returns the runtimeClass
object for this type.ClassOrInterfaceType
getSuperclass()
Return the type for the superclass for this class.(package private) ClassOrInterfaceType
getSuperclass(Substitution substitution)
Returns the superclass type for this generic class type instantiated by the given typeSubstitution
.List<TypeArgument>
getTypeArguments()
Returns the type arguments for this type.List<TypeVariable>
getTypeParameters()
Returns the list of type parameters of this generic class.int
hashCode()
InstantiatedType
instantiate(List<ReferenceType> typeArguments)
Creates a type substitution using the given type arguments and applies it to this type.InstantiatedType
instantiate(ReferenceType... typeArguments)
Creates a type substitution using the given type arguments and applies it to this type.boolean
isAbstract()
Indicate whether this class is abstract.boolean
isGeneric(boolean ignoreWildcards)
Indicate whether this type is generic.boolean
isInterface()
Indicates whether this object is an interface type.boolean
isStatic()
Indicates whether this class is static.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.2 of JLS for JavaSE 8.InstantiatedType
substitute(Substitution substitution)
Instantiates this generic class using the substitution to replace the type parameters.-
Methods inherited from class randoop.types.ParameterizedType
forClass, forType, getBinaryName, getFqName, getUnqualifiedBinaryName
-
Methods inherited from class randoop.types.ClassOrInterfaceType
applyCaptureConversion, getAllSupertypesInclusive, getCanonicalName, getImmediateSupertypes, getInstantiatingSubstitution, getMatchingSupertype, getPackage, getPackagePrefix, getSimpleName, getSuperTypes, hasCaptureVariable, hasWildcard, isClassOrInterfaceType, isInstantiationOf, isMemberClass, isNestedClass, isParameterized, substitute
-
Methods inherited from class randoop.types.ReferenceType
getInstantiatingSubstitutionforTypeVariable, isAssignableFrom, isCaptureVariable, isReferenceType
-
Methods inherited from class randoop.types.Type
compareTo, forFullyQualifiedName, forName, forValue, getTypeforFullyQualifiedName, isArray, isAssignableFromTypeOf, isBoxedPrimitive, isClass, isEnum, isGeneric, isNonreceiverType, isObject, isPrimitive, isRawtype, isString, isVariable, isVoid, runtimeClassIs, toString
-
-
-
-
Field Detail
-
rawType
private Class<?> rawType
The rawtype of the generic class.
-
parameters
private List<TypeVariable> parameters
The type parameters of the generic class.
-
-
Constructor Detail
-
GenericClassType
GenericClassType(Class<?> rawType)
Creates aGenericClassType
for the given raw type.- Parameters:
rawType
- theClass
raw type
-
-
Method Detail
-
equals
public boolean equals(Object obj)
Checks that the rawtypes are the same. This is sufficient since the type parameters and their bounds can be reconstructed from the Class object. Also, parameters can be distinct depending on how this object is constructed.
- Overrides:
equals
in classClassOrInterfaceType
- Returns:
- true if two generic classes have the same rawtype, false otherwise
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classClassOrInterfaceType
-
substitute
public InstantiatedType substitute(Substitution substitution)
Instantiates this generic class using the substitution to replace the type parameters.- Specified by:
substitute
in classParameterizedType
- Parameters:
substitution
- the type substitution- Returns:
- a
ParameterizedType
instantiating this generic class by the given substitution
-
applyCaptureConversion
public GenericClassType applyCaptureConversion()
Description copied from class:Type
Applies a capture conversion to this type.- Specified by:
applyCaptureConversion
in classClassOrInterfaceType
- Returns:
- a copy of this type with wildcards replaced by type conversion
-
getInterfaces
public List<ClassOrInterfaceType> getInterfaces()
Returns the interface types directly implemented by this class or interface type. Preserves the order in the reflection methodClass.getGenericInterfaces()
. If no interfaces are implemented, then returns the empty list.Note that this method uses
Class.getInterfaces()
and does not preserve the relationship between the type parameters of a class and its interfaces, and should not be used when finding supertypes of types represented asInstantiatedType
objects.- Specified by:
getInterfaces
in classClassOrInterfaceType
- Returns:
- the list of interfaces directly implemented by this type
-
getInterfaces
List<ClassOrInterfaceType> getInterfaces(Substitution substitution)
Return the directly-implemented interface types for this generic class type, instantiated by the given typeSubstitution
.This method is not public. It is used when finding the interfaces of an
InstantiatedType
usingInstantiatedType.getInterfaces()
, where it is important that the relationship between type variables is preserved. The reflection methodClass.getGenericInterfaces()
ensures the type variable objects are the same from a class to its interfaces, which allows the use of the same substitution for both types.- Parameters:
substitution
- the type substitution- Returns:
- the list of instantiated directly-implemented interface types of this type
-
getGenericClassType
public GenericClassType getGenericClassType()
Description copied from class:ParameterizedType
Returns theGenericClassType
for this parameterized type.- Specified by:
getGenericClassType
in classParameterizedType
- Returns:
- the generic class type for this type
-
getRuntimeClass
public Class<?> getRuntimeClass()
Description copied from class:Type
Returns the runtimeClass
object for this type. For use when reflection is needed.Note that type variables and the null reference type do not have a runtime class, and this method will return null in those cases.
This method should not be confused with the inherited
Object.getClass()
method, which returns theClass<?>
for theType
object, and not of the represented type. For instance, if aType
objectt
represented the Java typeint
, thent.getRuntimeClass()
would returnint.class
whilet.getClass()
would returnType.class
.- Specified by:
getRuntimeClass
in classType
- Returns:
- the
Class
that is the runtime representation of the type, or null if this type is a type variable or null reference type
-
getSuperclass
public ClassOrInterfaceType getSuperclass()
Return the type for the superclass for this class.Note that this method uses
Class.getSuperclass()
and does not preserve the relationship between the type parameters of a class and its superclass, and should not be used when finding supertypes of types represented asInstantiatedType
objects.- Specified by:
getSuperclass
in classClassOrInterfaceType
- Returns:
- superclass of this type, or the
Object
type if this type has no superclass
-
getSuperclass
ClassOrInterfaceType getSuperclass(Substitution substitution)
Returns the superclass type for this generic class type instantiated by the given typeSubstitution
.This method is not public. It is used when finding the superclass of an
InstantiatedType
usingInstantiatedType.getSuperclass()
, where it is important that the relationship between type variables is preserved. The reflection methodClass.getGenericSuperclass()
ensures the type variable objects are the same from subclass to superclass, which allows the use of the same substitution for both types.- Parameters:
substitution
- the type substitution- Returns:
- the instantiated type
-
getTypeArguments
public List<TypeArgument> getTypeArguments()
Description copied from class:ClassOrInterfaceType
Returns the type arguments for this type.- Overrides:
getTypeArguments
in classClassOrInterfaceType
- Returns:
- the list of type arguments
-
getTypeParameters
public List<TypeVariable> getTypeParameters()
Returns the list of type parameters of this generic class.- Overrides:
getTypeParameters
in classClassOrInterfaceType
- Returns:
- the list of type parameters of this generic class
-
instantiate
public InstantiatedType instantiate(ReferenceType... typeArguments)
Creates a type substitution using the given type arguments and applies it to this type.- Parameters:
typeArguments
- the type arguments- Returns:
- a type which is this type parameterized by the given type arguments
- See Also:
substitute(Substitution)
-
instantiate
public InstantiatedType instantiate(List<ReferenceType> typeArguments)
Creates a type substitution using the given type arguments and applies it to this type.- Parameters:
typeArguments
- the type arguments- Returns:
- the type that is this type instantiated by the given type arguments
- See Also:
substitute(Substitution)
-
isAbstract
public boolean isAbstract()
Description copied from class:ClassOrInterfaceType
Indicate whether this class is abstract.- Specified by:
isAbstract
in classClassOrInterfaceType
- Returns:
- true if this class is abstract, false otherwise
-
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.- Overrides:
isGeneric
in classClassOrInterfaceType
- Parameters:
ignoreWildcards
- if true, ignore wildcards; that is, treat wildcards as not making the operation generic- Returns:
- true if this type is generic, false otherwise
-
isInterface
public boolean isInterface()
Description copied from class:Type
Indicates whether this object is an interface type.- Overrides:
isInterface
in classType
- Returns:
- true if this object is an interface type, false otherwise
-
isStatic
public boolean isStatic()
Description copied from class:ClassOrInterfaceType
Indicates whether this class is static.- Specified by:
isStatic
in classClassOrInterfaceType
- Returns:
- true if this class is static, false otherwise
-
isSubtypeOf
public 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.2 of JLS for JavaSE 8.Handles the specific cases of supertypes of a generic class
C<F1,...,Fn>
for which the direct supertypes are:- the direct superclass,
- the direct superinterfaces,
- the type
Object
, and - the raw type
C
- Overrides:
isSubtypeOf
in classClassOrInterfaceType
- Parameters:
otherType
- the possible supertype- Returns:
- true if this type is a subtype of the given type, false otherwise
- See Also:
ReferenceType.isAssignableFrom(Type)
,ClassOrInterfaceType.isSubtypeOf(Type)
-
getRawtype
public NonParameterizedType getRawtype()
Returns the rawtypeType
for this generic class.- Specified by:
getRawtype
in classClassOrInterfaceType
- Returns:
- the rawtype for this generic class
-
-