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
ConstructorsConstructorDescriptionTryHandler(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 voidcheckChildIndentation(DetailAST ast, String subType, IndentLevel expectedIdent) Method to check indentation of try resources children.voidCheck the indentation of the expression we are handling.private voidcheckTryResources(DetailAST resourcesSpecAst) Checks indentation of resources parameters in try resources.private voidcheckTryResParen(DetailAST parenAst, String subType) Method to check the indentation of left paren or right paren.Indentation level suggested for a child element.private DetailASTMethod to find left parenthesis of try with resources.private DetailASTMethod to find right parenthesis of try with resources.private static booleanCheck 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, 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, 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:AbstractExpressionHandlerIndentation level suggested for a child element. Children don't have to respect this, but most do.- Overrides:
getSuggestedChildIndentin classBlockParentHandler- Parameters:
child- child AST (so suggestion level can differ based on child type)- Returns:
- suggested indentation for child
-
checkIndentation
Description copied from class:AbstractExpressionHandlerCheck the indentation of the expression we are handling.- Overrides:
checkIndentationin 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.
-