Class ArrayType
- java.lang.Object
-
- randoop.types.Type
-
- randoop.types.ReferenceType
-
- randoop.types.ArrayType
-
- All Implemented Interfaces:
Comparable<Type>
public class ArrayType extends ReferenceType
Represents an array type as defined in JLS, Section 4.3.ArrayType: PrimitiveType [ ] { [ ] } ClassOrInterfaceType [ ] { [ ] } TypeVariable [ ] { [ ] }
The type preceding the rightmost set of brackets is the component type, while the type preceding the brackets is the element type. An array may have components of any type.
-
-
Field Summary
Fields Modifier and Type Field Description private Type
componentType
The type of components in this array.private Class<?>
runtimeClass
The runtime type for this array.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
equals(Object obj)
static ArrayType
forClass(Class<?> arrayClass)
Creates an array type for the givenjava.lang.reflect.Class
object.static ArrayType
forType(Type type)
Creates anArrayType
from ajava.lang.reflect.Type
reference.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).Type
getComponentType()
Returns the component type of this array type.int
getDimensions()
Type
getElementType()
Returns the element type of this array type.String
getFqName()
Returns the fully-qualified name of this type, including type arguments if this is a parameterized type.Type
getRawtype()
Returns the raw type for this type, which is this type except for generic types.ArrayType
getRawTypeArray()
Returns the non-parameterized form for this array type.Class<?>
getRuntimeClass()
Returns the runtimeClass
object for this type.String
getSimpleName()
Returns the name of this type without type arguments or package qualifiers.List<TypeVariable>
getTypeParameters()
Returns the list of type parameters for this type.boolean
hasCaptureVariable()
Indicates whether thisReferenceType
has a capture variable.int
hashCode()
boolean
hasParameterizedElementType()
Indicates whether this array type has a parameterized element type.boolean
hasWildcard()
Indicates whether this type has a wildcard anywhere within it.boolean
isArray()
Indicates whether this object represents an array type.boolean
isAssignableFrom(Type otherType)
Indicates whether there is an assignment conversion from a sourceType
to this type.boolean
isGeneric(boolean ignoreWildcards)
Indicate whether this type is generic.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.static ArrayType
ofComponentType(Type componentType)
Creates anArrayType
for the given component type.ArrayType
substitute(Substitution substitution)
Applies a substitution to aReferenceType
.-
Methods inherited from class randoop.types.ReferenceType
applyCaptureConversion, getInstantiatingSubstitution, getInstantiatingSubstitutionforTypeVariable, isCaptureVariable, isInstantiationOf, isReferenceType
-
Methods inherited from class randoop.types.Type
compareTo, forFullyQualifiedName, forName, forValue, getCanonicalName, getTypeforFullyQualifiedName, getUnqualifiedBinaryName, isAssignableFromTypeOf, isBoxedPrimitive, isClass, isClassOrInterfaceType, isEnum, isGeneric, isInterface, isNonreceiverType, isObject, isParameterized, isPrimitive, isRawtype, isString, isVariable, isVoid, runtimeClassIs, toString
-
-
-
-
Method Detail
-
forClass
public static ArrayType forClass(Class<?> arrayClass)
Creates an array type for the givenjava.lang.reflect.Class
object.- Parameters:
arrayClass
- theClass
object for array type- Returns:
- the
ArrayType
for the given class object
-
forType
public static ArrayType forType(Type type)
Creates anArrayType
from ajava.lang.reflect.Type
reference. First checks whether reference has typejava.lang.reflectGenericArrayType
, and if so performs the conversion. If the reference is to aClass
object, then delegates toforClass(Class)
.- Parameters:
type
- theType
reference- Returns:
- the
Type
for the array type
-
ofComponentType
public static ArrayType ofComponentType(Type componentType)
Creates anArrayType
for the given component type. If the component type is a type variable then creates a type with anObject
array as the rawtype.- Parameters:
componentType
- the component type- Returns:
- an
ArrayType
with the given component type
-
substitute
public ArrayType 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
-
getComponentType
public Type getComponentType()
Returns the component type of this array type.- Returns:
- the component type of this array type
-
getElementType
public Type getElementType()
Returns the element type of this array type. If the component type of this array type is not an array type, the element type is the component type. Otherwise, the element type is the element type of the component type.- Returns:
- the element type of this array type
-
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
-
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
-
getTypeParameters
public List<TypeVariable> getTypeParameters()
Description copied from class:ReferenceType
Returns the list of type parameters for this type. Reference types that may have type parameters includeArrayType
(such asE[]
), and subclasses ofParameterizedType
.- Overrides:
getTypeParameters
in classReferenceType
- Returns:
- the type parameters for this type
-
isArray
public boolean isArray()
Description copied from class:Type
Indicates whether this object represents an array type.
-
isAssignableFrom
public boolean isAssignableFrom(Type otherType)
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.For an array type, check for assignability by reference widening. If not otherwise assignable, check for unchecked conversion, which occurs when this type is
C<T1,...,Tk>[]
and other type isC[]
(e.g., the component type is the rawtypeC
).- Overrides:
isAssignableFrom
in classReferenceType
- Parameters:
otherType
- the type to test for assignability- Returns:
- true if this type can be assigned from the source type, and 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.
-
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 of JLS for Java SE 8.For
ReferenceType
, returns true ifotherType
isObject
.This method specifically uses the definition in section 4.10.2 of JLS for JavaSE 8.
- Overrides:
isSubtypeOf
in classReferenceType
- Parameters:
otherType
- the possible supertype- Returns:
- true if this type is a subtype of the given type, false otherwise
-
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
-
hasWildcard
public boolean hasWildcard()
Description copied from class:Type
Indicates whether this type has a wildcard anywhere within it.- Overrides:
hasWildcard
in classType
- Returns:
- true if this type has a wildcard, false otherwise
-
hasCaptureVariable
public boolean hasCaptureVariable()
Description copied from class:Type
Indicates whether thisReferenceType
has a capture variable.- Overrides:
hasCaptureVariable
in classType
- Returns:
- true iff this type has a capture variable
-
hasParameterizedElementType
public boolean hasParameterizedElementType()
Indicates whether this array type has a parameterized element type.- Returns:
- true if the element type is parameterized; false otherwise
-
getRawTypeArray
public ArrayType getRawTypeArray()
Returns the non-parameterized form for this array type. For instance, convertsList<String>[]
toList[]
,List<String>[][]
toList[][]
, andint[]
toint[]
.- Returns:
- the non-parameterized form of this array type
-
getDimensions
public int getDimensions()
-
-