Class SwitchHandler
java.lang.Object
com.puppycrawl.tools.checkstyle.checks.indentation.AbstractExpressionHandler
com.puppycrawl.tools.checkstyle.checks.indentation.BlockParentHandler
com.puppycrawl.tools.checkstyle.checks.indentation.SwitchHandler
Handler for switch statements.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final int[]
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 Summary
ConstructorsConstructorDescriptionSwitchHandler
(IndentationCheck indentCheck, DetailAST ast, AbstractExpressionHandler parent) Construct an instance of this handler with the given indentation check, abstract syntax tree, and parent handler. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Check the indentation of the expression we are handling.private void
Check the indentation of the switch expression.protected IndentLevel
Compute the indentation amount for this handler.protected DetailAST
Get the left curly brace portion of the expression we are handling.protected DetailAST
Get the child element representing the list of statements.protected DetailAST
Get the child element that is not a list of statements.protected DetailAST
Get the right curly brace portion of the expression we are handling.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.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.Methods inherited from class com.puppycrawl.tools.checkstyle.checks.indentation.BlockParentHandler
canChildrenBeNested, checkTopLevelToken, curlyIndent, getCheckedChildren, getChildrenExpectedIndent, getSuggestedChildIndent, getTopLevelAst
Methods inherited from class com.puppycrawl.tools.checkstyle.checks.indentation.AbstractExpressionHandler
checkChildren, checkExpressionSubtree, checkLeftParen, checkModifiers, checkRightParen, checkWrappingIndentation, checkWrappingIndentation, expandedTabsColumnNo, findSubtreeAst, getBasicOffset, getBraceAdjustment, getFirstAstNode, getFirstLine, getFirstToken, getIndent, getIndentCheck, getLineStart, getLineStart, getMainAst, getParent, isOnStartOfLine, logError, logError, shouldIncreaseIndent
-
Field Details
-
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
Construct an instance of this handler with the given indentation check, abstract syntax tree, and parent handler.- Parameters:
indentCheck
- the indentation checkast
- the abstract syntax treeparent
- the parent handler
-
-
Method Details
-
getLeftCurly
Description copied from class:BlockParentHandler
Get the left curly brace portion of the expression we are handling.- Overrides:
getLeftCurly
in classBlockParentHandler
- Returns:
- the left curly brace expression
-
getRightCurly
Description copied from class:BlockParentHandler
Get the right curly brace portion of the expression we are handling.- Overrides:
getRightCurly
in classBlockParentHandler
- Returns:
- the right curly brace expression
-
getListChild
Description copied from class:BlockParentHandler
Get the child element representing the list of statements.- Overrides:
getListChild
in classBlockParentHandler
- Returns:
- the statement list child
-
getNonListChild
Description copied from class:BlockParentHandler
Get the child element that is not a list of statements.- Overrides:
getNonListChild
in classBlockParentHandler
- Returns:
- the non-list child element
-
checkSwitchExpr
Check the indentation of the switch expression. -
getIndentImpl
Description copied from class:AbstractExpressionHandler
Compute the indentation amount for this handler.- Overrides:
getIndentImpl
in classAbstractExpressionHandler
- Returns:
- the expected indentation amount
-
shouldIndentDueToWrapping
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 nodegrandParent
- 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
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
Description copied from class:AbstractExpressionHandler
Check the indentation of the expression we are handling.- Overrides:
checkIndentation
in classBlockParentHandler
-