Class LowerBoundAnnotatedTypeFactory

  • All Implemented Interfaces:
    AnnotationProvider

    public class LowerBoundAnnotatedTypeFactory
    extends BaseAnnotatedTypeFactoryForIndexChecker
    Implements the introduction rules for the Lower Bound Checker.
      The type hierarchy is:
    
      Top = lbu ("Lower Bound Unknown")
       |
      gte-1 ("Greater than or equal to -1")
       |
      nn  ("NonNegative")
       |
      pos ("Positive")
      
    In general, check whether the constant Value Checker can determine the value of a variable; if it can, use that; if not, use more specific rules based on expression type. This class implements the following type rules:
    • 1. If the value checker type for any expression is ≥ 1, refine that expression's type to positive.
    • 2. If the value checker type for any expression is ≥ 0 and case 1 did not apply, then refine that expression's type to non-negative.
    • 3. If the value checker type for any expression is ≥ -1 and cases 1 and 2 did not apply, then refine that expression's type to GTEN1.
    • 4. A unary prefix decrement shifts the type "down" in the hierarchy (i.e. --i when i is non-negative implies that i will be GTEN1 afterwards). Should this be 3 rules?
    • 5. A unary prefix increment shifts the type "up" in the hierarchy (i.e. ++i when i is non-negative implies that i will be positive afterwards). Should this be 3 rules?
    • 6. Unary negation on a NegativeIndexFor from the SearchIndex type system results in a non-negative.
    • 7. The result of a call to Math.max is the GLB of its arguments.
    • 8. If an array has a MinLen type ≥ 1 and its length is accessed, the length expression is positive.
    • Field Detail

      • GTEN1

        public final javax.lang.model.element.AnnotationMirror GTEN1
        The canonical @GTENegativeOne annotation.
      • NN

        public final javax.lang.model.element.AnnotationMirror NN
        The canonical @NonNegative annotation.
      • POS

        public final javax.lang.model.element.AnnotationMirror POS
        The canonical @Positive annotation.
      • BOTTOM

        public final javax.lang.model.element.AnnotationMirror BOTTOM
        The bottom annotation.
      • UNKNOWN

        public final javax.lang.model.element.AnnotationMirror UNKNOWN
        The canonical @LowerBoundUnknown annotation.
      • POLY

        public final javax.lang.model.element.AnnotationMirror POLY
        The canonical @PolyLowerBound annotation.
    • Constructor Detail

      • LowerBoundAnnotatedTypeFactory

        public LowerBoundAnnotatedTypeFactory​(BaseTypeChecker checker)
        Create a new LowerBoundAnnotatedTypeFactory.
        Parameters:
        checker - the type-checker
    • Method Detail

      • createSupportedTypeQualifiers

        protected java.util.Set<java.lang.Class<? extends java.lang.annotation.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 5 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(Regex.class, PartialRegex.class, RegexBottom.class, UnknownRegex.class);
            } 
           
        3. Supporting only annotations that are explicitly listed: 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
      • getValueAnnotatedTypeFactory

        public ValueAnnotatedTypeFactory getValueAnnotatedTypeFactory()
        Returns the Value Checker's annotated type factory.
      • getSearchIndexAnnotatedTypeFactory

        public SearchIndexAnnotatedTypeFactory getSearchIndexAnnotatedTypeFactory()
        Returns the SearchIndexFor Checker's annotated type factory.
      • getLessThanAnnotatedTypeFactory

        public LessThanAnnotatedTypeFactory getLessThanAnnotatedTypeFactory()
        Returns the LessThan Checker's annotated type factory.
      • isNonNegative

        public boolean isNonNegative​(com.sun.source.tree.Tree tree)
        Checks if the expression is non-negative, i.e. it has Positive on NonNegative annotation.