Class GrowAnnotatedTypeFactory

All Implemented Interfaces:
AnnotationProvider

public class GrowAnnotatedTypeFactory extends ModifiabilityBaseAnnotatedTypeFactory
The annotated type factory for the GrowChecker.
  • Constructor Details

    • GrowAnnotatedTypeFactory

      public GrowAnnotatedTypeFactory(BaseTypeChecker checker)
      Creates a GrowAnnotatedTypeFactory.
      Parameters:
      checker - the associated type-checker
  • Method Details

    • topAnnotation

      protected AnnotationMirror topAnnotation()
      Description copied from class: ModifiabilityBaseAnnotatedTypeFactory
      Returns the top qualifier of this checker's hierarchy, such as @MaybeGrowable.
      Specified by:
      topAnnotation in class ModifiabilityBaseAnnotatedTypeFactory
      Returns:
      the top qualifier of this checker's hierarchy
    • positiveCapability

      protected AnnotationMirror positiveCapability()
      Description copied from class: ModifiabilityBaseAnnotatedTypeFactory
      Returns the positive capability qualifier, such as @Growable.
      Specified by:
      positiveCapability in class ModifiabilityBaseAnnotatedTypeFactory
      Returns:
      the positive capability qualifier
    • negativeCapability

      protected AnnotationMirror negativeCapability()
      Description copied from class: ModifiabilityBaseAnnotatedTypeFactory
      Returns the negative capability qualifier, such as @Ungrowable. Only call this method if ModifiabilityBaseAnnotatedTypeFactory.hasNegativeCapability() returns true.
      Specified by:
      negativeCapability in class ModifiabilityBaseAnnotatedTypeFactory
      Returns:
      the negative capability qualifier
    • polyCapability

      protected AnnotationMirror polyCapability()
      Description copied from class: ModifiabilityBaseAnnotatedTypeFactory
      Returns the polymorphic capability qualifier, such as @PolyGrowable.
      Specified by:
      polyCapability in class ModifiabilityBaseAnnotatedTypeFactory
      Returns:
      the polymorphic capability qualifier
    • 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
    • typeLacksCapability

      protected boolean typeLacksCapability(TypeMirror type)
      Map.Entry and a non-ListIterator Iterator have no grow methods, so @Modifiable and @Unmodifiable make no claim about them.
      Overrides:
      typeLacksCapability in class ModifiabilityBaseAnnotatedTypeFactory
      Parameters:
      type - the type on which an alias was written; it is an upper bound, so it is never a type variable or a wildcard, and ModifiabilityBaseAnnotatedTypeFactory.lacksCapability(javax.lang.model.type.TypeMirror, java.util.function.Predicate<javax.lang.model.type.TypeMirror>) has already decomposed intersection types, so it is never an intersection type either
      Returns:
      true if type structurally cannot support this checker's capability
    • typesWithCapability

      protected List<TypeMirror> typesWithCapability()
      Description copied from class: ModifiabilityBaseAnnotatedTypeFactory
      Returns erased types whose every subtype has this checker's capability, unless ModifiabilityBaseAnnotatedTypeFactory.typeLacksCapability(javax.lang.model.type.TypeMirror) holds of the subtype. For example, the Replace Checker's result includes List.

      A type variable or wildcard may be instantiated by any subtype of its upper bound, including a subtype that also implements an unrelated interface. For example, a type variable whose upper bound is AbstractCollection or Serializable may be instantiated by HashSet, which cannot be replaced into. So an alias written on a type variable claims this checker's capability only if the upper bound is a subtype of one of these types.

      Specified by:
      typesWithCapability in class ModifiabilityBaseAnnotatedTypeFactory
      Returns:
      erased types whose subtypes have this checker's capability
    • polyLacksCapability

      protected boolean polyLacksCapability(TypeMirror type)
      For Map.Entry, only the replace bit is meaningful to carry from the map receiver, so the grow bit of @PolyModifiable is @MaybeGrowable.
      Overrides:
      polyLacksCapability in class ModifiabilityBaseAnnotatedTypeFactory
      Parameters:
      type - the type on which @PolyModifiable was written; it is an upper bound, so it is never a type variable or a wildcard, and ModifiabilityBaseAnnotatedTypeFactory.lacksCapability(javax.lang.model.type.TypeMirror, java.util.function.Predicate<javax.lang.model.type.TypeMirror>) has already decomposed intersection types, so it is never an intersection type either
      Returns:
      true if @PolyModifiable weakens to the top qualifier on type
    • refinedIteratorResultBound

      protected @Nullable TypeMirror refinedIteratorResultBound()
      Description copied from class: ModifiabilityBaseAnnotatedTypeFactory
      Returns the erased type that the result of an iterator method must be a subtype of for this checker to refine the result, or null if this checker does not refine iterator results. The Shrink Checker refines the result of iterator() and listIterator(); the Grow and Replace Checkers refine only the result of listIterator(), because a plain Iterator can neither grow nor replace.
      Overrides:
      refinedIteratorResultBound in class ModifiabilityBaseAnnotatedTypeFactory
      Returns:
      the erased upper bound of the iterator results this checker refines, or null