Class EmptyLineWrappingInBlockCheck
java.lang.Object
com.puppycrawl.tools.checkstyle.AbstractAutomaticBean
com.puppycrawl.tools.checkstyle.api.AbstractViolationReporter
com.puppycrawl.tools.checkstyle.api.AbstractCheck
com.puppycrawl.tools.checkstyle.checks.whitespace.EmptyLineWrappingInBlockCheck
- All Implemented Interfaces:
Configurable,Contextualizable
Checks the empty line right after the opening brace and right before the closing
brace of a block.
topSeparator controls the line after the opening brace and
bottomSeparator controls the line before the closing brace.
Both accept the following values:
empty_line- exactly one empty line is required;empty_line_allowed- not validated, an empty line may be present or absent;no_empty_line- an empty line is forbidden.
- Since:
- 14.4.0
-
Nested Class Summary
Nested classes/interfaces inherited from class com.puppycrawl.tools.checkstyle.AbstractAutomaticBean
AbstractAutomaticBean.OutputStreamOptions -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate SeparatorOptionPolicy for empty lines before the closing brace of the block.static final StringA key is pointing to the warning message empty.line.wrapping.bottom.no in "messages.properties" file.static final StringA key is pointing to the warning message empty.line.wrapping.bottom.one in "messages.properties" file.static final StringA key is pointing to the warning message empty.line.wrapping.top.no in "messages.properties" file.static final StringA key is pointing to the warning message empty.line.wrapping.top.one in "messages.properties" file.private SeparatorOptionPolicy for empty lines after the opening brace of the block. -
Constructor Summary
ConstructorsConstructorDescriptionCreates a newEmptyLineWrappingInBlockCheckinstance. -
Method Summary
Modifier and TypeMethodDescriptionprivate static DetailASTfindLeftBrace(DetailAST ast) Finds the left (opening) brace of the block for the given AST node.private static DetailASTfindRightBrace(DetailAST leftBrace) Finds the right (closing) brace of the block for the given opening brace.int[]Returns the set of tokens that can be configured for this check.int[]Returns the default token set that this check validates.int[]Returns the tokens that this check must be registered for.private booleanhasBlankLineAfter(DetailAST leftCurly, DetailAST rightCurly) Checks whether the line immediately after the opening brace is blank.private booleanhasBlankLineBefore(DetailAST leftCurly, DetailAST rightCurly) Checks whether the line immediately before the closing brace is blank.private booleanhasOneEmptyLineAfter(DetailAST leftCurly, DetailAST rightCurly) Checks whether there is exactly one empty line after the opening brace.private booleanhasOneEmptyLineBefore(DetailAST leftCurly, DetailAST rightCurly) Checks whether there is exactly one empty line before the closing brace.voidsetBottomSeparator(String value) Specify the policy for the empty line before the closing brace.voidsetTopSeparator(String value) Specify the policy for the empty line after the opening brace.voidvisitToken(DetailAST ast) Called to process a token.Methods inherited from class com.puppycrawl.tools.checkstyle.api.AbstractCheck
beginTree, clearViolations, destroy, finishTree, getFileContents, getFilePath, getLine, getLineCodePoints, getLines, getTabWidth, getTokenNames, getViolations, init, isCommentNodesRequired, leaveToken, log, log, log, setFileContents, setTabWidth, setTokensMethods inherited from class com.puppycrawl.tools.checkstyle.api.AbstractViolationReporter
finishLocalSetup, getCustomMessages, getId, getMessageBundle, getSeverity, getSeverityLevel, setId, setSeverityMethods inherited from class com.puppycrawl.tools.checkstyle.AbstractAutomaticBean
configure, contextualize, getConfiguration, setupChild
-
Field Details
-
MSG_EMPTY_LINE_WRAPPING_TOP_NO
A key is pointing to the warning message empty.line.wrapping.top.no in "messages.properties" file.- See Also:
-
MSG_EMPTY_LINE_WRAPPING_TOP_ONE
A key is pointing to the warning message empty.line.wrapping.top.one in "messages.properties" file.- See Also:
-
MSG_EMPTY_LINE_WRAPPING_BOTTOM_NO
A key is pointing to the warning message empty.line.wrapping.bottom.no in "messages.properties" file.- See Also:
-
MSG_EMPTY_LINE_WRAPPING_BOTTOM_ONE
A key is pointing to the warning message empty.line.wrapping.bottom.one in "messages.properties" file.- See Also:
-
topSeparator
Policy for empty lines after the opening brace of the block. -
bottomSeparator
Policy for empty lines before the closing brace of the block.
-
-
Constructor Details
-
EmptyLineWrappingInBlockCheck
public EmptyLineWrappingInBlockCheck()Creates a newEmptyLineWrappingInBlockCheckinstance.
-
-
Method Details
-
setTopSeparator
Specify the policy for the empty line after the opening brace.- Parameters:
value- one ofempty_line,empty_line_allowed,no_empty_line- Throws:
IllegalArgumentException- if the value is not recognized- Since:
- 14.4.0
-
setBottomSeparator
Specify the policy for the empty line before the closing brace.- Parameters:
value- one ofempty_line,empty_line_allowed,no_empty_line- Throws:
IllegalArgumentException- if the value is not recognized- Since:
- 14.4.0
-
getDefaultTokens
Returns the default token set that this check validates.- Specified by:
getDefaultTokensin classAbstractCheck- Returns:
- the default tokens
- See Also:
-
getAcceptableTokens
Returns the set of tokens that can be configured for this check.- Specified by:
getAcceptableTokensin classAbstractCheck- Returns:
- the acceptable tokens
- See Also:
-
getRequiredTokens
Returns the tokens that this check must be registered for.- Specified by:
getRequiredTokensin classAbstractCheck- Returns:
- the empty array as this check has no required tokens
- See Also:
-
visitToken
Called to process a token. Validates empty line wrapping after the opening brace and before the closing brace of the block according to the configured policies.- Overrides:
visitTokenin classAbstractCheck- Parameters:
ast- the token to process
-
findLeftBrace
Finds the left (opening) brace of the block for the given AST node. The result depends on the token type (e.g. SLIST for statements, OBJBLOCK for type bodies, or the node itself for array inits).- Parameters:
ast- the AST node representing a block or block-containing construct- Returns:
- the AST of the opening brace, or null if not found
-
findRightBrace
Finds the right (closing) brace of the block for the given opening brace. The result depends on the token type: for SLIST/array-init the closing brace is the last child; for OBJBLOCK etc. it is the last child of the parent.- Parameters:
leftBrace- the opening brace AST, non-null- Returns:
- the closing brace AST
-
hasBlankLineAfter
Checks whether the line immediately after the opening brace is blank.- Parameters:
leftCurly- the opening brace tokenrightCurly- the closing brace token- Returns:
- true if the braces are on different lines and the next line is blank
-
hasOneEmptyLineAfter
Checks whether there is exactly one empty line after the opening brace. Used when topSeparator is EMPTY_LINE. Two or more consecutive empty lines are rejected.- Parameters:
leftCurly- the opening brace tokenrightCurly- the closing brace token- Returns:
- true if the next line is blank and the line after that is not blank
-
hasBlankLineBefore
Checks whether the line immediately before the closing brace is blank. Used when bottomSeparator is NO_EMPTY_LINE. Always false for same-line braces.- Parameters:
leftCurly- the opening brace tokenrightCurly- the closing brace token- Returns:
- true if the braces are on different lines and the previous line is blank
-
hasOneEmptyLineBefore
Checks whether there is exactly one empty line before the closing brace. Used when bottomSeparator is EMPTY_LINE. Two or more consecutive empty lines are rejected.- Parameters:
leftCurly- the opening brace tokenrightCurly- the closing brace token- Returns:
- true if the previous line is blank and the line before that is not blank
-