Class QualifierDefaults

java.lang.Object
org.checkerframework.framework.util.defaults.QualifierDefaults

public class QualifierDefaults extends Object
Determines the default qualifiers on a type. Default qualifiers are specified via the DefaultQualifier annotation.
See Also:
  • Field Details

    • defaultQualifierValueElement

      protected final ExecutableElement defaultQualifierValueElement
      The value() element/field of a @DefaultQualifier annotation.
    • defaultQualifierLocationsElement

      protected final ExecutableElement defaultQualifierLocationsElement
      The locations() element/field of a @DefaultQualifier annotation.
    • defaultQualifierListValueElement

      protected final ExecutableElement defaultQualifierListValueElement
      The value() element/field of a @DefaultQualifier.List annotation.
    • elementToBoundType

      protected final Map<Element,QualifierDefaults.BoundType> elementToBoundType
      Mapping from an Element to the bound type.
    • STANDARD_CLIMB_DEFAULTS_TOP

      public static final List<TypeUseLocation> STANDARD_CLIMB_DEFAULTS_TOP
      CLIMB locations whose standard default is top for a given type system.
    • STANDARD_CLIMB_DEFAULTS_BOTTOM

      public static final List<TypeUseLocation> STANDARD_CLIMB_DEFAULTS_BOTTOM
      CLIMB locations whose standard default is bottom for a given type system.
    • STANDARD_UNCHECKED_DEFAULTS_TOP

      public static final List<TypeUseLocation> STANDARD_UNCHECKED_DEFAULTS_TOP
      Standard unchecked default locations that should be top.
    • STANDARD_UNCHECKED_DEFAULTS_BOTTOM

      public static final List<TypeUseLocation> STANDARD_UNCHECKED_DEFAULTS_BOTTOM
      Standard unchecked default locations that should be bottom.
  • Constructor Details

    • QualifierDefaults

      public QualifierDefaults(Elements elements, AnnotatedTypeFactory atypeFactory)
      Creates a new QualifierDefaults.
      Parameters:
      elements - interface to Element data in the current processing environment
      atypeFactory - an annotated type factory, used to get annotations by name
  • Method Details

    • validLocationsForUncheckedCodeDefaults

      public static List<TypeUseLocation> validLocationsForUncheckedCodeDefaults()
      Returns an array of locations that are valid for the unchecked value defaults. These are determined simply by syntax: since an entire file is type-checked, it is not possible for local variables to be unchecked.
      Returns:
      the locations that are valid for the unchecked value defaults
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • hasDefaultsForCheckedCode

      public boolean hasDefaultsForCheckedCode()
      Returns true if a default with TypeUseLocation OTHERWISE or ALL is specified.
      Returns:
      true if we found a Default with location OTHERWISE or ALL
    • addUncheckedStandardDefaults

      public void addUncheckedStandardDefaults()
      Adds standard unchecked defaults that do not conflict with previously added defaults.
    • addClimbStandardDefaults

      public void addClimbStandardDefaults()
      Adds standard CLIMB defaults that do not conflict with previously added defaults.
    • addCheckedCodeDefault

      public void addCheckedCodeDefault(AnnotationMirror absoluteDefaultAnno, TypeUseLocation location)
      Adds a default annotation. A programmer can override this by writing the @DefaultQualifier annotation on an element.
      Parameters:
      absoluteDefaultAnno - the default annotation mirror
      location - the type use location
    • addUncheckedCodeDefault

      public void addUncheckedCodeDefault(AnnotationMirror uncheckedDefaultAnno, TypeUseLocation location)
      Adds a default annotation for unchecked elements.
      Parameters:
      uncheckedDefaultAnno - the default annotation mirror
      location - the type use location
    • addUncheckedCodeDefaults

      public void addUncheckedCodeDefaults(AnnotationMirror absoluteDefaultAnno, TypeUseLocation[] locations)
      Sets the default annotation for unchecked elements, with specific locations.
    • addCheckedCodeDefaults

      public void addCheckedCodeDefaults(AnnotationMirror absoluteDefaultAnno, TypeUseLocation[] locations)
    • addElementDefault

      public void addElementDefault(Element elem, AnnotationMirror elementDefaultAnno, TypeUseLocation location)
      Sets the default annotation for the given element and location.

      The default is treated like a @DefaultQualifier annotation written on elem: it applies within elem and within the elements that elem encloses, and it is combined with the other @DefaultQualifier annotations that apply there, rather than suppressing them. As with @DefaultQualifier, an alias is replaced by its canonical qualifier.

      Call this method before the type of elem, or of any element that elem encloses, is computed. A type that was computed earlier does not reflect the default.

      Parameters:
      elem - the scope to set the default within
      elementDefaultAnno - the default to set
      location - the location to apply the default to
      Throws:
      BugInCF - if this type system does not support the qualifier
    • annotate

      public void annotate(Element elt, AnnotatedTypeMirror type)
      Applies default annotations to a type obtained from an Element.
      Parameters:
      elt - the element from which the type was obtained
      type - the type to annotate
    • annotate

      public void annotate(Tree tree, AnnotatedTypeMirror type)
      Applies default annotations to a type given a Tree.
      Parameters:
      tree - the tree from which the type was obtained
      type - the type to annotate
    • applyConservativeDefaults

      public boolean applyConservativeDefaults(Element annotationScope)
      Given an element, returns true if the conservative default should be applied for it. Handles elements from bytecode or source code.
      Parameters:
      annotationScope - the element that the conservative default might apply to
      Returns:
      true if the conservative default applies to the given element
    • createDefaultApplierElement

      protected QualifierDefaults.DefaultApplierElement createDefaultApplierElement(AnnotatedTypeFactory atypeFactory, Element annotationScope, AnnotatedTypeMirror type, boolean applyToTypeVar)
      Returns a new QualifierDefaults.DefaultApplierElement. A subclass can override this method to use a subclass of QualifierDefaults.DefaultApplierElement.
      Parameters:
      atypeFactory - the type factory
      annotationScope - the element whose defaults are being applied
      type - the type to which to apply defaults
      applyToTypeVar - true if the default should be applied to the primary annotation of a local variable whose type is a type variable
      Returns:
      a new QualifierDefaults.DefaultApplierElement
    • getWildcardBoundType

      public QualifierDefaults.BoundType getWildcardBoundType(AnnotatedTypeMirror.AnnotatedWildcardType wildcardType)
      Returns the BoundType of wildcardType. If it is unbounded, uses the type parameter to which it is an argument.

      If the declared type of which wildcardType is a type argument is known, call getWildcardBoundType(AnnotatedWildcardType, AnnotatedDeclaredType) instead, which determines the type parameter more reliably.

      Parameters:
      wildcardType - the annotated wildcard type
      Returns:
      the BoundType of wildcardType. If it is unbounded, uses the type parameter to which it is an argument
    • getWildcardBoundType

      Returns the BoundType of annotatedWildcard. If it is unbounded, use the type parameter to which its an argument.
      Parameters:
      wildcardType - the annotated wildcard type
      enclosingType - a declared type of which wildcardType might be a type argument, or null
      Returns:
      the BoundType of annotatedWildcard. If it is unbounded, use the type parameter to which its an argument