Class EmptyStatementCheck

All Implemented Interfaces:
Configurable, Contextualizable

public class EmptyStatementCheck extends AbstractCheck
Detects empty statements (standalone ";" semicolon). Empty statements often introduce bugs that are hard to spot
Since:
3.1
  • Field Details

  • Constructor Details

    • EmptyStatementCheck

      Creates a new EmptyStatementCheck instance.
  • 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
    • isEmptyDeclaration

      private static boolean isEmptyDeclaration(DetailAST semi)
      Checks whether a semicolon is a standalone empty declaration, i.e. it appears at the top level of a compilation unit or directly in a type body.
      Parameters:
      semi - semicolon token
      Returns:
      true if semicolon is an empty declaration
    • isEnumConstantsTerminator

      private static boolean isEnumConstantsTerminator(DetailAST semi)
      Checks whether a semicolon in a type body terminates the list of enum constants. Such a semicolon is part of the enum syntax and is not an empty declaration.
      Parameters:
      semi - semicolon token whose parent is an object block
      Returns:
      true if semicolon terminates the enum constants list