java.lang.Object
org.checkerframework.framework.util.typeinference8.types.AbstractType
Direct Known Subclasses:
InferenceType, ProperType, UseOfVariable

public abstract class AbstractType extends Object
As explained in section 18.1, the JLS Chapter on type inference use the term "type" to "include type-like syntax that contains inference variables". This class represents this types. Three subclasses of this class are:
  • ProperType: types that do not contain inference variables
  • Variable: inference variables
  • InferenceType: type-like syntax that contain at least one inference variable
  • Field Details

  • Constructor Details

    • AbstractType

      protected AbstractType(Java8InferenceContext context, boolean ignoreAnnotations)
      Creates an AbstractType.
      Parameters:
      context - the context object
      ignoreAnnotations - true if the annotations on this type should be ignored
  • Method Details

    • getKind

      public abstract AbstractType.Kind getKind()
      Returns the kind of AbstractType.
      Returns:
      the kind of AbstractType
    • isProper

      public boolean isProper()
      Returns true if this type is a proper type.
      Returns:
      true if this type is a proper type
    • isUseOfVariable

      public boolean isUseOfVariable()
      Returns true if this type is a use of an inference variable.
      Returns:
      true if this type is a use of an inference variable
    • isInferenceType

      public boolean isInferenceType()
      Returns true if this type contains inference variables, but is not an inference variable.
      Returns:
      true if this type contains inference variables, but is not an inference variable
    • getTypeKind

      public final TypeKind getTypeKind()
      Returns the TypeKind of the underlying Java type.
      Returns:
      the TypeKind of the underlying Java type
    • create

      public abstract AbstractType create(AnnotatedTypeMirror atm, TypeMirror type, boolean ignoreAnnotations)
      Creates a type using the given types.
      Parameters:
      atm - annotated type mirror
      type - type mirror
      ignoreAnnotations - true if the annotations on this type should be ignored
      Returns:
      the new type
    • getJavaType

      public abstract TypeMirror getJavaType()
      Returns the underlying Java type without inference variables.
      Returns:
      the underlying Java type without inference variables
    • getAnnotatedType

      public abstract AnnotatedTypeMirror getAnnotatedType()
      Returns the underlying Java type without inference variables.
      Returns:
      the underlying Java type without inference variables
    • getInferenceVariables

      public abstract Set<Variable> getInferenceVariables()
      Return a set of all inference variables referenced by this type.

      The returned set might be mutable or immutable, and it might or might not be freshly allocated. Callers that need to mutate the result must copy it first.

      Returns:
      a set of all inference variables referenced by this type
    • applyInstantiations

      public abstract AbstractType applyInstantiations()
      Returns a new type that is the same as this one except the variables in instantiations have been replaced by their instantiation.
      Returns:
      a new type that is the same as this one except the variables in instantiations have been replaced by their instantiation
    • isObject

      public abstract boolean isObject()
      Returns true if this type is java.lang.Object.
      Returns:
      true if this type is java.lang.Object
    • getTypeParameterBounds

      public List<ProperType> getTypeParameterBounds()
      Assuming the type is a declared type, this method returns the upper bounds of its type parameters. (A type parameter of a declared type, can't refer to any type being inferred, so they are proper types.)
      Returns:
      the upper bounds of the type parameter of this type
    • capture

      public AbstractType capture(Java8InferenceContext context)
      Returns a new type that is the capture of this type.
      Parameters:
      context - the context object
      Returns:
      a new type that is the capture of this type
    • asSuper

      public AbstractType asSuper(TypeMirror superType)
      If superType is a super type of this type, then this method returns the super type of this type that is the same class as superType. Otherwise, it returns null
      Parameters:
      superType - a type, need not be a super type of this type
      Returns:
      super type of this type that is the same class as superType or null if one doesn't exist
    • getFunctionTypeReturnType

      public @Nullable AbstractType getFunctionTypeReturnType()
      If this type is a functional interface whose function type returns a value, then this method returns that return type. Otherwise, returns null: null is returned both when this type is not a functional interface and when its function type's result is void. A void result is signaled by null rather than by a type of kind TypeKind.VOID because an AbstractType never represents void, an invariant that ProperType asserts. The returned type is therefore never of kind TypeKind.VOID.
      Returns:
      the return type of the function type of this type, or null if this type is not a functional interface or its function type's result is void
    • getFunctionTypeParameterTypes

      public List<AbstractType> getFunctionTypeParameterTypes()
      If this type is a functional interface, then this method returns the parameter types of the function type of that functional interface. Otherwise, it returns null.
      Returns:
      the parameter types of the function type of this type or null if no function type exists
    • isRaw

      public boolean isRaw()
      Returns true if the type is a raw type.
      Returns:
      true if the type is a raw type
    • replaceTypeArgs

      public AbstractType replaceTypeArgs(List<AbstractType> args)
      Returns a new type that is the same type as this one, but whose type arguments are args.
      Parameters:
      args - a list of type arguments
      Returns:
      a new type that is the same type as this one, but whose type arguments are args
    • isParameterizedType

      public boolean isParameterizedType()
      Returns true if the proper type is a parameterized class or interface type, or an inner class type of a parameterized class or interface type (directly or indirectly)
      Returns:
      true if T is a parameterized type
    • getMostSpecificArrayType

      public AbstractType getMostSpecificArrayType()
      Returns the most specific array type that is a super type of this type or null if one doesn't exist.
      Returns:
      the most specific array type that is a super type of this type or null if one doesn't exist
    • isPrimitiveArray

      public boolean isPrimitiveArray()
      Returns true if this type is a primitive array.
      Returns:
      true if this type is a primitive array
    • getIntersectionBounds

      public List<AbstractType> getIntersectionBounds()
      Returns assuming type is an intersection type, this method returns the bounds in this type.
      Returns:
      assuming type is an intersection type, this method returns the bounds in this type
    • getTypeVarUpperBound

      public AbstractType getTypeVarUpperBound()
      Returns assuming this type is a type variable, this method returns the upper bound of this type.
      Returns:
      assuming this type is a type variable, this method returns the upper bound of this type
    • getTypeVarLowerBound

      public AbstractType getTypeVarLowerBound()
      Returns assuming this type is a type variable that has a lower bound, this method returns the lower bound of this type.
      Returns:
      assuming this type is a type variable that has a lower bound, this method returns the lower bound of this type
    • isLowerBoundTypeVariable

      public boolean isLowerBoundTypeVariable()
      Returns true if this type is a type variable with a lower bound.
      Returns:
      true if this type is a type variable with a lower bound
    • isWildcardParameterizedType

      public boolean isWildcardParameterizedType()
      Returns true if this type is a parameterized type whose has at least one wildcard as a type argument.
      Returns:
      true if this type is a parameterized type whose has at least one wildcard as a type argument
    • getTypeArguments

      public List<AbstractType> getTypeArguments()
      Returns this type's type arguments or null if this type isn't a declared type.
      Returns:
      this type's type arguments or null this type isn't a declared type
    • getParameterizedEnclosingType

      public @Nullable AbstractType getParameterizedEnclosingType()
      Returns the enclosing type of this type if this type is an inner class type of a parameterized type, directly or indirectly; otherwise, returns null. The type arguments of the enclosing type are type arguments of this type, too (JLS 4.5).

      The returned type ignores annotations if this type does. Otherwise, constraints on it add qualifier bounds, too, just like the type hierarchy, which compares the type arguments of the enclosing types of two declared types (see DefaultTypeHierarchy.visitTypeArgs(org.checkerframework.framework.type.AnnotatedTypeMirror.AnnotatedDeclaredType, org.checkerframework.framework.type.AnnotatedTypeMirror.AnnotatedDeclaredType, boolean, boolean)).

      Returns:
      the parameterized enclosing type of this type, or null if there is none
    • isUnboundWildcard

      public boolean isUnboundWildcard()
      Returns true if the type is an unbound wildcard.
      Returns:
      true if the type is an unbound wildcard
    • isUpperBoundedWildcard

      public boolean isUpperBoundedWildcard()
      Returns true if the type is a wildcard with an upper bound.
      Returns:
      true if the type is a wildcard with an upper bound
    • isLowerBoundedWildcard

      public boolean isLowerBoundedWildcard()
      Returns true if the type is a wildcard with a lower bound.
      Returns:
      true if the type is a wildcard with a lower bound
    • getWildcardLowerBound

      public AbstractType getWildcardLowerBound()
      Returns if this type is a wildcard return its lower bound; otherwise, return null.
      Returns:
      if this type is a wildcard return its lower bound; otherwise, return null
    • getWildcardUpperBound

      public AbstractType getWildcardUpperBound()
      Returns if this type is a wildcard return its upper bound; otherwise, return null.
      Returns:
      if this type is a wildcard return its upper bound; otherwise, return null
    • getErased

      public AbstractType getErased()
      Returns new type whose Java type is the erasure of this type.
      Returns:
      a new type whose Java type is the erasure of this type
    • getComponentType

      public final AbstractType getComponentType()
      Returns the array component type fo this type or null if on does not exist.
      Returns:
      the array component type of this type or null if one does not exist
    • getQualifiers

      public abstract Set<AbstractQualifier> getQualifiers()
      Returns the primary qualifiers on this type.
      Returns:
      the primary qualifiers on this type
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object