Class IntersectionGlbAnnotatedTypeFactory

All Implemented Interfaces:
AnnotationProvider

public class IntersectionGlbAnnotatedTypeFactory extends BaseAnnotatedTypeFactory
The type factory for IntersectionGlbChecker.
  • Constructor Details

    • IntersectionGlbAnnotatedTypeFactory

      public IntersectionGlbAnnotatedTypeFactory(BaseTypeChecker checker)
      Creates an IntersectionGlbAnnotatedTypeFactory.
      Parameters:
      checker - the checker
  • Method Details

    • createSupportedTypeQualifiers

      protected Set<Class<? extends Annotation>> createSupportedTypeQualifiers()
      Description copied from class: AnnotatedTypeFactory
      Returns a mutable set of annotation classes that are supported by a checker.

      Subclasses may override this method to return a mutable set of their supported type qualifiers through one of the 5 approaches shown below.

      Subclasses should not call this method; they should call AnnotatedTypeFactory.getSupportedTypeQualifiers() instead.

      By default, a checker supports all annotations located in a subdirectory called qual that's located in the same directory as the checker. Note that only annotations defined with the @Target({ElementType.TYPE_USE}) meta-annotation (and optionally with the additional value of ElementType.TYPE_PARAMETER, but no other ElementType values) are automatically considered as supported annotations.

      To support a different set of annotations than those in the qual subdirectory, or that have other ElementType values, see examples below.

      In total, there are 3 ways to indicate annotations that are supported by a checker:

      1. Only support annotations located in a checker's qual directory:

        This is the default behavior. Simply place those annotations within the qual directory.

      2. Support annotations located in a checker's qual directory and a list of other annotations:

        Place those annotations within the qual directory, and override AnnotatedTypeFactory.createSupportedTypeQualifiers() by calling AnnotatedTypeFactory.getBundledTypeQualifiers(Class...) with a varargs parameter list of the other annotations. Code example:

         @Override
         protected Set<Class<? extends Annotation>> createSupportedTypeQualifiers() {
           return getBundledTypeQualifiers(
             // These annotations are in the Called Methods Checker, not the Resource Leak Checker.
             CalledMethods.class, CalledMethodsBottom.class, CalledMethodsPredicate.class);
          } 
         
      3. Support only annotations that are explicitly listed. This is common when a single directory holds qualifiers for multiple qualifier hierarchies. Override AnnotatedTypeFactory.createSupportedTypeQualifiers() and return a mutable set of the supported annotations. Code example:
         @Override
         protected Set<Class<? extends Annotation>> createSupportedTypeQualifiers() {
              return new HashSet<Class<? extends Annotation>>(
                      Arrays.asList(A.class, B.class));
          } 
         
        The set of qualifiers returned by AnnotatedTypeFactory.createSupportedTypeQualifiers() must be a fresh, mutable set. The methods AnnotatedTypeFactory.getBundledTypeQualifiers(Class...) must return a fresh, mutable set.
      Overrides:
      createSupportedTypeQualifiers in class AnnotatedTypeFactory
      Returns:
      the type qualifiers supported this processor, or an empty set if none
    • combineIntersectionBoundAnnotationsInHierarchy

      protected AnnotationMirror combineIntersectionBoundAnnotationsInHierarchy(AnnotationMirror existingAnnotation, AnnotationMirror newAnnotation, QualifierHierarchy qualifierHierarchy)
      Combines two conflicting bound annotations of an intersection type, in the same qualifier hierarchy, into the single annotation used to summarize that hierarchy. Called by AnnotatedTypeMirror.AnnotatedIntersectionType.summarizeBounds(): for a type variable's own intersection upper bound, after each bound has been independently defaulted, so a bound's annotation may be explicit or defaulted; for an intersection cast target, after each bound without a written qualifier got the cast operand's qualifier. Either way, this method is called only when two bounds carry different annotations in one hierarchy.

      By default the annotation of the bound encountered first, in source order, wins (first-bound-wins): the returned summary equals existingAnnotation and newAnnotation is ignored. The summary is therefore source-order dependent, but deterministic for a given compilation. It is still a sound upper bound of the intersection, because it equals one of the bounds' own annotations and the intersection is a subtype of each of its bounds.

      A checker in which every bound constrains the intersection -- for example a JSpecify-style integration -- may override this to return qualifierHierarchy.greatestLowerBoundQualifiersOnly(existingAnnotation, newAnnotation). Such a checker usually also overrides BaseTypeVisitor#checkExplicitAnnotationsOnIntersectionBounds, whose explicit.annotation.ignored warning assumes that only the first bound counts: under the greatest lower bound, no written qualifier is ignored. This method decides only how the per-hierarchy summary is computed; that summary is always written back onto every bound (homogenization). Computing it via greatestLowerBoundQualifiersOnly additionally relies on QualifierHierarchy.greatestLowerBoundQualifiers(javax.lang.model.element.AnnotationMirror, javax.lang.model.element.AnnotationMirror) being consistent with QualifierHierarchy.isSubtypeQualifiers(javax.lang.model.element.AnnotationMirror, javax.lang.model.element.AnnotationMirror) for the qualifier hierarchy in use (see that method's documentation): if a qualifier hierarchy's true subtyping relation depends on something a static declarative lattice cannot express, such as a checker option, and its computation of the greatest lower bound was not updated to match, the summary this method returns can be a qualifier the qualifier hierarchy's own subtype check would not itself have derived, producing a spurious type error where none existed before the summary was combined -- not a fault of this method or of homogenization, but of that inconsistency.

      This implementation is order-independent: it returns the greatest lower bound of the two qualifiers.

      Overrides:
      combineIntersectionBoundAnnotationsInHierarchy in class AnnotatedTypeFactory
      Parameters:
      existingAnnotation - the annotation already chosen for this hierarchy, from an earlier bound in source order
      newAnnotation - a conflicting annotation from a later bound in the same hierarchy
      qualifierHierarchy - the qualifier hierarchy that both annotations belong to
      Returns:
      the annotation to use as the intersection's summary for this hierarchy