Package randoop.types

Class 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 Detail

      • componentType

        private final Type componentType
        The type of components in this array.
      • runtimeClass

        private final Class<?> runtimeClass
        The runtime type for this array.
    • Constructor Detail

      • ArrayType

        private ArrayType​(Type componentType,
                          Class<?> runtimeClass)
        Creates an ArrayType with the given component type and runtime class.
        Parameters:
        componentType - the component type
        runtimeClass - the runtime class
    • Method Detail

      • forClass

        public static ArrayType forClass​(Class<?> arrayClass)
        Creates an array type for the given java.lang.reflect.Class object.
        Parameters:
        arrayClass - the Class object for array type
        Returns:
        the ArrayType for the given class object
      • forType

        public static ArrayType forType​(Type type)
        Creates an ArrayType from a java.lang.reflect.Type reference. First checks whether reference has type java.lang.reflectGenericArrayType, and if so performs the conversion. If the reference is to a Class object, then delegates to forClass(Class).
        Parameters:
        type - the Type reference
        Returns:
        the Type for the array type
      • ofComponentType

        public static ArrayType ofComponentType​(Type componentType)
        Creates an ArrayType for the given component type. If the component type is a type variable then creates a type with an Object array as the rawtype.
        Parameters:
        componentType - the component type
        Returns:
        an ArrayType with the given component type
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object
      • substitute

        public ArrayType substitute​(Substitution substitution)
        Description copied from class: ReferenceType
        Applies a substitution to a ReferenceType. 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 class ReferenceType
        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. For java.util.List<T> return "java.util.List<T>".
        Specified by:
        getFqName in class Type
        Returns:
        the fully-qualified type name for this type
      • 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). For java.util.List<T> return "java.util.List<T>".
        Specified by:
        getBinaryName in class Type
        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. For java.util.List<T>, returns "List".
        Specified by:
        getSimpleName in class Type
        Returns:
        the name of this type without type arguments
      • getRuntimeClass

        public Class<?> getRuntimeClass()
        Description copied from class: Type
        Returns the runtime Class 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 the Class<?> for the Type object, and not of the represented type. For instance, if a Type object t represented the Java type int, then t.getRuntimeClass() would return int.class while t.getClass() would return Type.class.

        Specified by:
        getRuntimeClass in class Type
        Returns:
        the Class that is the runtime representation of the type, or null if this type is a type variable or null reference type
      • isArray

        public boolean isArray()
        Description copied from class: Type
        Indicates whether this object represents an array type.
        Overrides:
        isArray in class Type
        Returns:
        true if this object represents an array type, false otherwise
      • isAssignableFrom

        public boolean isAssignableFrom​(Type otherType)
        Indicates whether there is an assignment conversion from a source Type 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.
        And, if after all those conversions, the type is a raw type, an unchecked conversion may occur.

        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 is C[] (e.g., the component type is the rawtype C).

        Overrides:
        isAssignableFrom in class ReferenceType
        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.
        Overrides:
        isGeneric in class Type
        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
      • 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 if otherType is Object.

        This method specifically uses the definition in section 4.10.2 of JLS for JavaSE 8.

        Overrides:
        isSubtypeOf in class ReferenceType
        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 class Type
        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 class Type
        Returns:
        true if this type has a wildcard, false otherwise
      • hasCaptureVariable

        public boolean hasCaptureVariable()
        Description copied from class: Type
        Indicates whether this ReferenceType has a capture variable.
        Overrides:
        hasCaptureVariable in class Type
        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, converts List<String>[] to List[], List<String>[][] to List[][], and int[] to int[].
        Returns:
        the non-parameterized form of this array type
      • getDimensions

        public int getDimensions()