Class BaseTypeVisitor.OverrideChecker

java.lang.Object
org.checkerframework.common.basetype.BaseTypeVisitor.OverrideChecker
Direct Known Subclasses:
GuiEffectVisitor.GuiEffectOverrideChecker
Enclosing class:
BaseTypeVisitor<Factory extends GenericAnnotatedTypeFactory<?,?,?,?>>

public class BaseTypeVisitor.OverrideChecker extends Object
Class to perform method override and method reference checks.

Method references are checked similarly to method overrides, with the method reference viewed as overriding the functional interface's method.

Checks that an overriding method's return type, parameter types, and receiver type are correct with respect to the annotations on the overridden method's return type, parameter types, and receiver type.

Furthermore, any contracts on the method must satisfy behavioral subtyping, that is, postconditions must be at least as strong as the postcondition on the superclass, and preconditions must be at most as strong as the condition on the superclass.

This method returns the result of the check, but also emits error messages as a side effect.

  • Field Details

  • Constructor Details

    • OverrideChecker

      public OverrideChecker(Tree overriderTree, AnnotatedTypeMirror.AnnotatedExecutableType overrider, AnnotatedTypeMirror overriderType, AnnotatedTypeMirror overriderReturnType, AnnotatedTypeMirror.AnnotatedExecutableType overridden, AnnotatedTypeMirror.AnnotatedDeclaredType overriddenType, AnnotatedTypeMirror overriddenReturnType)
      Create an OverrideChecker.

      Notice that the return types are passed in separately. This is to support some types of method references where the overrider's return type is not the appropriate type to check.

      Parameters:
      overriderTree - the AST node of the overriding method or method reference
      overrider - the type of the overriding method
      overriderType - the type enclosing the overrider method, usually an AnnotatedDeclaredType; for Method References may be something else
      overriderReturnType - the return type of the overriding method
      overridden - the type of the overridden method
      overriddenType - the declared type enclosing the overridden method
      overriddenReturnType - the return type of the overridden method
  • Method Details

    • checkOverride

      public boolean checkOverride()
      Perform the check.
      Returns:
      true if the override is allowed
    • checkReceiverOverride

      protected boolean checkReceiverOverride()
      Issue an "override.receiver" error if the receiver override is not valid.
      Returns:
      true if the override is legal