Class BlockParentHandler
java.lang.Object
com.puppycrawl.tools.checkstyle.checks.indentation.AbstractExpressionHandler
com.puppycrawl.tools.checkstyle.checks.indentation.BlockParentHandler
- Direct Known Subclasses:
AnnotationArrayInitHandler,ArrayInitHandler,CatchHandler,ClassDefHandler,DoWhileHandler,ElseHandler,FinallyHandler,ForHandler,IfHandler,MethodDefHandler,ObjectBlockHandler,SlistHandler,StaticInitHandler,SwitchHandler,SynchronizedHandler,TryHandler,WhileHandler
Handler for parents of blocks ('if', 'else', 'while', etc).
The "block" handler classes use a common superclass BlockParentHandler, employing the Template Method pattern.
- template method to get the lcurly
- template method to get the rcurly
- if curlies aren't present, then template method to get expressions is called
- now all the repetitious code which checks for BOL, if curlies are on same line, etc. can be collapsed into the superclass
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final int[]Children checked by parent handlers. -
Constructor Summary
ConstructorsConstructorDescriptionBlockParentHandler(IndentationCheck indentCheck, String name, DetailAST ast, AbstractExpressionHandler parent) Construct an instance of this handler with the given indentation check, name, abstract syntax tree, and parent handler. -
Method Summary
Modifier and TypeMethodDescriptionprotected booleanDetermines if child elements within the expression may be nested.private booleanChecks if lcurly is a Code block.voidCheck the indentation of the expression we are handling.private voidCheck the indentation of the left curly brace.private voidCheck the indentation level of a child that is not a list of statements.private voidCheck the indentation of the right curly brace.protected voidCheck the indent of the top level token.protected IndentLevelGet the expected indentation level for the curly braces.protected int[]Returns array of token types which should be checked among children.protected IndentLevelGets indentation level expected for children.protected DetailASTGet the left curly brace portion of the expression we are handling.private DetailASTGet the left parenthesis portion of the expression we are handling.private intA shortcut forIndentationCheckproperty.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 DetailASTGet the right parenthesis portion of the expression we are handling.Indentation level suggested for a child element.protected DetailASTGet the top level expression being managed by this handler.private booleanDetermines if this block expression has curly braces.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
-
Field Details
-
CHECKED_CHILDREN
Children checked by parent handlers.
-
-
Constructor Details
-
BlockParentHandler
public BlockParentHandler(IndentationCheck indentCheck, String name, DetailAST ast, AbstractExpressionHandler parent) Construct an instance of this handler with the given indentation check, name, abstract syntax tree, and parent handler.- Parameters:
indentCheck- the indentation checkname- the name of the handlerast- the abstract syntax treeparent- the parent handler
-
-
Method Details
-
getCheckedChildren
Returns array of token types which should be checked among children.- Returns:
- array of token types to check.
-
getTopLevelAst
Get the top level expression being managed by this handler.- Returns:
- the top level expression
-
checkTopLevelToken
Check the indent of the top level token. -
hasCurlies
Determines if this block expression has curly braces.- Returns:
- true if curly braces are present, false otherwise
-
getLeftCurly
Get the left curly brace portion of the expression we are handling.- Returns:
- the left curly brace expression
-
getRightCurly
Get the right curly brace portion of the expression we are handling.- Returns:
- the right curly brace expression
-
checkLeftCurly
Check the indentation of the left curly brace. -
curlyIndent
Get the expected indentation level for the curly braces.- Returns:
- the curly brace indentation level
-
checkIfCodeBlock
Checks if lcurly is a Code block.- Returns:
- true if lcurly is a code block
-
canChildrenBeNested
Determines if child elements within the expression may be nested.- Returns:
- false
-
checkRightCurly
Check the indentation of the right curly brace. -
getNonListChild
Get the child element that is not a list of statements.- Returns:
- the non-list child element
-
checkNonListChild
Check the indentation level of a child that is not a list of statements. -
getListChild
Get the child element representing the list of statements.- Returns:
- the statement list child
-
getRightParen
Get the right parenthesis portion of the expression we are handling.- Returns:
- the right parenthesis expression
-
getLeftParen
Get the left parenthesis portion of the expression we are handling.- Returns:
- the left parenthesis expression
-
checkIndentation
Description copied from class:AbstractExpressionHandlerCheck the indentation of the expression we are handling.- Specified by:
checkIndentationin classAbstractExpressionHandler
-
getChildrenExpectedIndent
Gets indentation level expected for children.- Returns:
- indentation level expected for children
-
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
-
getLineWrappingIndent
A shortcut forIndentationCheckproperty.- Returns:
- value of lineWrappingIndentation property
of
IndentationCheck
-