Class SwitchHandler


public class SwitchHandler extends BlockParentHandler
Handler for switch statements.
  • Field Details

    • LINE_WRAPPING_INDENT_TRIGGERS

      private static final int[] LINE_WRAPPING_INDENT_TRIGGERS
      Token types that, when appearing as a parent or grandparent of the current switch expression, indicate that the expression is likely line-wrapped and should be indented.
  • Constructor Details

    • SwitchHandler

      public SwitchHandler(IndentationCheck indentCheck, DetailAST ast, AbstractExpressionHandler parent)
      Construct an instance of this handler with the given indentation check, abstract syntax tree, and parent handler.
      Parameters:
      indentCheck - the indentation check
      ast - the abstract syntax tree
      parent - the parent handler
  • Method Details

    • getLeftCurly

      protected DetailAST getLeftCurly()
      Description copied from class: BlockParentHandler
      Get the left curly brace portion of the expression we are handling.
      Overrides:
      getLeftCurly in class BlockParentHandler
      Returns:
      the left curly brace expression
    • getRightCurly

      protected DetailAST getRightCurly()
      Description copied from class: BlockParentHandler
      Get the right curly brace portion of the expression we are handling.
      Overrides:
      getRightCurly in class BlockParentHandler
      Returns:
      the right curly brace expression
    • getListChild

      protected DetailAST getListChild()
      Description copied from class: BlockParentHandler
      Get the child element representing the list of statements.
      Overrides:
      getListChild in class BlockParentHandler
      Returns:
      the statement list child
    • getNonListChild

      protected DetailAST getNonListChild()
      Description copied from class: BlockParentHandler
      Get the child element that is not a list of statements.
      Overrides:
      getNonListChild in class BlockParentHandler
      Returns:
      the non-list child element
    • checkSwitchExpr

      private void checkSwitchExpr()
      Check the indentation of the switch expression.
    • getIndentImpl

      protected IndentLevel getIndentImpl()
      Description copied from class: AbstractExpressionHandler
      Compute the indentation amount for this handler.
      Overrides:
      getIndentImpl in class AbstractExpressionHandler
      Returns:
      the expected indentation amount
    • shouldIndentDueToWrapping

      private boolean shouldIndentDueToWrapping(DetailAST directParent, DetailAST grandParent)
      Determines if indentation is needed due to line wrapping caused by intermediate nodes between the current AST node and its enclosing handler node.
      Parameters:
      directParent - The immediate parent node of the current AST node
      grandParent - The grandparent node of the current AST node
      Returns:
      true if either the direct parent or grandparent requires additional indentation, but only when they are not the enclosing handler node itself
    • isWrappingTrigger

      private static boolean isWrappingTrigger(DetailAST astNode)
      Checks if the given AST node represents a construct that typically causes line wrapping and therefore requires additional indentation level.
      Parameters:
      astNode - The AST node to check
      Returns:
      true if the node type matches one of the line-wrapping triggers (e.g., assignments, switch rules, lambdas)
    • checkIndentation

      public void checkIndentation()
      Description copied from class: AbstractExpressionHandler
      Check the indentation of the expression we are handling.
      Overrides:
      checkIndentation in class BlockParentHandler