Class SignednessVisitor

java.lang.Object
com.sun.source.util.TreeScanner<R,P>
com.sun.source.util.TreePathScanner<R,P>
All Implemented Interfaces:
com.sun.source.tree.TreeVisitor<Void,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 Details

  • Method Details

    • visitBinary

      public Void visitBinary(com.sun.source.tree.BinaryTree node, 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<Void,Void>
      Overrides:
      visitBinary in class com.sun.source.util.TreeScanner<Void,Void>
    • visitMethod

      public Void visitMethod(com.sun.source.tree.MethodTree node, 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<Void,Void>
      Overrides:
      visitMethod in class BaseTypeVisitor<SignednessAnnotatedTypeFactory>
    • visitMethodInvocation

      public Void visitMethodInvocation(com.sun.source.tree.MethodInvocationTree node, 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<Void,Void>
      Overrides:
      visitMethodInvocation in class BaseTypeVisitor<SignednessAnnotatedTypeFactory>
    • visitCompoundAssignment

      public Void visitCompoundAssignment(com.sun.source.tree.CompoundAssignmentTree node, 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<Void,Void>
      Overrides:
      visitCompoundAssignment in class BaseTypeVisitor<SignednessAnnotatedTypeFactory>
    • 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<SignednessAnnotatedTypeFactory>
      Parameters:
      castType - annotated type of the cast
      exprType - annotated type of the casted expression
      Returns:
      true if the type cast is safe, false otherwise
    • getExceptionParameterLowerBoundAnnotations

      protected Set<? extends AnnotationMirror> getExceptionParameterLowerBoundAnnotations()
      Description copied from class: BaseTypeVisitor
      Returns a set of AnnotationMirrors that is a lower bound for exception parameters.

      This implementation returns top; subclasses can change this behavior.

      Note: by default this method is called by BaseTypeVisitor.getThrowUpperBoundAnnotations(), so that this annotation is enforced.

      Overrides:
      getExceptionParameterLowerBoundAnnotations in class BaseTypeVisitor<SignednessAnnotatedTypeFactory>
      Returns:
      set of annotation mirrors, one per hierarchy, that form a lower bound of annotations that can be written on an exception parameter
    • checkConstructorResult

      protected void checkConstructorResult(AnnotatedTypeMirror.AnnotatedExecutableType constructorType, ExecutableElement constructorElement)
      Description copied from class: BaseTypeVisitor
      Issue a warning if the result type of the constructor is not top. If it is a supertype of the class, then a conflicting.annos error will also be issued by BaseTypeVisitor.isValidUse(AnnotatedTypeMirror.AnnotatedDeclaredType,AnnotatedTypeMirror.AnnotatedDeclaredType,Tree).
      Overrides:
      checkConstructorResult in class BaseTypeVisitor<SignednessAnnotatedTypeFactory>
      Parameters:
      constructorType - AnnotatedExecutableType for the constructor
      constructorElement - element that declares the constructor
    • shouldWarnAboutIrrelevantJavaTypes

      protected boolean shouldWarnAboutIrrelevantJavaTypes()
      Description copied from class: BaseTypeVisitor
      Returns true if the checker should issue warnings about irrelevant java types.
      Overrides:
      shouldWarnAboutIrrelevantJavaTypes in class BaseTypeVisitor<SignednessAnnotatedTypeFactory>
      Returns:
      true if the checker should issue warnings about irrelevant java types