Class MostlyNoElementQualifierHierarchy

java.lang.Object
org.checkerframework.framework.type.ElementQualifierHierarchy
org.checkerframework.framework.type.MostlyNoElementQualifierHierarchy
All Implemented Interfaces:
QualifierHierarchy
Direct Known Subclasses:
FenumAnnotatedTypeFactory.FenumQualifierHierarchy, InitializationAnnotatedTypeFactory.InitializationQualifierHierarchy, SubtypeIsSubsetQualifierHierarchy, SubtypeIsSupersetQualifierHierarchy, UnitsAnnotatedTypeFactory.UnitsQualifierHierarchy

@AnnotatedFor("nullness") public abstract class MostlyNoElementQualifierHierarchy extends ElementQualifierHierarchy
A QualifierHierarchy where qualifiers may be represented by annotations with elements, but most of the qualifiers do not have elements. In contrast to ElementQualifierHierarchy, this class partially implements isSubtype(AnnotationMirror, AnnotationMirror), leastUpperBound(AnnotationMirror, AnnotationMirror), and greatestLowerBound(AnnotationMirror, AnnotationMirror) and calls *WithElements when the result cannot be computed from the meta-annotations SubtypeOf.

Subclasses must implement the following methods when annotations have elements:

MostlyNoElementQualifierHierarchy uses a QualifierKindHierarchy to model the relationships between qualifiers. Subclasses can override ElementQualifierHierarchy.createQualifierKindHierarchy(Collection) to return a subclass of QualifierKindHierarchy.

  • Constructor Details

    • MostlyNoElementQualifierHierarchy

      protected MostlyNoElementQualifierHierarchy(Collection<Class<? extends Annotation>> qualifierClasses, Elements elements)
      Creates a MostlyNoElementQualifierHierarchy from the given classes.
      Parameters:
      qualifierClasses - classes of annotations that are the qualifiers for this hierarchy
      elements - element utils
  • Method Details

    • isSubtype

      public final boolean isSubtype(AnnotationMirror subAnno, AnnotationMirror superAnno)
      Description copied from interface: QualifierHierarchy
      Tests whether subQualifier is equal to or a sub-qualifier of superQualifier, according to the type qualifier hierarchy.
      Parameters:
      subAnno - possible subqualifier of superQualifier
      superAnno - possible superqualifier of subQualifier
      Returns:
      true iff subQualifier is a subqualifier of, or equal to, superQualifier
    • isSubtypeWithElements

      protected abstract boolean isSubtypeWithElements(AnnotationMirror subAnno, QualifierKind subKind, AnnotationMirror superAnno, QualifierKind superKind)
      Returns true if subAnno is a subtype of superAnno. Both subAnno and superAnno are annotations with elements. subKind is a sub qualifier kind of superKind.
      Parameters:
      subAnno - possible subtype annotation; has elements
      subKind - QualifierKind of subAnno
      superAnno - possible super annotation; has elements
      superKind - QualifierKind of superAnno
      Returns:
      true if subAnno is a subtype of superAnno
    • leastUpperBound

      public final @Nullable AnnotationMirror leastUpperBound(AnnotationMirror a1, AnnotationMirror a2)
      Description copied from interface: QualifierHierarchy
      Returns the least upper bound (LUB) of the qualifiers qualifier1 and qualifier2. Returns null if the qualifiers are not from the same qualifier hierarchy.

      Examples:

      • For NonNull, leastUpperBound('Nullable', 'NonNull') ⇒ Nullable
      Parameters:
      a1 - the first qualifier; may not be in the same hierarchy as qualifier2
      a2 - the second qualifier; may not be in the same hierarchy as qualifier1
      Returns:
      the least upper bound of the qualifiers, or null if the qualifiers are from different hierarchies
    • leastUpperBoundWithElements

      protected abstract AnnotationMirror leastUpperBoundWithElements(AnnotationMirror a1, QualifierKind qualifierKind1, AnnotationMirror a2, QualifierKind qualifierKind2, QualifierKind lubKind)
      Returns the least upper bound of a1 and a2 in cases where the lub of qualifierKind1 and qualifierKind2 is a qualifier kind that has elements. If the lub of qualifierKind1 and qualifierKind2 does not have elements, then leastUpperBound(AnnotationMirror, AnnotationMirror) returns the correct AnnotationMirror without calling this method.
      Parameters:
      a1 - first annotation
      qualifierKind1 - QualifierKind for a1
      a2 - second annotation
      qualifierKind2 - QualifierKind for a2
      lubKind - the kind of the lub of qualifierKind1 and qualifierKind2
      Returns:
      the least upper bound of a1 and a2
    • greatestLowerBound

      public final @Nullable AnnotationMirror greatestLowerBound(AnnotationMirror a1, AnnotationMirror a2)
      Description copied from interface: QualifierHierarchy
      Returns the greatest lower bound for the qualifiers qualifier1 and qualifier2. Returns null if the qualifiers are not from the same qualifier hierarchy.
      Parameters:
      a1 - first qualifier
      a2 - second qualifier
      Returns:
      greatest lower bound of the two annotations or null if the two annotations are not from the same hierarchy
    • greatestLowerBoundWithElements

      protected abstract AnnotationMirror greatestLowerBoundWithElements(AnnotationMirror a1, QualifierKind qualifierKind1, AnnotationMirror a2, QualifierKind qualifierKind2, QualifierKind glbKind)
      Returns the greatest lower bound of a1 and a2 in cases where the glb of qualifierKind1 and qualifierKind2 is a qualifier kind that has elements. If the glb of qualifierKind1 and qualifierKind2 does not have elements, then greatestLowerBound(AnnotationMirror, AnnotationMirror) returns the correct AnnotationMirror without calling this method.
      Parameters:
      a1 - first annotation
      qualifierKind1 - QualifierKind for a1
      a2 - second annotation
      qualifierKind2 - QualifierKind for a2
      Returns:
      the greatest lower bound between a1 and a2