Class NullnessNoInitVisitor

    • Constructor Detail

      • NullnessNoInitVisitor

        public NullnessNoInitVisitor​(BaseTypeChecker checker)
        Create a new NullnessVisitor.
        Parameters:
        checker - the checker to which this visitor belongs
    • Method Detail

      • createTypeFactory

        public NullnessNoInitAnnotatedTypeFactory 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<NullnessNoInitAnnotatedTypeFactory>
        Returns:
        the appropriate type factory
      • checkThisOrSuperConstructorCall

        protected void checkThisOrSuperConstructorCall​(com.sun.source.tree.MethodInvocationTree superCall,
                                                       @CompilerMessageKey java.lang.String errorKey)
        Description copied from class: BaseTypeVisitor
        Checks that the following rule is satisfied: The type on a constructor declaration must be a supertype of the return type of "this()" or "super()" invocation within that constructor.
        Overrides:
        checkThisOrSuperConstructorCall in class BaseTypeVisitor<NullnessNoInitAnnotatedTypeFactory>
        Parameters:
        superCall - the AST node for the constructor call
        errorKey - the error message key to use if the check fails
      • commonAssignmentCheck

        protected boolean commonAssignmentCheck​(com.sun.source.tree.Tree varTree,
                                                com.sun.source.tree.ExpressionTree valueExp,
                                                @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<NullnessNoInitAnnotatedTypeFactory>
        Parameters:
        varTree - the AST node for 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

        protected boolean commonAssignmentCheck​(AnnotatedTypeMirror varType,
                                                com.sun.source.tree.ExpressionTree valueExp,
                                                @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<NullnessNoInitAnnotatedTypeFactory>
        Parameters:
        varType - the annotated type for 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<NullnessNoInitAnnotatedTypeFactory>
        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
      • visitMemberSelect

        public java.lang.Void visitMemberSelect​(com.sun.source.tree.MemberSelectTree tree,
                                                java.lang.Void p)
        Case 1: Check for null dereferencing.
        Specified by:
        visitMemberSelect in interface com.sun.source.tree.TreeVisitor<java.lang.Void,​java.lang.Void>
        Overrides:
        visitMemberSelect in class com.sun.source.util.TreeScanner<java.lang.Void,​java.lang.Void>
      • visitEnhancedForLoop

        public java.lang.Void visitEnhancedForLoop​(com.sun.source.tree.EnhancedForLoopTree tree,
                                                   java.lang.Void p)
        Case 2: Check for implicit .iterator call.
        Specified by:
        visitEnhancedForLoop in interface com.sun.source.tree.TreeVisitor<java.lang.Void,​java.lang.Void>
        Overrides:
        visitEnhancedForLoop in class BaseTypeVisitor<NullnessNoInitAnnotatedTypeFactory>
      • visitArrayAccess

        public java.lang.Void visitArrayAccess​(com.sun.source.tree.ArrayAccessTree tree,
                                               java.lang.Void p)
        Case 3: Check for array dereferencing.
        Specified by:
        visitArrayAccess in interface com.sun.source.tree.TreeVisitor<java.lang.Void,​java.lang.Void>
        Overrides:
        visitArrayAccess in class com.sun.source.util.TreeScanner<java.lang.Void,​java.lang.Void>
      • visitNewArray

        public java.lang.Void visitNewArray​(com.sun.source.tree.NewArrayTree tree,
                                            java.lang.Void p)
        Specified by:
        visitNewArray in interface com.sun.source.tree.TreeVisitor<java.lang.Void,​java.lang.Void>
        Overrides:
        visitNewArray in class BaseTypeVisitor<NullnessNoInitAnnotatedTypeFactory>
      • visitSynchronized

        public java.lang.Void visitSynchronized​(com.sun.source.tree.SynchronizedTree tree,
                                                java.lang.Void p)
        Case 5: Check for synchronizing locks.
        Specified by:
        visitSynchronized in interface com.sun.source.tree.TreeVisitor<java.lang.Void,​java.lang.Void>
        Overrides:
        visitSynchronized in class com.sun.source.util.TreeScanner<java.lang.Void,​java.lang.Void>
      • visitAssert

        public java.lang.Void visitAssert​(com.sun.source.tree.AssertTree tree,
                                          java.lang.Void p)
        Specified by:
        visitAssert in interface com.sun.source.tree.TreeVisitor<java.lang.Void,​java.lang.Void>
        Overrides:
        visitAssert in class com.sun.source.util.TreeScanner<java.lang.Void,​java.lang.Void>
      • visitIf

        public java.lang.Void visitIf​(com.sun.source.tree.IfTree tree,
                                      java.lang.Void p)
        Specified by:
        visitIf in interface com.sun.source.tree.TreeVisitor<java.lang.Void,​java.lang.Void>
        Overrides:
        visitIf in class com.sun.source.util.TreeScanner<java.lang.Void,​java.lang.Void>
      • visitInstanceOf

        public java.lang.Void visitInstanceOf​(com.sun.source.tree.InstanceOfTree tree,
                                              java.lang.Void p)
        Specified by:
        visitInstanceOf in interface com.sun.source.tree.TreeVisitor<java.lang.Void,​java.lang.Void>
        Overrides:
        visitInstanceOf in class BaseTypeVisitor<NullnessNoInitAnnotatedTypeFactory>
      • checkForRedundantTests

        protected void checkForRedundantTests​(com.sun.source.tree.BinaryTree tree)
        Reports an error if a comparison of a @NonNull expression with the null literal is performed.
        Parameters:
        tree - a tree that might be a comparison of a @NonNull expression with the null literal
      • visitBinary

        public java.lang.Void visitBinary​(com.sun.source.tree.BinaryTree tree,
                                          java.lang.Void p)
        Case 6: Check for redundant nullness tests Case 7: unboxing case: primitive operations.
        Specified by:
        visitBinary in interface com.sun.source.tree.TreeVisitor<java.lang.Void,​java.lang.Void>
        Overrides:
        visitBinary in class com.sun.source.util.TreeScanner<java.lang.Void,​java.lang.Void>
      • visitUnary

        public java.lang.Void visitUnary​(com.sun.source.tree.UnaryTree tree,
                                         java.lang.Void p)
        Case 7: unboxing case: primitive operation.
        Specified by:
        visitUnary in interface com.sun.source.tree.TreeVisitor<java.lang.Void,​java.lang.Void>
        Overrides:
        visitUnary in class BaseTypeVisitor<NullnessNoInitAnnotatedTypeFactory>
      • visitCompoundAssignment

        public java.lang.Void visitCompoundAssignment​(com.sun.source.tree.CompoundAssignmentTree tree,
                                                      java.lang.Void p)
        Case 7: unboxing case: primitive operation.
        Specified by:
        visitCompoundAssignment in interface com.sun.source.tree.TreeVisitor<java.lang.Void,​java.lang.Void>
        Overrides:
        visitCompoundAssignment in class BaseTypeVisitor<NullnessNoInitAnnotatedTypeFactory>
      • visitTypeCast

        public java.lang.Void visitTypeCast​(com.sun.source.tree.TypeCastTree tree,
                                            java.lang.Void p)
        Case 7: unboxing case: casting to a primitive.
        Specified by:
        visitTypeCast in interface com.sun.source.tree.TreeVisitor<java.lang.Void,​java.lang.Void>
        Overrides:
        visitTypeCast in class BaseTypeVisitor<NullnessNoInitAnnotatedTypeFactory>
      • 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<NullnessNoInitAnnotatedTypeFactory>
      • visitMethodInvocation

        public java.lang.Void visitMethodInvocation​(com.sun.source.tree.MethodInvocationTree tree,
                                                    java.lang.Void p)
        Description copied from class: BaseTypeVisitor
        Performs a method invocation check.

        An invocation of a method, m, on the receiver, r is valid only if:

        • passed arguments are subtypes of corresponding m parameters
        • r is a subtype of m receiver type
        • if m is generic, passed type arguments are subtypes of m type variables
        Specified by:
        visitMethodInvocation in interface com.sun.source.tree.TreeVisitor<java.lang.Void,​java.lang.Void>
        Overrides:
        visitMethodInvocation in class BaseTypeVisitor<NullnessNoInitAnnotatedTypeFactory>
      • checkMethodInvocability

        protected void checkMethodInvocability​(AnnotatedTypeMirror.AnnotatedExecutableType method,
                                               com.sun.source.tree.MethodInvocationTree tree)
        Description copied from class: BaseTypeVisitor
        Tests whether the method can be invoked using the receiver of the 'tree' method invocation, and issues a "method.invocation.invalid" if the invocation is invalid.

        This implementation tests whether the receiver in the method invocation is a subtype of the method receiver type. This behavior can be specialized by overriding skipReceiverSubtypeCheck.

        Overrides:
        checkMethodInvocability in class BaseTypeVisitor<NullnessNoInitAnnotatedTypeFactory>
        Parameters:
        method - the type of the invoked method
        tree - the method invocation tree
      • visitSwitch

        public java.lang.Void visitSwitch​(com.sun.source.tree.SwitchTree tree,
                                          java.lang.Void p)
        Specified by:
        visitSwitch in interface com.sun.source.tree.TreeVisitor<java.lang.Void,​java.lang.Void>
        Overrides:
        visitSwitch in class com.sun.source.util.TreeScanner<java.lang.Void,​java.lang.Void>
      • visitForLoop

        public java.lang.Void visitForLoop​(com.sun.source.tree.ForLoopTree tree,
                                           java.lang.Void p)
        Specified by:
        visitForLoop in interface com.sun.source.tree.TreeVisitor<java.lang.Void,​java.lang.Void>
        Overrides:
        visitForLoop in class com.sun.source.util.TreeScanner<java.lang.Void,​java.lang.Void>
      • visitNewClass

        public java.lang.Void visitNewClass​(com.sun.source.tree.NewClassTree tree,
                                            java.lang.Void p)
        Description copied from class: BaseTypeVisitor
        Performs a new class invocation check.

        An invocation of a constructor, c, is valid only if:

        • passed arguments are subtypes of corresponding c parameters
        • if c is generic, passed type arguments are subtypes of c type variables
        Specified by:
        visitNewClass in interface com.sun.source.tree.TreeVisitor<java.lang.Void,​java.lang.Void>
        Overrides:
        visitNewClass in class BaseTypeVisitor<NullnessNoInitAnnotatedTypeFactory>
      • visitWhileLoop

        public java.lang.Void visitWhileLoop​(com.sun.source.tree.WhileLoopTree tree,
                                             java.lang.Void p)
        Specified by:
        visitWhileLoop in interface com.sun.source.tree.TreeVisitor<java.lang.Void,​java.lang.Void>
        Overrides:
        visitWhileLoop in class com.sun.source.util.TreeScanner<java.lang.Void,​java.lang.Void>
      • visitDoWhileLoop

        public java.lang.Void visitDoWhileLoop​(com.sun.source.tree.DoWhileLoopTree tree,
                                               java.lang.Void p)
        Specified by:
        visitDoWhileLoop in interface com.sun.source.tree.TreeVisitor<java.lang.Void,​java.lang.Void>
        Overrides:
        visitDoWhileLoop in class com.sun.source.util.TreeScanner<java.lang.Void,​java.lang.Void>
      • visitConditionalExpression

        public java.lang.Void visitConditionalExpression​(com.sun.source.tree.ConditionalExpressionTree tree,
                                                         java.lang.Void p)
        Description copied from class: BaseTypeVisitor
        If the computation of the type of the ConditionalExpressionTree in org.checkerframework.framework.type.TypeFromTree.TypeFromExpression.visitConditionalExpression(ConditionalExpressionTree, AnnotatedTypeFactory) is correct, the following checks are redundant. However, let's add another failsafe guard and do the checks.
        Specified by:
        visitConditionalExpression in interface com.sun.source.tree.TreeVisitor<java.lang.Void,​java.lang.Void>
        Overrides:
        visitConditionalExpression in class BaseTypeVisitor<NullnessNoInitAnnotatedTypeFactory>
      • visitAnnotation

        public java.lang.Void visitAnnotation​(com.sun.source.tree.AnnotationTree tree,
                                              java.lang.Void p)
        Description copied from class: BaseTypeVisitor
        Ensure that the annotation arguments comply to their declarations. This needs some special casing, as annotation arguments form special trees.
        Specified by:
        visitAnnotation in interface com.sun.source.tree.TreeVisitor<java.lang.Void,​java.lang.Void>
        Overrides:
        visitAnnotation in class BaseTypeVisitor<NullnessNoInitAnnotatedTypeFactory>