Class MissingOverrideOnRecordAccessorCheck

All Implemented Interfaces:
Configurable, Contextualizable

Verifies that explicitly declared record accessor methods include the @Override annotation.

Per JEP 395, the meaning of the @Override annotation was extended to include explicitly declared accessor methods for record components.

This check focuses only on record component accessor methods. It does not attempt to detect general method overrides from interfaces or superclasses, due to Checkstyle's single-file analysis limitations.

Since:
13.1.0
  • Field Details

  • Constructor Details

  • Method Details

    • getDefaultTokens

      public int[] getDefaultTokens()
      Description copied from class: AbstractCheck
      Returns the default token a check is interested in. Only used if the configuration for a check does not define the tokens.
      Specified by:
      getDefaultTokens in class AbstractCheck
      Returns:
      the default tokens
      See Also:
    • getAcceptableTokens

      public int[] getAcceptableTokens()
      Description copied from class: AbstractCheck
      The configurable token set. Used to protect Checks against malicious users who specify an unacceptable token set in the configuration file. The default implementation returns the check's default tokens.
      Specified by:
      getAcceptableTokens in class AbstractCheck
      Returns:
      the token set this check is designed for.
      See Also:
    • getRequiredTokens

      public int[] getRequiredTokens()
      Description copied from class: AbstractCheck
      The tokens that this check must be registered for.
      Specified by:
      getRequiredTokens in class AbstractCheck
      Returns:
      the token set this must be registered for.
      See Also:
    • visitToken

      public void visitToken(DetailAST ast)
      Description copied from class: AbstractCheck
      Called to process a token.
      Overrides:
      visitToken in class AbstractCheck
      Parameters:
      ast - the token to process
    • isRecordAccessorMethod

      private static boolean isRecordAccessorMethod(DetailAST ast)
      Checks if the given method is an explicitly declared accessor for a record component.
      Parameters:
      ast - the METHOD_DEF AST node
      Returns:
      true if this method is a record accessor
    • getRecordComponentNames

      private static Set<String> getRecordComponentNames(DetailAST recordDef)
      Gets the set of record component names from a record definition.
      Parameters:
      recordDef - the RECORD_DEF AST node
      Returns:
      set of component names