Class QualifierDefaults
java.lang.Object
org.checkerframework.framework.util.defaults.QualifierDefaults
Determines the default qualifiers on a type. Default qualifiers are specified via the
DefaultQualifier annotation.- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static enumSpecifies whether the type variable or wildcard has an explicit upper bound (UPPER), an explicit lower bound (LOWER), or no explicit bounds (UNBOUNDED).protected classA default applier element. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final ExecutableElementThe value() element/field of a @DefaultQualifier.List annotation.protected final ExecutableElementThe locations() element/field of a @DefaultQualifier annotation.protected final ExecutableElementThe value() element/field of a @DefaultQualifier annotation.protected final Map<Element, QualifierDefaults.BoundType> Mapping from an Element to the bound type.static final List<TypeUseLocation> CLIMB locations whose standard default is bottom for a given type system.static final List<TypeUseLocation> CLIMB locations whose standard default is top for a given type system.static final List<TypeUseLocation> Standard unchecked default locations that should be bottom.static final List<TypeUseLocation> Standard unchecked default locations that should be top. -
Constructor Summary
ConstructorsConstructorDescriptionQualifierDefaults(Elements elements, AnnotatedTypeFactory atypeFactory) Creates a new QualifierDefaults. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddCheckedCodeDefault(AnnotationMirror absoluteDefaultAnno, TypeUseLocation location) Adds a default annotation.voidaddCheckedCodeDefaults(AnnotationMirror absoluteDefaultAnno, TypeUseLocation[] locations) voidAdds standard CLIMB defaults that do not conflict with previously added defaults.voidaddElementDefault(Element elem, AnnotationMirror elementDefaultAnno, TypeUseLocation location) Sets the default annotation for the given element and location.voidaddUncheckedCodeDefault(AnnotationMirror uncheckedDefaultAnno, TypeUseLocation location) Adds a default annotation for unchecked elements.voidaddUncheckedCodeDefaults(AnnotationMirror absoluteDefaultAnno, TypeUseLocation[] locations) Sets the default annotation for unchecked elements, with specific locations.voidAdds standard unchecked defaults that do not conflict with previously added defaults.voidannotate(Tree tree, AnnotatedTypeMirror type) Applies default annotations to a type given aTree.voidannotate(Element elt, AnnotatedTypeMirror type) Applies default annotations to a type obtained from anElement.booleanapplyConservativeDefaults(Element annotationScope) Given an element, returns true if the conservative default should be applied for it.protected QualifierDefaults.DefaultApplierElementcreateDefaultApplierElement(AnnotatedTypeFactory atypeFactory, Element annotationScope, AnnotatedTypeMirror type, boolean applyToTypeVar) Returns a newQualifierDefaults.DefaultApplierElement.Returns the BoundType of wildcardType.getWildcardBoundType(AnnotatedTypeMirror.AnnotatedWildcardType wildcardType, @Nullable AnnotatedTypeMirror.AnnotatedDeclaredType enclosingType) Returns the BoundType of annotatedWildcard.booleanReturns true if a default with TypeUseLocation OTHERWISE or ALL is specified.toString()static List<TypeUseLocation> Returns an array of locations that are valid for the unchecked value defaults.
-
Field Details
-
defaultQualifierValueElement
The value() element/field of a @DefaultQualifier annotation. -
defaultQualifierLocationsElement
The locations() element/field of a @DefaultQualifier annotation. -
defaultQualifierListValueElement
The value() element/field of a @DefaultQualifier.List annotation. -
elementToBoundType
Mapping from an Element to the bound type. -
STANDARD_CLIMB_DEFAULTS_TOP
CLIMB locations whose standard default is top for a given type system. -
STANDARD_CLIMB_DEFAULTS_BOTTOM
CLIMB locations whose standard default is bottom for a given type system. -
STANDARD_UNCHECKED_DEFAULTS_TOP
Standard unchecked default locations that should be top. -
STANDARD_UNCHECKED_DEFAULTS_BOTTOM
Standard unchecked default locations that should be bottom.
-
-
Constructor Details
-
QualifierDefaults
Creates a new QualifierDefaults.- Parameters:
elements- interface to Element data in the current processing environmentatypeFactory- an annotated type factory, used to get annotations by name
-
-
Method Details
-
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
-
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
Adds a default annotation. A programmer can override this by writing the @DefaultQualifier annotation on an element.- Parameters:
absoluteDefaultAnno- the default annotation mirrorlocation- the type use location
-
addUncheckedCodeDefault
public void addUncheckedCodeDefault(AnnotationMirror uncheckedDefaultAnno, TypeUseLocation location) Adds a default annotation for unchecked elements.- Parameters:
uncheckedDefaultAnno- the default annotation mirrorlocation- 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
@DefaultQualifierannotation written onelem: it applies withinelemand within the elements thatelemencloses, and it is combined with the other@DefaultQualifierannotations 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 thatelemencloses, is computed. A type that was computed earlier does not reflect the default.- Parameters:
elem- the scope to set the default withinelementDefaultAnno- the default to setlocation- the location to apply the default to- Throws:
BugInCF- if this type system does not support the qualifier
-
annotate
Applies default annotations to a type obtained from anElement.- Parameters:
elt- the element from which the type was obtainedtype- the type to annotate
-
annotate
Applies default annotations to a type given aTree.- Parameters:
tree- the tree from which the type was obtainedtype- the type to annotate
-
applyConservativeDefaults
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 newQualifierDefaults.DefaultApplierElement. A subclass can override this method to use a subclass ofQualifierDefaults.DefaultApplierElement.- Parameters:
atypeFactory- the type factoryannotationScope- the element whose defaults are being appliedtype- the type to which to apply defaultsapplyToTypeVar- 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
wildcardTypeis a type argument is known, callgetWildcardBoundType(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
public QualifierDefaults.BoundType getWildcardBoundType(AnnotatedTypeMirror.AnnotatedWildcardType wildcardType, @Nullable AnnotatedTypeMirror.AnnotatedDeclaredType enclosingType) Returns the BoundType of annotatedWildcard. If it is unbounded, use the type parameter to which its an argument.- Parameters:
wildcardType- the annotated wildcard typeenclosingType- a declared type of whichwildcardTypemight be a type argument, or null- Returns:
- the BoundType of annotatedWildcard. If it is unbounded, use the type parameter to which its an argument
-