@AnnotatedFor(value="nullness") public class DefaultQualifierKindHierarchy extends Object implements QualifierKindHierarchy
QualifierKindHierarchy
.
By default, the subtyping information and information about polymorphic qualifiers is read from meta-annotations on the annotation classes. This information is used to infer further information such as top and bottom qualifiers. Subclasses can override the following methods to change this behavior:
createQualifierKinds(Collection)
createDirectSuperMap()
initializePolymorphicQualifiers()
initializeQualifierKindFields(Map)
createLubsMap()
createGlbsMap()
DefaultQualifierKindHierarchy.DefaultQualifierKind
is the implementation used for QualifierKind
by this class.Modifier and Type | Class and Description |
---|---|
static class |
DefaultQualifierKindHierarchy.DefaultQualifierKind
The default implementation of
QualifierKind . |
Modifier and Type | Field and Description |
---|---|
protected Map<String,DefaultQualifierKindHierarchy.DefaultQualifierKind> |
nameToQualifierKind
A mapping from canonical name of a qualifier class to the QualifierKind object representing
that class.
|
protected List<DefaultQualifierKindHierarchy.DefaultQualifierKind> |
qualifierKinds
A list of all
QualifierKind s for this DefaultQualifierKindHierarchy, sorted in
ascending order. |
Constructor and Description |
---|
DefaultQualifierKindHierarchy(Collection<Class<? extends Annotation>> qualifierClasses)
Creates a
DefaultQualifierKindHierarchy . |
DefaultQualifierKindHierarchy(Collection<Class<? extends Annotation>> qualifierClasses,
Class<? extends Annotation> bottom)
Creates a
DefaultQualifierKindHierarchy . |
Modifier and Type | Method and Description |
---|---|
List<? extends QualifierKind> |
allQualifierKinds()
Returns a list of all
QualifierKind s sorted in ascending order. |
protected Map<DefaultQualifierKindHierarchy.DefaultQualifierKind,Set<DefaultQualifierKindHierarchy.DefaultQualifierKind>> |
createDirectSuperMap()
Creates a mapping from a
QualifierKind to a set of its direct super qualifier kinds. |
protected Map<QualifierKind,Map<QualifierKind,QualifierKind>> |
createGlbsMap()
Creates the glb of qualifier kinds.
|
protected Map<QualifierKind,Map<QualifierKind,QualifierKind>> |
createLubsMap()
Creates the lub of qualifier kinds.
|
protected Map<String,DefaultQualifierKindHierarchy.DefaultQualifierKind> |
createQualifierKinds(Collection<Class<? extends Annotation>> qualifierClasses)
Creates all QualifierKind objects for the given qualifier classes and adds them to
qualifierClassMap.
|
protected static Set<QualifierKind> |
findHighestQualifiers(Set<QualifierKind> qualifierKinds)
Returns the highest qualifiers in the passed set.
|
protected static Set<QualifierKind> |
findLowestQualifiers(Set<QualifierKind> qualifierKinds)
Returns the lowest qualifiers in the passed set.
|
Set<? extends QualifierKind> |
getBottoms()
Returns the qualifier kinds that are the bottom qualifier in their hierarchies.
|
@Nullable QualifierKind |
getQualifierKind(@CanonicalName String name)
Returns the
QualifierKind for the given annotation class name, or null if one does not
exist. |
Set<? extends QualifierKind> |
getTops()
Returns the qualifier kinds that are the top qualifier in their hierarchies.
|
@Nullable QualifierKind |
greatestLowerBound(QualifierKind q1,
QualifierKind q2)
Returns the greatest lower bound of
q1 and q2 , or null if the qualifier
kinds are not in the same hierarchy. |
protected void |
initializePolymorphicQualifiers()
Iterates over all the qualifier kinds and adds all polymorphic qualifier kinds to
polymorphicQualifiers.
|
protected void |
initializeQualifierKindFields(Map<DefaultQualifierKindHierarchy.DefaultQualifierKind,Set<DefaultQualifierKindHierarchy.DefaultQualifierKind>> directSuperMap)
For each qualifier kind in
directSuperMap , initializes DefaultQualifierKindHierarchy.DefaultQualifierKind.strictSuperTypes , DefaultQualifierKindHierarchy.DefaultQualifierKind.top , DefaultQualifierKindHierarchy.DefaultQualifierKind.bottom , and DefaultQualifierKindHierarchy.DefaultQualifierKind.poly . |
@Nullable QualifierKind |
leastUpperBound(QualifierKind q1,
QualifierKind q2)
Returns the least upper bound of
q1 and q2 , or null if the qualifier
kinds are not in the same hierarchy. |
protected void |
verifyHierarchy(Map<DefaultQualifierKindHierarchy.DefaultQualifierKind,Set<DefaultQualifierKindHierarchy.DefaultQualifierKind>> directSuperMap)
Verifies that the
DefaultQualifierKindHierarchy is a valid hierarchy. |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
annotationClassName
protected final Map<String,DefaultQualifierKindHierarchy.DefaultQualifierKind> nameToQualifierKind
protected final List<DefaultQualifierKindHierarchy.DefaultQualifierKind> qualifierKinds
QualifierKind
s for this DefaultQualifierKindHierarchy, sorted in
ascending order.public DefaultQualifierKindHierarchy(Collection<Class<? extends Annotation>> qualifierClasses)
DefaultQualifierKindHierarchy
. Also, creates and initializes all its
qualifier kinds.qualifierClasses
- all the classes of qualifiers supported by this hierarchypublic DefaultQualifierKindHierarchy(Collection<Class<? extends Annotation>> qualifierClasses, Class<? extends Annotation> bottom)
DefaultQualifierKindHierarchy
. Also, creates and initializes all its
qualifier kinds.
For some type systems, qualifiers may be added at run time, so the SubtypeOf
meta-annotation on the bottom qualifier class cannot specify all other qualifiers. For those
type systems, use this constructor. Otherwise, use DefaultQualifierKindHierarchy(Collection)
.
qualifierClasses
- all the classes of qualifiers supported by this hierarchybottom
- the bottom qualifier of this hierarchypublic Set<? extends QualifierKind> getTops()
QualifierKindHierarchy
getTops
in interface QualifierKindHierarchy
public Set<? extends QualifierKind> getBottoms()
QualifierKindHierarchy
getBottoms
in interface QualifierKindHierarchy
public @Nullable QualifierKind leastUpperBound(QualifierKind q1, QualifierKind q2)
QualifierKindHierarchy
q1
and q2
, or null
if the qualifier
kinds are not in the same hierarchy. Ignores elements/arguments (as QualifierKind always does).leastUpperBound
in interface QualifierKindHierarchy
q1
- a qualifier kindq2
- a qualifier kindq1
and q2
, or null
if the qualifier
kinds are not in the same hierarchypublic @Nullable QualifierKind greatestLowerBound(QualifierKind q1, QualifierKind q2)
QualifierKindHierarchy
q1
and q2
, or null
if the qualifier
kinds are not in the same hierarchy. Ignores elements/arguments (as QualifierKind always does).greatestLowerBound
in interface QualifierKindHierarchy
q1
- a qualifier kindq2
- a qualifier kindq1
and q2
, or null
if the qualifier
kinds are not in the same hierarchypublic List<? extends QualifierKind> allQualifierKinds()
QualifierKindHierarchy
QualifierKind
s sorted in ascending order.allQualifierKinds
in interface QualifierKindHierarchy
QualifierKind
s sorted in ascending orderpublic @Nullable QualifierKind getQualifierKind(@CanonicalName String name)
QualifierKindHierarchy
QualifierKind
for the given annotation class name, or null if one does not
exist.getQualifierKind
in interface QualifierKindHierarchy
name
- canonical name of an annotation classQualifierKind
for the given annotation class name, or null if one does not
exist@RequiresNonNull(value={"this.qualifierKinds","this.tops","this.bottoms"}) protected void verifyHierarchy(@UnderInitialization DefaultQualifierKindHierarchy this, Map<DefaultQualifierKindHierarchy.DefaultQualifierKind,Set<DefaultQualifierKindHierarchy.DefaultQualifierKind>> directSuperMap)
DefaultQualifierKindHierarchy
is a valid hierarchy.directSuperMap
- mapping from qualifier to its direct supertypes; used to verify that a
polymorphic annotation does not have a SubtypeOf
meta-annotationTypeSystemError
- if the hierarchy isn't validprotected Map<String,DefaultQualifierKindHierarchy.DefaultQualifierKind> createQualifierKinds(@UnderInitialization DefaultQualifierKindHierarchy this, Collection<Class<? extends Annotation>> qualifierClasses)
QualifierKind
;
that is done by initializeQualifierKindFields(Map)
.qualifierClasses
- classes of annotations that are type qualifiersQualifierKind
@RequiresNonNull(value={"this.nameToQualifierKind","this.qualifierKinds"}) protected Map<DefaultQualifierKindHierarchy.DefaultQualifierKind,Set<DefaultQualifierKindHierarchy.DefaultQualifierKind>> createDirectSuperMap(@UnderInitialization DefaultQualifierKindHierarchy this)
QualifierKind
to a set of its direct super qualifier kinds.
The direct super qualifier kinds do not contain the qualifier itself. This mapping is used to
create the bottom set, to create the top set, and by initializeQualifierKindFields(Map)
.
This implementation uses the SubtypeOf
meta-annotation. Subclasses may override this
method to create the direct super map some other way.
Note that this method is called from the constructor when nameToQualifierKind
and
qualifierKinds
are the only fields that have nonnull values. This method is not
static, so it can be overridden by subclasses.
QualifierKind
to a set of its direct super qualifiers@RequiresNonNull(value={"this.nameToQualifierKind","this.qualifierKinds","this.tops"}) protected void initializePolymorphicQualifiers(@UnderInitialization DefaultQualifierKindHierarchy this)
DefaultQualifierKindHierarchy.DefaultQualifierKind.poly
and DefaultQualifierKindHierarchy.DefaultQualifierKind.top
for the polymorphic qualifiers, and sets DefaultQualifierKindHierarchy.DefaultQualifierKind.poly
for the top qualifiers.
Requires that tops has been initialized.
@RequiresNonNull(value={"this.qualifierKinds","this.tops","this.bottoms"}) protected void initializeQualifierKindFields(@UnderInitialization DefaultQualifierKindHierarchy this, Map<DefaultQualifierKindHierarchy.DefaultQualifierKind,Set<DefaultQualifierKindHierarchy.DefaultQualifierKind>> directSuperMap)
directSuperMap
, initializes DefaultQualifierKindHierarchy.DefaultQualifierKind.strictSuperTypes
, DefaultQualifierKindHierarchy.DefaultQualifierKind.top
, DefaultQualifierKindHierarchy.DefaultQualifierKind.bottom
, and DefaultQualifierKindHierarchy.DefaultQualifierKind.poly
.
Requires tops, bottoms, and polymorphicQualifiers to be initialized.
directSuperMap
- a mapping from a QualifierKind
to a set of its direct super
qualifier kinds; created by createDirectSuperMap()
@RequiresNonNull(value="this.qualifierKinds") protected Map<QualifierKind,Map<QualifierKind,QualifierKind>> createLubsMap(@UnderInitialization DefaultQualifierKindHierarchy this)
lubs.get(kind1).get(kind2)
returns the lub of kind1
and kind2.protected static Set<QualifierKind> findLowestQualifiers(Set<QualifierKind> qualifierKinds)
qualifierKinds
- a set of qualifiers@RequiresNonNull(value="this.qualifierKinds") protected Map<QualifierKind,Map<QualifierKind,QualifierKind>> createGlbsMap(@UnderInitialization DefaultQualifierKindHierarchy this)
glbs.get(kind1).get(kind2)
returns the glb of kind1
and kind2.protected static Set<QualifierKind> findHighestQualifiers(Set<QualifierKind> qualifierKinds)
qualifierKinds
- a set of qualifiers