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.

Type variable uses have two possible defaults. If flow sensitive type refinement is enabled, unannotated top-level type variable uses receive the same default as local variables. All other type variable uses are defaulted using the TYPE_VARIABLE_USE default.


 <T> void method(USE T tIn) {
     LOCAL T t = tIn;
 }
 
The parameter tIn will be defaulted using the TYPE_VARIABLE_USE default. The local variable t will be defaulted using the LOCAL_VARIABLE default, in order to allow dataflow to refine T.
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.
    • defaultQualifierApplyToSubpackagesElement

      protected final ExecutableElement defaultQualifierApplyToSubpackagesElement
      The applyToSubpackages() 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)
      Parameters:
      elements - interface to Element data in the current processing environment
      atypeFactory - an annotation 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 simply by syntax, since an entire file is typechecked, it is not possible for local variables to be unchecked.
    • toString

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

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

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

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

      public void addCheckedCodeDefault(AnnotationMirror absoluteDefaultAnno, TypeUseLocation location, boolean applyToSubpackages)
      Adds a default annotation. A programmer may override this by writing the @DefaultQualifier annotation on an element.
      Parameters:
      absoluteDefaultAnno - the default annotation mirror
      location - the type use location
      applyToSubpackages - whether the default should be inherited by subpackages
    • addCheckedCodeDefault

      public void addCheckedCodeDefault(AnnotationMirror absoluteDefaultAnno, TypeUseLocation location)
      Adds a default annotation that also applies to subpackages, if applicable. A programmer may 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, boolean applyToSubpackages)
      Add a default annotation for unchecked elements.
      Parameters:
      uncheckedDefaultAnno - the default annotation mirror
      location - the type use location
      applyToSubpackages - whether the default should be inherited by subpackages
    • addUncheckedCodeDefault

      public void addUncheckedCodeDefault(AnnotationMirror uncheckedDefaultAnno, TypeUseLocation location)
      Add a default annotation for unchecked elements that also applies to subpackages, if applicable.
      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 annotations for a certain Element.
      Parameters:
      elem - the scope to set the default within
      elementDefaultAnno - the default to set
      location - the location to apply the default to
    • 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 whether 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:
      whether the conservative default applies to the given element
    • createDefaultApplierElement

      protected QualifierDefaults.DefaultApplierElement createDefaultApplierElement(AnnotatedTypeFactory atypeFactory, Element annotationScope, AnnotatedTypeMirror type, boolean fromTree)
      Create the default applier element.
      Parameters:
      atypeFactory - the annotated type factory
      annotationScope - the scope of the default
      type - the type to which to apply the default
      fromTree - whether the element came from a tree
      Returns:
      the default applier element