Class ValueVisitor

  • All Implemented Interfaces:
    com.sun.source.tree.TreeVisitor<java.lang.Void,​java.lang.Void>

    public class ValueVisitor
    extends BaseTypeVisitor<ValueAnnotatedTypeFactory>
    Visitor for the Constant Value type system.
    • Method Detail

      • commonAssignmentCheck

        protected boolean commonAssignmentCheck​(AnnotatedTypeMirror varType,
                                                com.sun.source.tree.ExpressionTree valueExp,
                                                @CompilerMessageKey java.lang.String errorKey,
                                                java.lang.Object... extraArgs)
        ValueVisitor overrides this method so that it does not have to check variables annotated with the IntRangeFromPositive annotation, the IntRangeFromNonNegative annotation, or the IntRangeFromGTENegativeOne annotation. This annotation is only introduced by the Index Checker's lower bound annotations. It is safe to defer checking of these values to the Index Checker because this is only introduced for explicitly-written org.checkerframework.checker.index.qual.Positive, explicitly-written org.checkerframework.checker.index.qual.NonNegative, and explicitly-written org.checkerframework.checker.index.qual.GTENegativeOne annotations, which must be checked by the Lower Bound Checker.
        Overrides:
        commonAssignmentCheck in class BaseTypeVisitor<ValueAnnotatedTypeFactory>
        Parameters:
        varType - the annotated type of the lvalue (usually a variable)
        valueExp - the AST node for the rvalue (the new value)
        errorKey - the error message key to use if the check fails
        extraArgs - arguments to the error message key, before "found" and "expected" types
        Returns:
        true if the check succeeds, false if an error message was issued
      • commonAssignmentCheck

        @FormatMethod
        protected boolean commonAssignmentCheck​(AnnotatedTypeMirror varType,
                                                AnnotatedTypeMirror valueType,
                                                com.sun.source.tree.Tree valueTree,
                                                @CompilerMessageKey java.lang.String errorKey,
                                                java.lang.Object... extraArgs)
        Description copied from class: BaseTypeVisitor
        Checks the validity of an assignment (or pseudo-assignment) from a value to a variable and emits an error message (through the compiler's messaging interface) if it is not valid.
        Overrides:
        commonAssignmentCheck in class BaseTypeVisitor<ValueAnnotatedTypeFactory>
        Parameters:
        varType - the annotated type of the variable
        valueType - the annotated type of the value
        valueTree - the location to use when reporting the error message
        errorKey - the error message key to use if the check fails
        extraArgs - arguments to the error message key, before "found" and "expected" types
        Returns:
        true if the check succeeds, false if an error message was issued
      • createTypeFactory

        protected ValueAnnotatedTypeFactory createTypeFactory()
        Description copied from class: BaseTypeVisitor
        Constructs an instance of the appropriate type factory for the implemented type system.

        The default implementation uses the checker naming convention to create the appropriate type factory. If no factory is found, it returns BaseAnnotatedTypeFactory. It reflectively invokes the constructor that accepts this checker and compilation unit tree (in that order) as arguments.

        Subclasses have to override this method to create the appropriate visitor if they do not follow the checker naming convention.

        Overrides:
        createTypeFactory in class BaseTypeVisitor<ValueAnnotatedTypeFactory>
        Returns:
        the appropriate type factory
      • visitAnnotation

        public java.lang.Void visitAnnotation​(com.sun.source.tree.AnnotationTree tree,
                                              java.lang.Void p)
        Warns about malformed constant-value annotations.

        Issues an error if any @IntRange annotation has its 'from' value greater than 'to' value.

        Issues an error if any constant-value annotation has no arguments.

        Issues a warning if any constant-value annotation has > MAX_VALUES arguments.

        Issues a warning if any @ArrayLen/@ArrayLenRange annotations contain a negative array length.

        Issues a warning if any @MatchesRegex or @DoesNotMatchRegex annotation contains an invalid regular expression.

        Specified by:
        visitAnnotation in interface com.sun.source.tree.TreeVisitor<java.lang.Void,​java.lang.Void>
        Overrides:
        visitAnnotation in class BaseTypeVisitor<ValueAnnotatedTypeFactory>
      • visitTypeCast

        public java.lang.Void visitTypeCast​(com.sun.source.tree.TypeCastTree tree,
                                            java.lang.Void p)
        Specified by:
        visitTypeCast in interface com.sun.source.tree.TreeVisitor<java.lang.Void,​java.lang.Void>
        Overrides:
        visitTypeCast in class BaseTypeVisitor<ValueAnnotatedTypeFactory>
      • isTypeCastSafe

        protected boolean isTypeCastSafe​(AnnotatedTypeMirror castType,
                                         AnnotatedTypeMirror exprType)
        Description copied from class: BaseTypeVisitor
        Returns true if the cast is safe.

        Only primary qualifiers are checked unless the command line option "checkCastElementType" is supplied.

        Overrides:
        isTypeCastSafe in class BaseTypeVisitor<ValueAnnotatedTypeFactory>
        Parameters:
        castType - annotated type of the cast
        exprType - annotated type of the casted expression
        Returns:
        true if the type cast is safe, false otherwise
      • visitMethod

        public java.lang.Void visitMethod​(com.sun.source.tree.MethodTree tree,
                                          java.lang.Void p)
        Description copied from class: BaseTypeVisitor
        Checks that the method obeys override and subtype rules to all overridden methods. (Uses the pseudo-assignment logic to do so.)

        The override rule specifies that a method, m1, may override a method m2 only if:

        • m1 return type is a subtype of m2
        • m1 receiver type is a supertype of m2
        • m1 parameters are supertypes of corresponding m2 parameters
        Also, it issues a "missing.this" error for static method annotated receivers.
        Specified by:
        visitMethod in interface com.sun.source.tree.TreeVisitor<java.lang.Void,​java.lang.Void>
        Overrides:
        visitMethod in class BaseTypeVisitor<ValueAnnotatedTypeFactory>