Class LambdaHandler
java.lang.Object
com.puppycrawl.tools.checkstyle.checks.indentation.AbstractExpressionHandler
com.puppycrawl.tools.checkstyle.checks.indentation.LambdaHandler
Handler for lambda expressions.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate booleanChecks whether the lambda is correctly indented, this variable get its value from checking the lambda handler's indentation, and it is being used in aligning the lambda's children. -
Constructor Summary
ConstructorsConstructorDescriptionLambdaHandler(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 voidcheckLineWrappedLambda(boolean isSwitchRuleLambda, int mainAstColumnNo) This method checks a line wrapped lambda, whether it is a lambda expression or switch rule lambda.private voidcheckSingleStatementSwitchRuleIndentation(boolean isLambdaFirstInLine) Checks the indentation of statements inside a single-statement switch rule when the statement is not on the same line as the lambda operator (->).protected IndentLevelCompute the indentation amount for this handler.Indentation level suggested for a child element.private booleanisNonAcceptableIndent(int astColumnNo, IndentLevel level) Checks that given indent is acceptable or not.private booleanisSameLineAsSwitch(DetailAST node) Checks if the current LAMBDA node is placed on the same line as the given SWITCH_LITERAL node.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
-
isLambdaCorrectlyIndented
Checks whether the lambda is correctly indented, this variable get its value from checking the lambda handler's indentation, and it is being used in aligning the lambda's children. A true value depicts lambda is correctly aligned without giving any errors. This is updated to false where there is any Indentation error log.
-
-
Constructor Details
-
LambdaHandler
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
-
getSuggestedChildIndent
Description copied from class:AbstractExpressionHandlerIndentation level suggested for a child element. Children don't have to respect this, but most do.- Overrides:
getSuggestedChildIndentin classAbstractExpressionHandler- Parameters:
child- child AST (so suggestion level can differ based on child type)- Returns:
- suggested indentation for child
-
getIndentImpl
Compute the indentation amount for this handler..- Overrides:
getIndentImplin classAbstractExpressionHandler- Returns:
- the expected indentation amount
-
checkIndentation
Description copied from class:AbstractExpressionHandlerCheck the indentation of the expression we are handling.- Specified by:
checkIndentationin classAbstractExpressionHandler
-
isNonAcceptableIndent
Checks that given indent is acceptable or not.- Parameters:
astColumnNo- indent value to checklevel- indent level- Returns:
- true if indent is not acceptable
-
checkLineWrappedLambda
This method checks a line wrapped lambda, whether it is a lambda expression or switch rule lambda.- Parameters:
isSwitchRuleLambda- if mainAst is a switch rule lambdamainAstColumnNo- the column number of the lambda we are checking
-
checkSingleStatementSwitchRuleIndentation
Checks the indentation of statements inside a single-statement switch rule when the statement is not on the same line as the lambda operator (->). This applies to single-statement switch rules without curly braces{}. Example:case ONE
->1;- Parameters:
isLambdaFirstInLine- if->is the first element on the line
-
isSameLineAsSwitch
Checks if the current LAMBDA 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 LAMBDA node is on the same line as the given SWITCH_LITERAL node
-