Class LeftCurlyCheck

All Implemented Interfaces:
Configurable, Contextualizable

public class LeftCurlyCheck extends AbstractCheck
Checks for the placement of left curly braces ('{') for code blocks.

Parent is com.puppycrawl.tools.checkstyle.TreeWalker

Violation Message Keys:

  • line.break.after
  • line.new
  • line.previous
Since:
3.0
  • Field Details

  • Constructor Details

  • Method Details

    • setOption

      public void setOption(String optionStr)
      Setter to specify the policy on placement of a left curly brace ('{').
      Parameters:
      optionStr - string to decode option from
      Throws:
      IllegalArgumentException - if unable to decode
      Since:
      3.0
    • setIgnoreEnums

      public void setIgnoreEnums(boolean ignoreEnums)
      Setter to allow to ignore enums when left curly brace policy is EOL.
      Parameters:
      ignoreEnums - check's option for ignoring enums.
      Since:
      6.9
    • 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)
      Visits token.
      Overrides:
      visitToken in class AbstractCheck
      Parameters:
      ast - the token to process
    • getBraceFromSwitchMember

      @Nullable private static DetailAST getBraceFromSwitchMember(DetailAST ast)
      Gets the brace of a switch statement/ expression member.
      Parameters:
      ast - DetailAST.
      Returns:
      DetailAST if the first child is TokenTypes.SLIST, null otherwise.
    • getBraceAsFirstChild

      @Nullable private static DetailAST getBraceAsFirstChild(DetailAST ast)
      Gets a SLIST if it is the first child of the AST.
      Parameters:
      ast - DetailAST.
      Returns:
      DetailAST if the first child is TokenTypes.SLIST, null otherwise.
    • skipModifierAnnotations

      Skip all TokenTypes.ANNOTATIONs to the first non-annotation.
      Parameters:
      ast - DetailAST.
      Returns:
      DetailAST.
    • findLastAnnotation

      private static DetailAST findLastAnnotation(DetailAST modifiers)
      Find the last token of type TokenTypes.ANNOTATION under the given set of modifiers.
      Parameters:
      modifiers - DetailAST.
      Returns:
      DetailAST or null if there are no annotations.
    • verifyBrace

      private void verifyBrace(DetailAST brace, DetailAST startToken)
      Verifies that a specified left curly brace is placed correctly according to policy.
      Parameters:
      brace - token for left curly brace
      startToken - token for start of expression
    • validateEol

      private void validateEol(DetailAST brace, String braceLine)
      Validate EOL case.
      Parameters:
      brace - brace AST
      braceLine - line content
    • validateNewLinePosition

      private void validateNewLinePosition(DetailAST brace, DetailAST startToken, String braceLine)
      Validate token on new Line position.
      Parameters:
      brace - brace AST
      startToken - start Token
      braceLine - content of line with Brace
    • hasLineBreakAfter

      private boolean hasLineBreakAfter(DetailAST leftCurly)
      Checks if left curly has line break after.
      Parameters:
      leftCurly - Left curly token.
      Returns:
      True, left curly has line break after.