Class SwitchRuleHandler

java.lang.Object
com.puppycrawl.tools.checkstyle.checks.indentation.AbstractExpressionHandler
com.puppycrawl.tools.checkstyle.checks.indentation.SwitchRuleHandler

public class SwitchRuleHandler extends AbstractExpressionHandler
Handler for switch rules.
  • Field Details

    • SWITCH_RULE_CHILDREN

      private static final int[] SWITCH_RULE_CHILDREN
      The child elements of a switch rule.
  • Constructor Details

    • SwitchRuleHandler

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

    • 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
    • checkCase

      private void checkCase()
      Check the indentation of the case statement.
    • getSuggestedChildIndent

      public IndentLevel getSuggestedChildIndent(AbstractExpressionHandler child)
      Description copied from class: AbstractExpressionHandler
      Indentation level suggested for a child element. Children don't have to respect this, but most do.
      Overrides:
      getSuggestedChildIndent in class AbstractExpressionHandler
      Parameters:
      child - child AST (so suggestion level can differ based on child type)
      Returns:
      suggested indentation for child
    • checkIndentation

      public void checkIndentation()
      Description copied from class: AbstractExpressionHandler
      Check the indentation of the expression we are handling.
      Specified by:
      checkIndentation in class AbstractExpressionHandler
    • isSameLineAsSwitch

      private boolean isSameLineAsSwitch(DetailAST node)
      Checks if the current SWITCH_RULE node is placed on the same line as the given SWITCH_LITERAL node.
      Parameters:
      node - the SWITCH_LITERAL node to compare with
      Returns:
      true if the current SWITCH_RULE node is on the same line as the given SWITCH_LITERAL node