Package randoop.types

Class CaptureTypeVariable

  • All Implemented Interfaces:
    Comparable<Type>

    class CaptureTypeVariable
    extends TypeVariable
    Represents a type variable introduced by capture conversion over a wildcard type argument.

    A CaptureTypeVariable has both an upper and lower bound determined by combining the wildcard bound with the ParameterBound on the type parameter. An object is constructed from a wildcard using the wildcard bound to determine the initial upper or lower bound. The convert(TypeVariable, Substitution) method is then used to update the bounds to match the definition in JLS section 5.1.10, Capture Conversion.

    • Field Detail

      • count

        private static int count
        The ID counter for capture conversion variables.
      • varID

        private final int varID
        The integer ID of this capture variable.
    • Constructor Detail

      • CaptureTypeVariable

        private CaptureTypeVariable​(int varID,
                                    WildcardArgument wildcard,
                                    ParameterBound lowerBound,
                                    ParameterBound upperBound)
        Creates a CaptureTypeVariable with explicitly given ID, wildcard, and bounds.
        Parameters:
        varID - the variable ID for the created variable
        wildcard - the wildcard for the created variable
        lowerBound - the lower type bound of the variable
        upperBound - the upper type bound of the variable
    • Method Detail

      • getWildcard

        WildcardArgument getWildcard()
        Returns the wildcard.
        Returns:
        the wildcard
      • convert

        public void convert​(TypeVariable typeParameter,
                            Substitution substitution)
        Converts the bounds on this CaptureTypeVariable by including those of the formal type parameters of the generic type, and applying the implied substitution between the type parameters and capture conversion argument list. Implements the clauses of the JLS section 5.1.10, Capture Conversion.

        Creates an upper bound on a type variable resulting from a capture conversion (JLS section 5.1.10) in the case that a wildcard has an upper bound other than Object. In particular, each object represents a bound on a variable Si in a parameterized type C<S1,...,Sn> defined as glb(Bi, Ui[Ai:=Si]) where

        • Ui is the upper bound on the type variable Ai in the declared class C<A1,...,An>,
        • glb(S, T) for types S and T is the intersection type S & T.
        The JLS states that if S and T are both class types not related as subtypes, then the greatest lower bound of the two types is a compiler error. Technically it is the null type.
        Parameters:
        typeParameter - the formal type parameter of the generic type
        substitution - the capture conversion substitution
      • 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
      • hasCaptureVariable

        public boolean hasCaptureVariable()
        Description copied from class: Type
        Indicates whether this ReferenceType has a capture variable.
        Overrides:
        hasCaptureVariable in class ParameterType
        Returns:
        true iff this type has a capture variable
      • 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
      • substitute

        public ReferenceType 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.

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