Class ElementQualifierHierarchy

java.lang.Object
org.checkerframework.framework.type.ElementQualifierHierarchy
All Implemented Interfaces:
QualifierHierarchy
Direct Known Subclasses:
AccumulationAnnotatedTypeFactory.AccumulationQualifierHierarchy, ClassValAnnotatedTypeFactory.ClassValQualifierHierarchy, MethodValAnnotatedTypeFactory.MethodValQualifierHierarchy, MostlyNoElementQualifierHierarchy, UpperBoundAnnotatedTypeFactory.UpperBoundQualifierHierarchy

@AnnotatedFor("nullness") public abstract class ElementQualifierHierarchy extends Object implements QualifierHierarchy
A QualifierHierarchy where qualifiers may be represented by annotations with elements.

ElementQualifierHierarchy uses a QualifierKindHierarchy to model the relationships between qualifiers. (By contrast, MostlyNoElementQualifierHierarchy uses the QualifierKindHierarchy to implement isSubtype, leastUpperBound, and greatestLowerBound methods for qualifiers without elements.)

Subclasses can override createQualifierKindHierarchy(Collection) to return a subclass of QualifierKindHierarchy.

  • Field Details

  • Constructor Details

    • ElementQualifierHierarchy

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

    • isValid

      public boolean isValid()
      Description copied from interface: QualifierHierarchy
      Determine whether this is valid.
      Specified by:
      isValid in interface QualifierHierarchy
      Returns:
      whether this is valid
    • createQualifierKindHierarchy

      protected QualifierKindHierarchy createQualifierKindHierarchy(@UnderInitialization ElementQualifierHierarchy this, Collection<Class<? extends Annotation>> qualifierClasses)
      Create the QualifierKindHierarchy. (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 Map<QualifierKind,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 Map<QualifierKind,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 Map<QualifierKind,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(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 String name)
      Returns the qualifier kind for the annotation with the canonical name name.
      Parameters:
      name - fully qualified annotation name
      Returns:
      the qualifier kind for the annotation named name
    • getTopAnnotations

      public Set<? extends AnnotationMirror> getTopAnnotations()
      Description copied from interface: QualifierHierarchy
      Returns the top (ultimate super) type qualifiers in the type system. The size of this set is equal to QualifierHierarchy.getWidth().
      Specified by:
      getTopAnnotations in interface QualifierHierarchy
      Returns:
      the top (ultimate super) type qualifiers in the type system
    • getTopAnnotation

      public AnnotationMirror getTopAnnotation(AnnotationMirror start)
      Description copied from interface: QualifierHierarchy
      Return the top qualifier for the given qualifier, that is, the qualifier that is a supertype of qualifier but no further supertypes exist.
      Specified by:
      getTopAnnotation in interface QualifierHierarchy
      Parameters:
      start - any qualifier from one of the qualifier hierarchies represented by this
      Returns:
      the top qualifier of qualifier's hierarchy
    • getBottomAnnotations

      public Set<? extends AnnotationMirror> getBottomAnnotations()
      Description copied from interface: QualifierHierarchy
      Returns the bottom type qualifiers in the hierarchy. The size of this set is equal to QualifierHierarchy.getWidth().
      Specified by:
      getBottomAnnotations in interface QualifierHierarchy
      Returns:
      the bottom type qualifiers in the hierarchy
    • getPolymorphicAnnotation

      public @Nullable AnnotationMirror getPolymorphicAnnotation(AnnotationMirror start)
      Description copied from interface: QualifierHierarchy
      Returns the polymorphic qualifier for the hierarchy containing qualifier, or null if there is no polymorphic qualifier in that hierarchy.
      Specified by:
      getPolymorphicAnnotation in interface QualifierHierarchy
      Parameters:
      start - any qualifier from one of the qualifier hierarchies represented by this
      Returns:
      the polymorphic qualifier for the hierarchy containing qualifier, or null if there is no polymorphic qualifier in that hierarchy
    • isPolymorphicQualifier

      public boolean isPolymorphicQualifier(AnnotationMirror qualifier)
      Description copied from interface: QualifierHierarchy
      Returns true if the qualifier is a polymorphic qualifier; otherwise, returns false.
      Specified by:
      isPolymorphicQualifier in interface QualifierHierarchy
      Parameters:
      qualifier - qualifier
      Returns:
      true if the qualifier is a polymorphic qualifier; otherwise, returns false.
    • getBottomAnnotation

      public AnnotationMirror getBottomAnnotation(AnnotationMirror start)
      Description copied from interface: QualifierHierarchy
      Return the bottom for the given qualifier, that is, the qualifier that is a subtype of qualifier but no further subtypes exist.
      Specified by:
      getBottomAnnotation in interface QualifierHierarchy
      Parameters:
      start - any qualifier from one of the qualifier hierarchies represented by this
      Returns:
      the bottom qualifier of qualifier's hierarchy
    • findAnnotationInSameHierarchy

      public @Nullable AnnotationMirror findAnnotationInSameHierarchy(Collection<? extends AnnotationMirror> annos, AnnotationMirror annotationMirror)
      Description copied from interface: QualifierHierarchy
      Returns the annotation in qualifiers that is in the same hierarchy as qualifier.

      The default implementation calls QualifierHierarchy.getTopAnnotation(AnnotationMirror) and then calls QualifierHierarchy.findAnnotationInHierarchy(Collection, AnnotationMirror). So, if qualifier is a top qualifier, then call QualifierHierarchy.findAnnotationInHierarchy(Collection, AnnotationMirror) directly is faster.

      Specified by:
      findAnnotationInSameHierarchy in interface QualifierHierarchy
      Parameters:
      annos - set of annotations to search
      annotationMirror - 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 AnnotationMirror findAnnotationInHierarchy(Collection<? extends AnnotationMirror> annos, AnnotationMirror top)
      Description copied from interface: QualifierHierarchy
      Returns the annotation in qualifiers that is in the hierarchy for which top is top.
      Specified by:
      findAnnotationInHierarchy in interface QualifierHierarchy
      Parameters:
      annos - set of annotations to search
      top - 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