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
-
public class TryHandler extends BlockParentHandler
Handler for try blocks.
-
-
Constructor Summary
Constructors Constructor Description TryHandler(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
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private void
checkChildIndentation(DetailAST ast, String subType, IndentLevel expectedIdent)
Method to check indentation of try resources children.void
checkIndentation()
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.IndentLevel
getSuggestedChildIndent(AbstractExpressionHandler child)
Indentation level suggested for a child element.private DetailAST
getTryResLparen()
Method to find left parenthesis of try with resources.private DetailAST
getTryResRparen()
Method to find right parenthesis of try with resources.private static boolean
isTryBlocksResourceSpecification(AbstractExpressionHandler expression)
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 Detail
-
TryHandler
public TryHandler(IndentationCheck indentCheck, DetailAST ast, AbstractExpressionHandler parent)
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 Detail
-
getTryResLparen
private DetailAST getTryResLparen()
Method to find left parenthesis of try with resources.- Returns:
- DetailAst left parenthesis of try with resources
-
getTryResRparen
private DetailAST getTryResRparen()
Method to find right parenthesis of try with resources.- Returns:
- DetailAst right parenthesis of try with resources
-
getSuggestedChildIndent
public IndentLevel getSuggestedChildIndent(AbstractExpressionHandler child)
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
public void checkIndentation()
Description copied from class:AbstractExpressionHandler
Check the indentation of the expression we are handling.- Overrides:
checkIndentation
in classBlockParentHandler
-
checkTryResParen
private void checkTryResParen(DetailAST parenAst, String subType)
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
private void checkChildIndentation(DetailAST ast, String subType, IndentLevel expectedIdent)
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
private void checkTryResources(DetailAST resourcesSpecAst)
Checks indentation of resources parameters in try resources.- Parameters:
resourcesSpecAst
- Resource specification ast
-
isTryBlocksResourceSpecification
private static boolean isTryBlocksResourceSpecification(AbstractExpressionHandler expression)
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.
-
-