Class AnnotatedTypeMirror.AnnotatedTypeVariable

java.lang.Object
org.checkerframework.framework.type.AnnotatedTypeMirror
org.checkerframework.framework.type.AnnotatedTypeMirror.AnnotatedTypeVariable
All Implemented Interfaces:
DeepCopyable<AnnotatedTypeMirror>
Enclosing class:
AnnotatedTypeMirror

public static class AnnotatedTypeMirror.AnnotatedTypeVariable extends AnnotatedTypeMirror
Represents a type variable. A type variable may be explicitly declared by a type parameter of a type, method, or constructor. A type variable may also be declared implicitly, as by the capture conversion of a wildcard type argument (see chapter 5 of The Java Language Specification, Third Edition).
  • Method Details

    • getKind

      public TypeKind getKind()
      Description copied from class: AnnotatedTypeMirror
      Returns the kind of this type.

      Subclasses whose kind is constant (e.g. AnnotatedTypeMirror.AnnotatedDeclaredType, AnnotatedTypeMirror.AnnotatedArrayType) override this to return the constant directly; this is meaningful for performance because the underlying javac Type#getKind() on declared types runs Symbol#apiComplete. Only AnnotatedTypeMirror.AnnotatedPrimitiveType and AnnotatedTypeMirror.AnnotatedNoType fall through to this base implementation; for both, the underlying type's getKind() is cheap and does not force symbol completion.

      Overrides:
      getKind in class AnnotatedTypeMirror
      Returns:
      the kind of this type
    • isDeclaration

      public boolean isDeclaration()
      Description copied from class: AnnotatedTypeMirror
      Returns true if this type mirror represents a declaration, rather than a use, of a type.

      For example, class List<T> { ... } declares a new type List<T>, while List<Integer> is a use of the type.

      Overrides:
      isDeclaration in class AnnotatedTypeMirror
      Returns:
      true if this represents a declaration
    • addAnnotation

      public void addAnnotation(AnnotationMirror annotation)
      Description copied from class: AnnotatedTypeMirror
      Adds the canonical version of annotation as a primary annotation of this type and, in the case of AnnotatedTypeMirror.AnnotatedTypeVariables, AnnotatedTypeMirror.AnnotatedWildcardTypes, and AnnotatedTypeMirror.AnnotatedIntersectionTypes, adds it to all bounds. (The canonical version is found via AnnotatedTypeFactory.asSupportedQualifier(javax.lang.model.element.AnnotationMirror).) If the canonical version of annotation is not a supported qualifier, then no annotation is added. If this type already has annotation in the same hierarchy as annotation, the behavior of this method is undefined.
      Overrides:
      addAnnotation in class AnnotatedTypeMirror
      Parameters:
      annotation - the annotation to add
    • removeAnnotation

      public boolean removeAnnotation(AnnotationMirror a)
      Description copied from class: AnnotatedTypeMirror
      Removes a primary annotation from the type.
      Overrides:
      removeAnnotation in class AnnotatedTypeMirror
      Parameters:
      a - the annotation to remove
      Returns:
      true if the annotation was removed, false if the type's annotations were unchanged
    • clearAnnotations

      public void clearAnnotations()
      Removes all primary annotations on this type and, in the case of AnnotatedTypeMirror.AnnotatedTypeVariables, AnnotatedTypeMirror.AnnotatedWildcardTypes, and AnnotatedTypeMirror.AnnotatedIntersectionTypes, clears all bounds too, matching AnnotatedTypeMirror.addAnnotation(javax.lang.model.element.AnnotationMirror) and AnnotatedTypeMirror.removeAnnotation(javax.lang.model.element.AnnotationMirror), which already propagate to bounds for those three kinds.

      Also clears both bounds' annotations, for the same reason removeAnnotation(AnnotationMirror) does: leaving a bound's annotations in place while clearing only this type variable's own primary annotation would let a bound keep a stale qualifier that a caller clearing this type is trying to discard, with no local signal that the two had gone out of sync.

      Overrides:
      clearAnnotations in class AnnotatedTypeMirror
    • setDeclaration

      public void setDeclaration(boolean declaration)
      Change whether this AnnotatedTypeVariable is considered a use or a declaration (use this method with caution).
      Parameters:
      declaration - true if this type variable should be considered a declaration
    • asUse

      Overrides:
      asUse in class AnnotatedTypeMirror
    • accept

      public <R, P> R accept(AnnotatedTypeVisitor<R,P> v, P p)
      Description copied from class: AnnotatedTypeMirror
      Applies a visitor to this type.
      Specified by:
      accept in class AnnotatedTypeMirror
      Type Parameters:
      R - the return type of the visitor's methods
      P - the type of the additional parameter to the visitor's methods
      Parameters:
      v - the visitor operating on this type
      p - additional parameter to the visitor
      Returns:
      a visitor-specified result
    • getUnderlyingType

      public TypeVariable getUnderlyingType()
      Description copied from class: AnnotatedTypeMirror
      Returns the underlying unannotated Java type, which this wraps.
      Overrides:
      getUnderlyingType in class AnnotatedTypeMirror
      Returns:
      the underlying type
    • setLowerBound

      public void setLowerBound(AnnotatedTypeMirror type)
      Set the lower bound of this variable type.

      Returns the lower bound of this type variable. While a type parameter cannot include an explicit lower bound declaration, capture conversion can produce a type variable with a non-trivial lower bound. Type variables otherwise have a lower bound of NullType.

      This method is for framework usage only.

      Parameters:
      type - the lower bound type
    • getLowerBoundField

      public AnnotatedTypeMirror getLowerBoundField()
      Returns the lower bound field directly, bypassing any lazy initialization. This method is necessary to prevent infinite recursions in initialization. In general, prefer getLowerBound.
      Returns:
      the lower bound field
    • getLowerBound

      public AnnotatedTypeMirror getLowerBound()
      Returns the lower bound type of this type variable.
      Returns:
      the lower bound type of this type variable
    • setUpperBound

      public void setUpperBound(AnnotatedTypeMirror type)
      Set the upper bound of this variable type.

      This method is for framework usage only.

      Parameters:
      type - the upper bound type
    • getUpperBoundField

      public AnnotatedTypeMirror getUpperBoundField()
      Returns the upper bound field directly, bypassing any lazy initialization. This method is necessary to prevent infinite recursions in initialization. In general, prefer getUpperBound.
      Returns:
      the upper bound field
    • getUpperBound

      public AnnotatedTypeMirror getUpperBound()
      Returns the upper bound of the type variable, possibly lazily initializing it. Attention: If the upper bound is lazily initialized, it contains only the annotations written on the declaration's bound, not the defaults! Callers of the method have to make sure that an AnnotatedTypeFactory first processed the bound.
      Returns:
      the upper bound type of this type variable
    • getBounds

      public AnnotatedTypeParameterBounds getBounds()
      Returns the upper and lower bounds of this type variable, forcing their lazy initialization if necessary.
      Returns:
      the bounds of this type variable
    • getBoundFields

      public AnnotatedTypeParameterBounds getBoundFields()
      Returns the upper and lower bound fields of this type variable directly, without forcing lazy initialization (the fields may be null).
      Returns:
      the bound fields of this type variable
    • deepCopy

      public AnnotatedTypeMirror.AnnotatedTypeVariable deepCopy(boolean copyAnnotations)
      Description copied from class: AnnotatedTypeMirror
      Returns a deep copy of this type. A deep copy implies that each component type is copied recursively and the returned type refers to those copies in its component locations.

      Note: deepCopy provides two important properties in the returned copy:

      1. Structure preservation -- The exact structure of the original AnnotatedTypeMirror is preserved in the copy including all component types.
      2. Annotation preservation -- All of the annotations from the original AnnotatedTypeMirror and its components have been copied to the new type.
      If copyAnnotations is set to false, the second property, Annotation preservation, is removed. This is useful for cases in which the user may want to copy the structure of a type exactly but NOT its annotations.
      Specified by:
      deepCopy in class AnnotatedTypeMirror
      Returns:
      a deep copy
    • deepCopy

      Description copied from class: AnnotatedTypeMirror
      Returns a deep copy of this type with annotations.

      Each subclass implements this method with the subclass return type. The method body must always be a call to deepCopy(true).

      Specified by:
      deepCopy in interface DeepCopyable<AnnotatedTypeMirror>
      Specified by:
      deepCopy in class AnnotatedTypeMirror
      Returns:
      a deep copy of this type with annotations
      See Also:
    • shallowCopy

      public AnnotatedTypeMirror.AnnotatedTypeVariable shallowCopy(boolean copyAnnotations)
      Description copied from class: AnnotatedTypeMirror
      Returns a shallow copy of this type. A shallow copy implies that each component type in the output copy refers to the same object as the object being copied.
      Specified by:
      shallowCopy in class AnnotatedTypeMirror
      Parameters:
      copyAnnotations - true if copy should have annotations, i.e., field annotations should be copied
      Returns:
      a shallow copy of this type
    • shallowCopy

      Description copied from class: AnnotatedTypeMirror
      Returns a shallow copy of this type with annotations.

      Each subclass implements this method with the subclass return type. The method body must always be a call to shallowCopy(true).

      Specified by:
      shallowCopy in class AnnotatedTypeMirror
      Returns:
      a shallow copy of this type with annotations
      See Also:
    • getErased

      public AnnotatedTypeMirror getErased()
      This method will traverse the upper bound of this type variable calling getErased until it finds the concrete upper bound. e.g.
       <E extends T>, T extends S, S extends List<String>>
      A call to getErased will return the type List
      Overrides:
      getErased in class AnnotatedTypeMirror
      Returns:
      the erasure of the upper bound of this type

      IMPORTANT NOTE: getErased should always return a FRESH object. This will occur for type variables if all other getErased methods are implemented appropriately. Therefore, to avoid extra copy calls, this method will not call deepCopy on getUpperBound

      See Also: