Class SignednessVisitor

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

    public class SignednessVisitor
    extends BaseTypeVisitor<SignednessAnnotatedTypeFactory>
    The SignednessVisitor enforces the Signedness Checker rules. These rules are described in the Checker Framework Manual.
    See the Checker Framework Manual:
    Signedness Checker
    • Constructor Detail

    • Method Detail

      • visitBinary

        public java.lang.Void visitBinary​(com.sun.source.tree.BinaryTree tree,
                                          java.lang.Void p)
        Enforces the following rules on binary operations involving Unsigned and Signed types:
        • Do not allow any Unsigned types or PolySigned types in {/, %} operations.
        • Do not allow signed right shift {>>} on an Unsigned type or a PolySigned type.
        • Do not allow unsigned right shift {>>>} on a Signed type or a PolySigned type.
        • Allow any left shift {<<}.
        • Do not allow non-equality comparisons {<, <=, >, >=} on Unsigned types or PolySigned types.
        • Do not allow the mixing of Signed and Unsigned types.
        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>
      • 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<SignednessAnnotatedTypeFactory>
      • 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<SignednessAnnotatedTypeFactory>
      • visitCompoundAssignment

        public java.lang.Void visitCompoundAssignment​(com.sun.source.tree.CompoundAssignmentTree tree,
                                                      java.lang.Void p)
        Enforces the following rules on compound assignments involving Unsigned and Signed types:
        • Do not allow any Unsigned types or PolySigned types in {/=, %=} assignments.
        • Do not allow signed right shift {>>=} to assign to an Unsigned type or a PolySigned type.
        • Do not allow unsigned right shift {>>>=} to assign to a Signed type or a PolySigned type.
        • Allow any left shift {<<=} assignment.
        • Do not allow mixing of Signed and Unsigned types.
        Specified by:
        visitCompoundAssignment in interface com.sun.source.tree.TreeVisitor<java.lang.Void,​java.lang.Void>
        Overrides:
        visitCompoundAssignment in class BaseTypeVisitor<SignednessAnnotatedTypeFactory>