Class TextBlockGoogleStyleFormattingCheck

All Implemented Interfaces:
Configurable, Contextualizable

Checks correct format of Java Text Blocks as specified in Google Java Style Guide.
This Check performs two validations:
  1. It ensures that the opening and closing text-block quotes (""") each appear on their own line, with no other item preceding them.
  2. Opening and closing quotes are vertically aligned.
Note: Closing quotes can be followed by additional code on the same line.
Since:
12.3.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
    • quotesAreVerticallyAligned

      private static boolean quotesAreVerticallyAligned(DetailAST openQuotes, DetailAST closeQuotes)
      Checks if opening and closing quotes are vertically aligned.
      Parameters:
      openQuotes - the ast to check.
      closeQuotes - the ast to check.
      Returns:
      true if both quotes have same indentation else false.
    • getClosingQuotes

      private static DetailAST getClosingQuotes(DetailAST ast)
      Gets the TEXT_BLOCK_LITERAL_END of a TEXT_BLOCK_LITERAL_BEGIN.
      Parameters:
      ast - the ast to check
      Returns:
      DetailAST TEXT_BLOCK_LITERAL_END
    • openingQuotesAreAloneOnTheLine

      private static boolean openingQuotesAreAloneOnTheLine(DetailAST openingQuotes)
      Determines if the Opening quotes of text block are not preceded by any code.
      Parameters:
      openingQuotes - opening quotes
      Returns:
      true if the opening quotes are on the new line.
    • quotesArePrecededWithComma

      private static boolean quotesArePrecededWithComma(DetailAST openingQuotes)
      Determines if opening quotes are preceded by ,.
      Parameters:
      openingQuotes - the quotes
      Returns:
      true if , is present before opening quotes.
    • closingQuotesAreAloneOnTheLine

      private static boolean closingQuotesAreAloneOnTheLine(DetailAST closingQuotes)
      Determines if the Closing quotes of text block are not preceded by any code.
      Parameters:
      closingQuotes - closing quotes
      Returns:
      true if the closing quotes are on the new line.