Class TryHandler
java.lang.Object
com.puppycrawl.tools.checkstyle.checks.indentation.AbstractExpressionHandler
com.puppycrawl.tools.checkstyle.checks.indentation.BlockParentHandler
com.puppycrawl.tools.checkstyle.checks.indentation.TryHandler
Handler for try blocks.
-
Constructor Summary
ConstructorDescriptionTryHandler
(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 TypeMethodDescriptionprivate void
checkChildIndentation
(DetailAST ast, String subType, IndentLevel expectedIdent) Method to check indentation of try resources children.void
Check the indentation of the expression we are handling.private void
checkTryResources
(DetailAST resourcesSpecAst) Checks indentation of resources parameters in try resources.private void
checkTryResParen
(DetailAST parenAst, String subType) Method to check the indentation of left paren or right paren.Indentation level suggested for a child element.private DetailAST
Method to find left parenthesis of try with resources.private DetailAST
Method to find right parenthesis of try with resources.private static boolean
Check if the expression is resource of try block.Methods inherited from class com.puppycrawl.tools.checkstyle.checks.indentation.BlockParentHandler
canChildrenBeNested, checkTopLevelToken, curlyIndent, getCheckedChildren, getChildrenExpectedIndent, getLeftCurly, getListChild, getNonListChild, getRightCurly, 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, getIndentImpl, getLineStart, getLineStart, getMainAst, getParent, isOnStartOfLine, logError, logError, shouldIncreaseIndent
-
Constructor Details
-
TryHandler
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
-
getTryResLparen
Method to find left parenthesis of try with resources.- Returns:
- DetailAst left parenthesis of try with resources
-
getTryResRparen
Method to find right parenthesis of try with resources.- Returns:
- DetailAst right parenthesis of try with resources
-
getSuggestedChildIndent
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 classBlockParentHandler
- Parameters:
child
- child AST (so suggestion level can differ based on child type)- Returns:
- suggested indentation for child
-
checkIndentation
Description copied from class:AbstractExpressionHandler
Check the indentation of the expression we are handling.- Overrides:
checkIndentation
in classBlockParentHandler
-
checkTryResParen
Method to check the indentation of left paren or right paren. This method itself checks whether either of these are on start of line. This method takes care of line wrapping strict condition as well.- Parameters:
parenAst
- lparen or rparen ast to checksubType
- name to be used in log message
-
checkChildIndentation
Method to check indentation of try resources children. It takes into account forceStrictCondition value when logging violations. Example of usage would include checking for try parenthesis and try resources.- Parameters:
ast
- AST to check.subType
- String representing child type.expectedIdent
- Expected indent level.
-
checkTryResources
Checks indentation of resources parameters in try resources.- Parameters:
resourcesSpecAst
- Resource specification ast
-
isTryBlocksResourceSpecification
Check if the expression is resource of try block.- Parameters:
expression
- The expression to check- Returns:
- if the expression provided is try block's resource specification.
-