Package randoop.types

Class ReferenceType

    • Constructor Detail

      • ReferenceType

        public ReferenceType()
    • Method Detail

      • forClass

        public static ReferenceType forClass​(Class<?> classType)
        Returns a ReferenceType object for the given Class object. Creates arrays, classes, and interfaces. For arrays, calls ArrayType.forClass(Class). For other (class/interface) types, calls ClassOrInterfaceType.forClass(Class).
        Parameters:
        classType - the Class object representing the type
        Returns:
        the ReferenceType object for the given type
      • forType

        public static ReferenceType forType​(Type type)
        Creates a ReferenceType for the given java.lang.reflect.Type. Specifically, creates
        • an ArrayType if the reference is GenericArrayType or is a Class object representing an array.
        • a TypeVariable) if the reference is java.lang.reflect.TypeVariable.
        • a ClassOrInterfaceType if the reference is none of those.
        Parameters:
        type - the type reference
        Returns:
        the ReferenceType for the given Type
      • substitute

        public abstract ReferenceType substitute​(Substitution substitution)
        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.

        Overrides:
        substitute in class Type
        Parameters:
        substitution - the type substitution
        Returns:
        the type created by applying the substitution to this type
      • applyCaptureConversion

        public ReferenceType applyCaptureConversion()
        Description copied from class: Type
        Applies a capture conversion to this type.
        Overrides:
        applyCaptureConversion in class Type
        Returns:
        a copy of this type with wildcards replaced by type conversion
      • getTypeParameters

        public List<TypeVariable> getTypeParameters()
        Returns the list of type parameters for this type. Reference types that may have type parameters include ArrayType (such as E[]), and subclasses of ParameterizedType.
        Returns:
        the type parameters for this type
      • isAssignableFrom

        public boolean isAssignableFrom​(Type sourceType)
        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.

        Overrides:
        isAssignableFrom in class Type
        Parameters:
        sourceType - the type to test for assignability
        Returns:
        true if this type can be assigned from the source type, and false otherwise
      • getInstantiatingSubstitution

        public Substitution getInstantiatingSubstitution​(ReferenceType goalType)
        Computes a substitution that can be applied to the type variables of the generic goal type to instantiate operations of this type, possibly inherited from from the goal type. The substitution will unify this type or a supertype of this type with the given goal type.

        If there is no unifying substitution, returns null.

        Parameters:
        goalType - the generic type for which a substitution is needed
        Returns:
        a substitution unifying this type or a supertype of this type with the goal type
      • getInstantiatingSubstitutionforTypeVariable

        public static Substitution getInstantiatingSubstitutionforTypeVariable​(ReferenceType instantiatedType,
                                                                               ReferenceType goalType)
        Static helper method that does the work of getInstantiatingSubstitution, if goalType is a type variable.
        Parameters:
        instantiatedType - the first type
        goalType - the generic type for which a substitution is needed
        Returns:
        a substitution unifying this first type or a supertype of the first type with the goal type
      • isReferenceType

        public boolean isReferenceType()
        Description copied from class: Type
        Indicates whether this is a reference type. Note: implementing classes should ensure that this is equivalent to !(this.isPrimitive())
        Overrides:
        isReferenceType in class Type
        Returns:
        true if this type is a reference type, and 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.

        Overrides:
        isSubtypeOf in class Type
        Parameters:
        otherType - the possible supertype
        Returns:
        true if this type is a subtype of the given type, false otherwise