Class ElementQualifierHierarchy
- java.lang.Object
-
- org.checkerframework.framework.type.QualifierHierarchy
-
- org.checkerframework.framework.type.ElementQualifierHierarchy
-
- Direct Known Subclasses:
AccumulationAnnotatedTypeFactory.AccumulationQualifierHierarchy
,ClassValAnnotatedTypeFactory.ClassValQualifierHierarchy
,MethodValAnnotatedTypeFactory.MethodValQualifierHierarchy
,MostlyNoElementQualifierHierarchy
,UpperBoundAnnotatedTypeFactory.UpperBoundQualifierHierarchy
@AnnotatedFor("nullness") public abstract class ElementQualifierHierarchy extends QualifierHierarchy
AQualifierHierarchy
where qualifiers may be represented by annotations with elements.ElementQualifierHierarchy uses a
QualifierKindHierarchy
to model the relationships between qualifiers. (By contrast,MostlyNoElementQualifierHierarchy
uses theQualifierKindHierarchy
to implementisSubtype
,leastUpperBound
, andgreatestLowerBound
methods for qualifiers without elements.)Subclasses can override
createQualifierKindHierarchy(Collection)
to return a subclass of QualifierKindHierarchy.
-
-
Field Summary
Fields Modifier and Type Field Description protected AnnotationMirrorSet
bottoms
The set of bottom annotation mirrors.protected java.util.Map<QualifierKind,javax.lang.model.element.AnnotationMirror>
bottomsMap
A mapping from bottom QualifierKinds to their corresponding AnnotationMirror.protected java.util.Map<QualifierKind,javax.lang.model.element.AnnotationMirror>
kindToElementlessQualifier
A mapping from QualifierKind to AnnotationMirror for all qualifiers whose annotations do not have elements.protected QualifierKindHierarchy
qualifierKindHierarchy
protected AnnotationMirrorSet
tops
The set of top annotation mirrors.protected java.util.Map<QualifierKind,javax.lang.model.element.AnnotationMirror>
topsMap
A mapping from top QualifierKinds to their corresponding AnnotationMirror.-
Fields inherited from class org.checkerframework.framework.type.QualifierHierarchy
atypeFactory
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
ElementQualifierHierarchy(java.util.Collection<java.lang.Class<? extends java.lang.annotation.Annotation>> qualifierClasses, javax.lang.model.util.Elements elements, GenericAnnotatedTypeFactory<?,?,?,?> atypeFactory)
Creates a ElementQualifierHierarchy from the given classes.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected java.util.Map<QualifierKind,javax.lang.model.element.AnnotationMirror>
createBottomsMap()
Creates a mapping from QualifierKind to AnnotationMirror, where the QualifierKind is bottom and the AnnotationMirror is bottom in their respective hierarchies.protected java.util.Map<QualifierKind,javax.lang.model.element.AnnotationMirror>
createElementlessQualifierMap()
Creates a mapping from QualifierKind to AnnotationMirror for all qualifiers whose annotations do not have elements.protected QualifierKindHierarchy
createQualifierKindHierarchy(java.util.Collection<java.lang.Class<? extends java.lang.annotation.Annotation>> qualifierClasses)
Create theQualifierKindHierarchy
.protected java.util.Map<QualifierKind,javax.lang.model.element.AnnotationMirror>
createTopsMap()
Creates a mapping from QualifierKind to AnnotationMirror, where the QualifierKind is top and the AnnotationMirror is top in their respective hierarchies.@Nullable javax.lang.model.element.AnnotationMirror
findAnnotationInHierarchy(java.util.Collection<? extends javax.lang.model.element.AnnotationMirror> annos, javax.lang.model.element.AnnotationMirror top)
Returns the annotation inqualifiers
that is in the hierarchy for whichtop
is top.@Nullable javax.lang.model.element.AnnotationMirror
findAnnotationInSameHierarchy(java.util.Collection<? extends javax.lang.model.element.AnnotationMirror> annos, javax.lang.model.element.AnnotationMirror annotationMirror)
Returns the annotation inqualifiers
that is in the same hierarchy asqualifier
.javax.lang.model.element.AnnotationMirror
getBottomAnnotation(javax.lang.model.element.AnnotationMirror start)
Return the bottom for the given qualifier, that is, the qualifier that is a subtype ofqualifier
but no further subtypes exist.AnnotationMirrorSet
getBottomAnnotations()
Returns the bottom type qualifiers in the hierarchy.@Nullable javax.lang.model.element.AnnotationMirror
getPolymorphicAnnotation(javax.lang.model.element.AnnotationMirror start)
Returns the polymorphic qualifier for the hierarchy containingqualifier
, ornull
if there is no polymorphic qualifier in that hierarchy.protected QualifierKind
getQualifierKind(@CanonicalName java.lang.String name)
Returns the qualifier kind for the annotation with the canonical namename
.protected QualifierKind
getQualifierKind(javax.lang.model.element.AnnotationMirror anno)
Returns the qualifier kind for the given annotation.javax.lang.model.element.AnnotationMirror
getTopAnnotation(javax.lang.model.element.AnnotationMirror start)
Return the top qualifier for the given qualifier, that is, the qualifier that is a supertype ofqualifier
but no further supertypes exist.AnnotationMirrorSet
getTopAnnotations()
Returns the top (ultimate super) type qualifiers in the type system.boolean
isPolymorphicQualifier(javax.lang.model.element.AnnotationMirror qualifier)
Returnstrue
if the qualifier is a polymorphic qualifier; otherwise, returnsfalse
.boolean
isValid()
Determine whether this is valid.-
Methods inherited from class org.checkerframework.framework.type.QualifierHierarchy
assertSameSize, assertSameSize, canHaveEmptyAnnotationSet, getWidth, greatestLowerBoundQualifiers, greatestLowerBoundQualifiersOnly, greatestLowerBoundShallow, greatestLowerBoundsShallow, isSubtypeQualifiers, isSubtypeQualifiersOnly, isSubtypeShallow, isSubtypeShallow, isSubtypeShallow, isSubtypeShallow, leastUpperBoundQualifiers, leastUpperBoundQualifiersOnly, leastUpperBoundShallow, leastUpperBoundsShallow, numberOfIterationsBeforeWidening, updateMappingToMutableSet, widenedUpperBound
-
-
-
-
Field Detail
-
qualifierKindHierarchy
protected final QualifierKindHierarchy qualifierKindHierarchy
-
topsMap
protected final java.util.Map<QualifierKind,javax.lang.model.element.AnnotationMirror> topsMap
A mapping from top QualifierKinds to their corresponding AnnotationMirror.
-
tops
protected final AnnotationMirrorSet tops
The set of top annotation mirrors.
-
bottomsMap
protected final java.util.Map<QualifierKind,javax.lang.model.element.AnnotationMirror> bottomsMap
A mapping from bottom QualifierKinds to their corresponding AnnotationMirror.
-
bottoms
protected final AnnotationMirrorSet bottoms
The set of bottom annotation mirrors.
-
kindToElementlessQualifier
protected final java.util.Map<QualifierKind,javax.lang.model.element.AnnotationMirror> kindToElementlessQualifier
A mapping from QualifierKind to AnnotationMirror for all qualifiers whose annotations do not have elements.
-
-
Constructor Detail
-
ElementQualifierHierarchy
protected ElementQualifierHierarchy(java.util.Collection<java.lang.Class<? extends java.lang.annotation.Annotation>> qualifierClasses, javax.lang.model.util.Elements elements, GenericAnnotatedTypeFactory<?,?,?,?> atypeFactory)
Creates a ElementQualifierHierarchy from the given classes.- Parameters:
qualifierClasses
- classes of annotations that are the qualifiers for this hierarchyelements
- element utilsatypeFactory
- the associated type factory
-
-
Method Detail
-
isValid
public boolean isValid()
Description copied from class:QualifierHierarchy
Determine whether this is valid.- Overrides:
isValid
in classQualifierHierarchy
- Returns:
- true if this is valid
-
createQualifierKindHierarchy
protected QualifierKindHierarchy createQualifierKindHierarchy(@UnderInitialization ElementQualifierHierarchy this, java.util.Collection<java.lang.Class<? extends java.lang.annotation.Annotation>> qualifierClasses)
Create theQualifierKindHierarchy
. (Subclasses may override to return a subclass of QualifierKindHierarchy.)- Parameters:
qualifierClasses
- classes of annotations that are the qualifiers for this hierarchy- Returns:
- the newly created qualifier kind hierarchy
-
createElementlessQualifierMap
@RequiresNonNull({"this.qualifierKindHierarchy","this.elements"}) protected java.util.Map<QualifierKind,javax.lang.model.element.AnnotationMirror> createElementlessQualifierMap(@UnderInitialization ElementQualifierHierarchy this)
Creates a mapping from QualifierKind to AnnotationMirror for all qualifiers whose annotations do not have elements.- Returns:
- the mapping
-
createTopsMap
@RequiresNonNull({"this.qualifierKindHierarchy","this.elements"}) protected java.util.Map<QualifierKind,javax.lang.model.element.AnnotationMirror> createTopsMap(@UnderInitialization ElementQualifierHierarchy this)
Creates a mapping from QualifierKind to AnnotationMirror, where the QualifierKind is top and the AnnotationMirror is top in their respective hierarchies.This implementation works if the top annotation has no elements, or if it has elements, provides a default, and that default is the top. Otherwise, subclasses must override this.
- Returns:
- a mapping from top QualifierKind to top AnnotationMirror
-
createBottomsMap
@RequiresNonNull({"this.qualifierKindHierarchy","this.elements"}) protected java.util.Map<QualifierKind,javax.lang.model.element.AnnotationMirror> createBottomsMap(@UnderInitialization ElementQualifierHierarchy this)
Creates a mapping from QualifierKind to AnnotationMirror, where the QualifierKind is bottom and the AnnotationMirror is bottom in their respective hierarchies.This implementation works if the bottom annotation has no elements, or if it has elements, provides a default, and that default is the bottom. Otherwise, subclasses must override this.
- Returns:
- a mapping from bottom QualifierKind to bottom AnnotationMirror
-
getQualifierKind
protected QualifierKind getQualifierKind(javax.lang.model.element.AnnotationMirror anno)
Returns the qualifier kind for the given annotation.- Parameters:
anno
- an annotation mirror that is in this hierarchy- Returns:
- the qualifier kind for the given annotation
-
getQualifierKind
protected QualifierKind getQualifierKind(@CanonicalName java.lang.String name)
Returns the qualifier kind for the annotation with the canonical namename
.- Parameters:
name
- fully qualified annotation name- Returns:
- the qualifier kind for the annotation named
name
-
getTopAnnotations
public AnnotationMirrorSet getTopAnnotations()
Description copied from class:QualifierHierarchy
Returns the top (ultimate super) type qualifiers in the type system. The size of this set is equal toQualifierHierarchy.getWidth()
.- Specified by:
getTopAnnotations
in classQualifierHierarchy
- Returns:
- the top (ultimate super) type qualifiers in the type system
-
getTopAnnotation
public javax.lang.model.element.AnnotationMirror getTopAnnotation(javax.lang.model.element.AnnotationMirror start)
Description copied from class:QualifierHierarchy
Return the top qualifier for the given qualifier, that is, the qualifier that is a supertype ofqualifier
but no further supertypes exist.- Specified by:
getTopAnnotation
in classQualifierHierarchy
- Parameters:
start
- any qualifier from one of the qualifier hierarchies represented by this- Returns:
- the top qualifier of
qualifier
's hierarchy
-
getBottomAnnotations
public AnnotationMirrorSet getBottomAnnotations()
Description copied from class:QualifierHierarchy
Returns the bottom type qualifiers in the hierarchy. The size of this set is equal toQualifierHierarchy.getWidth()
.- Specified by:
getBottomAnnotations
in classQualifierHierarchy
- Returns:
- the bottom type qualifiers in the hierarchy
-
getPolymorphicAnnotation
public @Nullable javax.lang.model.element.AnnotationMirror getPolymorphicAnnotation(javax.lang.model.element.AnnotationMirror start)
Description copied from class:QualifierHierarchy
Returns the polymorphic qualifier for the hierarchy containingqualifier
, ornull
if there is no polymorphic qualifier in that hierarchy.- Specified by:
getPolymorphicAnnotation
in classQualifierHierarchy
- Parameters:
start
- any qualifier from one of the qualifier hierarchies represented by this- Returns:
- the polymorphic qualifier for the hierarchy containing
qualifier
, ornull
if there is no polymorphic qualifier in that hierarchy
-
isPolymorphicQualifier
public boolean isPolymorphicQualifier(javax.lang.model.element.AnnotationMirror qualifier)
Description copied from class:QualifierHierarchy
Returnstrue
if the qualifier is a polymorphic qualifier; otherwise, returnsfalse
.- Specified by:
isPolymorphicQualifier
in classQualifierHierarchy
- Parameters:
qualifier
- qualifier- Returns:
true
if the qualifier is a polymorphic qualifier; otherwise, returnsfalse
.
-
getBottomAnnotation
public javax.lang.model.element.AnnotationMirror getBottomAnnotation(javax.lang.model.element.AnnotationMirror start)
Description copied from class:QualifierHierarchy
Return the bottom for the given qualifier, that is, the qualifier that is a subtype ofqualifier
but no further subtypes exist.- Specified by:
getBottomAnnotation
in classQualifierHierarchy
- Parameters:
start
- any qualifier from one of the qualifier hierarchies represented by this- Returns:
- the bottom qualifier of
qualifier
's hierarchy
-
findAnnotationInSameHierarchy
public @Nullable javax.lang.model.element.AnnotationMirror findAnnotationInSameHierarchy(java.util.Collection<? extends javax.lang.model.element.AnnotationMirror> annos, javax.lang.model.element.AnnotationMirror annotationMirror)
Description copied from class:QualifierHierarchy
Returns the annotation inqualifiers
that is in the same hierarchy asqualifier
.The default implementation calls
QualifierHierarchy.getTopAnnotation(AnnotationMirror)
and then callsQualifierHierarchy.findAnnotationInHierarchy(Collection, AnnotationMirror)
. So, ifqualifier
is a top qualifier, then callQualifierHierarchy.findAnnotationInHierarchy(Collection, AnnotationMirror)
directly is faster.- Overrides:
findAnnotationInSameHierarchy
in classQualifierHierarchy
- Parameters:
annos
- set of annotations to searchannotationMirror
- annotation that is in the same hierarchy as the returned annotation- Returns:
- annotation in the same hierarchy as qualifier, or null if one is not found
-
findAnnotationInHierarchy
public @Nullable javax.lang.model.element.AnnotationMirror findAnnotationInHierarchy(java.util.Collection<? extends javax.lang.model.element.AnnotationMirror> annos, javax.lang.model.element.AnnotationMirror top)
Description copied from class:QualifierHierarchy
Returns the annotation inqualifiers
that is in the hierarchy for whichtop
is top.- Overrides:
findAnnotationInHierarchy
in classQualifierHierarchy
- Parameters:
annos
- set of annotations to searchtop
- the top annotation in the hierarchy to which the returned annotation belongs- Returns:
- annotation in the same hierarchy as annotationMirror, or null if one is not found
-
-