Class TypeBodyPaddingCheck

All Implemented Interfaces:
Configurable, Contextualizable

public class TypeBodyPaddingCheck extends AbstractCheck
Checks the padding of the body of type definitions (classes, interfaces, enums, records). That is, whether a blank line is required immediately after the opening brace and/or immediately before the closing brace of type bodies. Empty type bodies are exempt from this check by default.

A blank line (padding) line is a line containing only whitespace characters.

Since:
13.9.0
  • Field Details

    • MSG_AFTER_LCURLY

      public static final String MSG_AFTER_LCURLY
      A key pointing to the warning message text in "messages.properties" file. Emitted when a blank line is missing after the opening brace of a type body.
      See Also:
    • MSG_BEFORE_RCURLY

      public static final String MSG_BEFORE_RCURLY
      A key pointing to the warning message text in "messages.properties" file. Emitted when a blank line is missing before the closing brace of a type body.
      See Also:
    • atStartOfBody

      private boolean atStartOfBody
      Require a blank line after the type body opening brace.
    • atEndOfBody

      private boolean atEndOfBody
      Require a blank line before the type body closing brace.
    • allowEmpty

      private boolean allowEmpty
      Allow empty type bodies (those with no members) to omit blank line padding.
    • skipInner

      private boolean skipInner
      Whether to skip inner types.
    • skipLocal

      private boolean skipLocal
      Whether to skip local types (types defined inside methods or constructors).
  • Constructor Details

  • Method Details

    • setAtStartOfBody

      public void setAtStartOfBody(boolean atStartOfBody)
      Setter to require a blank line after the type body opening brace.
      Parameters:
      atStartOfBody - the value to set.
      Since:
      13.9.0
    • setAtEndOfBody

      public void setAtEndOfBody(boolean atEndOfBody)
      Setter to require a blank line before the type body closing brace.
      Parameters:
      atEndOfBody - the value to set.
      Since:
      13.9.0
    • setAllowEmpty

      public void setAllowEmpty(boolean allowEmpty)
      Setter to allow empty type bodies to omit blank line padding.
      Parameters:
      allowEmpty - the value to set.
      Since:
      13.9.0
    • setSkipInner

      public void setSkipInner(boolean skipInner)
      Setter to control whether to skip checking of inner types.
      Parameters:
      skipInner - false to also check inner types.
      Since:
      13.9.0
    • setSkipLocal

      public void setSkipLocal(boolean skipLocal)
      Setter to control whether to skip checking of local types.
      Parameters:
      skipLocal - false to also check local types.
      Since:
      13.9.0
    • 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
    • requirePaddingAfterLcurly

      private boolean requirePaddingAfterLcurly(DetailAST lcurly, DetailAST rcurly)
      Checks if padding is required after the left curly brace.
      Parameters:
      lcurly - the left curly brace.
      rcurly - the right curly brace.
      Returns:
      true if padding is required.
    • requirePaddingBeforeRcurly

      private boolean requirePaddingBeforeRcurly(DetailAST lcurly, DetailAST rcurly)
      Checks if padding is required before the right curly brace.
      Parameters:
      lcurly - the left curly brace.
      rcurly - the right curly brace.
      Returns:
      true if padding is required.
    • haveBlankLineAfterLeftCurly

      private boolean haveBlankLineAfterLeftCurly(DetailAST lcurly)
      Checks that a blank line exists after the opening brace of the type body. The line immediately following the LCURLY line must be blank (contain only whitespace).
      Parameters:
      lcurly - the LCURLY token.
      Returns:
      true if there is a blank line after the opening brace.
    • haveBlankLineBeforeRightCurly

      private boolean haveBlankLineBeforeRightCurly(DetailAST rcurly)
      Checks that a blank line exists before the closing brace of the type body. The line immediately preceding the RCURLY line must be blank.
      Parameters:
      rcurly - the RCURLY token.
      Returns:
      true if there is a blank line before the closing brace.
    • shouldSkipType

      private boolean shouldSkipType(DetailAST ast, boolean isEmpty)
      Determines whether to skip checking the given AST node.
      Parameters:
      ast - the AST node to check
      isEmpty - whether the type body is empty
      Returns:
      true if the node should be skipped, false otherwise