public class ChildBlockLengthCheck
extends com.puppycrawl.tools.checkstyle.api.AbstractCheck
Supported keywords are used to detect blocks:
"if", "else", "for", "switch", "do", "while", "try", "catch".
Rationale:
Length of child block that is more then 80% of parent block is usually hard to read in case child block is long(few display screens). Such child blocks should be refactored or moved to separate method.
| Modifier and Type | Field and Description |
|---|---|
static String |
MSG_KEY
A key is pointing to the warning message text in "messages.properties"
file.
|
| Constructor and Description |
|---|
ChildBlockLengthCheck() |
| Modifier and Type | Method and Description |
|---|---|
int[] |
getAcceptableTokens() |
int[] |
getDefaultTokens() |
int[] |
getRequiredTokens() |
void |
setBlockTypes(String... blockTypes)
Sets allowed types of blocks to be checked.
|
void |
setIgnoreBlockLinesCount(int ignoreBlockLinesCount)
Sets the maximum linelength of blocks that will be ignored by check.
|
void |
setMaxChildBlockPercentage(int maxChildBlockPercentage)
Sets the maximum percentage ratio between child and parent block.
|
void |
visitToken(com.puppycrawl.tools.checkstyle.api.DetailAST ast) |
beginTree, clearMessages, destroy, finishTree, getFileContents, getLine, getLines, getMessages, getTabWidth, getTokenNames, init, isCommentNodesRequired, leaveToken, log, log, log, setFileContents, setTabWidth, setTokensfinishLocalSetup, getCustomMessages, getId, getMessageBundle, getSeverity, getSeverityLevel, setId, setSeveritypublic static final String MSG_KEY
public void setBlockTypes(String... blockTypes)
blockTypes - - DetailAST tokenTypes that are related to the types which are
allowed by user in check preferences.public void setMaxChildBlockPercentage(int maxChildBlockPercentage)
maxChildBlockPercentage - the new "maxChildBlockPercentage" option value.public void setIgnoreBlockLinesCount(int ignoreBlockLinesCount)
ignoreBlockLinesCount - the maximum linelength of the block to be ignored.public int[] getDefaultTokens()
getDefaultTokens in class com.puppycrawl.tools.checkstyle.api.AbstractCheckpublic int[] getAcceptableTokens()
getAcceptableTokens in class com.puppycrawl.tools.checkstyle.api.AbstractCheckpublic int[] getRequiredTokens()
getRequiredTokens in class com.puppycrawl.tools.checkstyle.api.AbstractCheckpublic void visitToken(com.puppycrawl.tools.checkstyle.api.DetailAST ast)
visitToken in class com.puppycrawl.tools.checkstyle.api.AbstractCheckCopyright © 2021. All rights reserved.