Class NoElementQualifierHierarchy
- java.lang.Object
-
- org.checkerframework.framework.type.QualifierHierarchy
-
- org.checkerframework.framework.type.NoElementQualifierHierarchy
-
- Direct Known Subclasses:
AliasingAnnotatedTypeFactory.AliasingQualifierHierarchy
@AnnotatedFor("nullness") public class NoElementQualifierHierarchy extends QualifierHierarchy
AQualifierHierarchy
where no qualifier has arguments; that is, no qualifier is represented by an annotation with elements. The meta-annotationSubtypeOf
specifies the subtyping relationships.It uses a
QualifierKindHierarchy
to model the relationships between qualifiers. Subclasses can overridecreateQualifierKindHierarchy(Collection)
to return a subclass of QualifierKindHierarchy.
-
-
Field Summary
Fields Modifier and Type Field Description protected AnnotationMirrorSet
bottoms
Set of bottom annotation mirrors.protected java.util.Map<QualifierKind,javax.lang.model.element.AnnotationMirror>
kindToAnnotationMirror
Mapping fromQualifierKind
to its correspondingAnnotationMirror
.protected QualifierKindHierarchy
qualifierKindHierarchy
protected java.util.Set<? extends javax.lang.model.element.AnnotationMirror>
qualifiers
Set of all annotations in all the hierarchies.protected AnnotationMirrorSet
tops
Set of top annotation mirrors.-
Fields inherited from class org.checkerframework.framework.type.QualifierHierarchy
atypeFactory
-
-
Constructor Summary
Constructors Constructor Description NoElementQualifierHierarchy(java.util.Collection<java.lang.Class<? extends java.lang.annotation.Annotation>> qualifierClasses, javax.lang.model.util.Elements elements, GenericAnnotatedTypeFactory<?,?,?,?> atypeFactory)
Creates a NoElementQualifierHierarchy 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>
createAnnotationMirrors(javax.lang.model.util.Elements elements)
Creates and returns a mapping from qualifier kind to an annotation mirror created from the qualifier kind's annotation class.protected AnnotationMirrorSet
createBottoms()
Creates and returns the unmodifiable set of bottomAnnotationMirror
s.protected QualifierKindHierarchy
createQualifierKindHierarchy(java.util.Collection<java.lang.Class<? extends java.lang.annotation.Annotation>> qualifierClasses)
Create theQualifierKindHierarchy
.protected AnnotationMirrorSet
createTops()
Creates and returns the unmodifiable set of topAnnotationMirror
s.@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(javax.lang.model.element.AnnotationMirror anno)
Returns theQualifierKind
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.@Nullable javax.lang.model.element.AnnotationMirror
greatestLowerBoundQualifiers(javax.lang.model.element.AnnotationMirror a1, javax.lang.model.element.AnnotationMirror a2)
Returns the greatest lower bound for the qualifiers qualifier1 and qualifier2.boolean
isPolymorphicQualifier(javax.lang.model.element.AnnotationMirror qualifier)
Returnstrue
if the qualifier is a polymorphic qualifier; otherwise, returnsfalse
.boolean
isSubtypeQualifiers(javax.lang.model.element.AnnotationMirror subAnno, javax.lang.model.element.AnnotationMirror superAnno)
Tests whethersubQualifier
is equal to or a sub-qualifier ofsuperQualifier
, according to the type qualifier hierarchy, ignoring Java basetypes.@Nullable javax.lang.model.element.AnnotationMirror
leastUpperBoundQualifiers(javax.lang.model.element.AnnotationMirror a1, javax.lang.model.element.AnnotationMirror a2)
Returns the least upper bound (LUB) of the qualifiersqualifier1
andqualifier2
.-
Methods inherited from class org.checkerframework.framework.type.QualifierHierarchy
assertSameSize, assertSameSize, canHaveEmptyAnnotationSet, getWidth, greatestLowerBoundQualifiersOnly, greatestLowerBoundShallow, greatestLowerBoundsShallow, isSubtypeQualifiersOnly, isSubtypeShallow, isSubtypeShallow, isSubtypeShallow, isSubtypeShallow, isValid, leastUpperBoundQualifiersOnly, leastUpperBoundShallow, leastUpperBoundsShallow, numberOfIterationsBeforeWidening, updateMappingToMutableSet, widenedUpperBound
-
-
-
-
Field Detail
-
qualifierKindHierarchy
protected final QualifierKindHierarchy qualifierKindHierarchy
-
tops
protected final AnnotationMirrorSet tops
Set of top annotation mirrors.
-
bottoms
protected final AnnotationMirrorSet bottoms
Set of bottom annotation mirrors.
-
kindToAnnotationMirror
protected final java.util.Map<QualifierKind,javax.lang.model.element.AnnotationMirror> kindToAnnotationMirror
Mapping fromQualifierKind
to its correspondingAnnotationMirror
.
-
qualifiers
protected final java.util.Set<? extends javax.lang.model.element.AnnotationMirror> qualifiers
Set of all annotations in all the hierarchies.
-
-
Constructor Detail
-
NoElementQualifierHierarchy
public NoElementQualifierHierarchy(java.util.Collection<java.lang.Class<? extends java.lang.annotation.Annotation>> qualifierClasses, javax.lang.model.util.Elements elements, GenericAnnotatedTypeFactory<?,?,?,?> atypeFactory)
Creates a NoElementQualifierHierarchy from the given classes.- Parameters:
qualifierClasses
- classes of annotations that are the qualifierselements
- element utilsatypeFactory
- the associated type factory
-
-
Method Detail
-
createQualifierKindHierarchy
protected QualifierKindHierarchy createQualifierKindHierarchy(@UnderInitialization NoElementQualifierHierarchy 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- Returns:
- the newly created qualifier kind hierarchy
-
createAnnotationMirrors
@RequiresNonNull("this.qualifierKindHierarchy") protected java.util.Map<QualifierKind,javax.lang.model.element.AnnotationMirror> createAnnotationMirrors(@UnderInitialization NoElementQualifierHierarchy this, javax.lang.model.util.Elements elements)
Creates and returns a mapping from qualifier kind to an annotation mirror created from the qualifier kind's annotation class.- Parameters:
elements
- element utils- Returns:
- a mapping from qualifier kind to its annotation mirror
-
createTops
@RequiresNonNull({"this.kindToAnnotationMirror","this.qualifierKindHierarchy"}) protected AnnotationMirrorSet createTops(@UnderInitialization NoElementQualifierHierarchy this)
Creates and returns the unmodifiable set of topAnnotationMirror
s.- Returns:
- the unmodifiable set of top
AnnotationMirror
s
-
createBottoms
@RequiresNonNull({"this.kindToAnnotationMirror","this.qualifierKindHierarchy"}) protected AnnotationMirrorSet createBottoms(@UnderInitialization NoElementQualifierHierarchy this)
Creates and returns the unmodifiable set of bottomAnnotationMirror
s.- Returns:
- the unmodifiable set of bottom
AnnotationMirror
s
-
getQualifierKind
protected QualifierKind getQualifierKind(javax.lang.model.element.AnnotationMirror anno)
Returns theQualifierKind
for the given annotation.- Parameters:
anno
- an annotation that is a qualifier in this- Returns:
- the
QualifierKind
for the given annotation
-
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
-
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
-
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
-
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
.
-
isSubtypeQualifiers
public boolean isSubtypeQualifiers(javax.lang.model.element.AnnotationMirror subAnno, javax.lang.model.element.AnnotationMirror superAnno)
Description copied from class:QualifierHierarchy
Tests whethersubQualifier
is equal to or a sub-qualifier ofsuperQualifier
, according to the type qualifier hierarchy, ignoring Java basetypes.Clients should generally call
QualifierHierarchy.isSubtypeShallow(javax.lang.model.element.AnnotationMirror, javax.lang.model.type.TypeMirror, javax.lang.model.element.AnnotationMirror, javax.lang.model.type.TypeMirror)
. However, subtypes should generally override this method (if needed).This method behaves the same as
QualifierHierarchy.isSubtypeQualifiersOnly(AnnotationMirror, AnnotationMirror)
, which calls this method. This method is for clients inside the framework, and it hasprotected
access to prevent use by clients outside the framework. This makes it easy to find places where code outside the framework is ignoring Java basetypes -- at calls toQualifierHierarchy.isSubtypeQualifiersOnly(javax.lang.model.element.AnnotationMirror, javax.lang.model.element.AnnotationMirror)
.- Specified by:
isSubtypeQualifiers
in classQualifierHierarchy
- Parameters:
subAnno
- possible subqualifiersuperAnno
- possible superqualifier- Returns:
- true iff
subQualifier
is a subqualifier of, or equal to,superQualifier
-
leastUpperBoundQualifiers
public @Nullable javax.lang.model.element.AnnotationMirror leastUpperBoundQualifiers(javax.lang.model.element.AnnotationMirror a1, javax.lang.model.element.AnnotationMirror a2)
Description copied from class:QualifierHierarchy
Returns the least upper bound (LUB) of the qualifiersqualifier1
andqualifier2
. Returnsnull
if the qualifiers are not from the same qualifier hierarchy. Ignores Java basetypes.Examples:
- For NonNull, leastUpperBound('Nullable', 'NonNull') ⇒ Nullable
- Specified by:
leastUpperBoundQualifiers
in classQualifierHierarchy
- Parameters:
a1
- the first qualifier; may not be in the same hierarchy asqualifier2
a2
- the second qualifier; may not be in the same hierarchy asqualifier1
- Returns:
- the least upper bound of the qualifiers, or
null
if the qualifiers are from different hierarchies
-
greatestLowerBoundQualifiers
public @Nullable javax.lang.model.element.AnnotationMirror greatestLowerBoundQualifiers(javax.lang.model.element.AnnotationMirror a1, javax.lang.model.element.AnnotationMirror a2)
Description copied from class:QualifierHierarchy
Returns the greatest lower bound for the qualifiers qualifier1 and qualifier2. Returns null if the qualifiers are not from the same qualifier hierarchy.- Specified by:
greatestLowerBoundQualifiers
in classQualifierHierarchy
- Parameters:
a1
- first qualifiera2
- second qualifier- Returns:
- greatest lower bound of the two annotations, or null if the two annotations are not from the same hierarchy
-
-