Class OpenjdkMethodThrowsAlignmentCheck

All Implemented Interfaces:
Configurable, Contextualizable

Checks that the throws clause of a wrapped method or constructor declaration is properly aligned according to the OpenJDK Java Style Guide.

This check only applies when the method or constructor declaration is wrapped, that is, the parameter list spans more than one line. Single-line declarations are not in scope.

The two rules enforced are:

  1. The throws keyword must start on a new line, it must not share the line with the closing ) of the parameter list.
  2. The throws keyword must stand out from the parameter list by being indented 8 columns relative to either:
    • the column of the method/constructor declaration (i.e. the indentation of the line containing the declaration keyword)
    • the indentation (first non-whitespace column) of the source line immediately above the line where throws appears
Since:
14.2.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
    • getIndentOfLine

      private int getIndentOfLine(int lineNo)
      Returns the indentation (column of the first non-whitespace character) of the given 1-indexed source line number.
      Parameters:
      lineNo - 1-indexed line number of the source line to inspect.
      Returns:
      0-indexed column of the first non-whitespace character on that line, or the full line length if the line is blank.