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 TypeMethodDescriptionvoidCheck the indentation of the expression we are handling.private voidCheck the indentation of the switch expression.protected IndentLevelCompute the indentation amount for this handler.protected DetailASTGet the left curly brace portion of the expression we are handling.protected DetailASTGet the child element representing the list of statements.protected DetailASTGet the child element that is not a list of statements.protected DetailASTGet the right curly brace portion of the expression we are handling.private static booleanisWrappingTrigger(DetailAST astNode) Checks if the given AST node represents a construct that typically causes line wrapping and therefore requires additional indentation level.private booleanshouldIndentDueToWrapping(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, getTopLevelAstMethods 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:BlockParentHandlerGet the left curly brace portion of the expression we are handling.- Overrides:
getLeftCurlyin classBlockParentHandler- Returns:
- the left curly brace expression
-
getRightCurly
Description copied from class:BlockParentHandlerGet the right curly brace portion of the expression we are handling.- Overrides:
getRightCurlyin classBlockParentHandler- Returns:
- the right curly brace expression
-
getListChild
Description copied from class:BlockParentHandlerGet the child element representing the list of statements.- Overrides:
getListChildin classBlockParentHandler- Returns:
- the statement list child
-
getNonListChild
Description copied from class:BlockParentHandlerGet the child element that is not a list of statements.- Overrides:
getNonListChildin classBlockParentHandler- Returns:
- the non-list child element
-
checkSwitchExpr
Check the indentation of the switch expression. -
getIndentImpl
Description copied from class:AbstractExpressionHandlerCompute the indentation amount for this handler.- Overrides:
getIndentImplin 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:AbstractExpressionHandlerCheck the indentation of the expression we are handling.- Overrides:
checkIndentationin classBlockParentHandler
-