public class EmptyBlockCheck extends AbstractCheck
BlockOption class and defaults to BlockOption.STATEMENT.
By default the check will check the following blocks:
LITERAL_WHILE,
LITERAL_TRY,
LITERAL_FINALLY,
LITERAL_DO,
LITERAL_IF,
LITERAL_ELSE,
LITERAL_FOR,
STATIC_INIT,
LITERAL_SWITCH.
LITERAL_SYNCHRONIZED.
An example of how to configure the check is:
<module name="EmptyBlock"/>
An example of how to configure the check for the BlockOption.TEXT policy and only try blocks is:
<module name="EmptyBlock">
<property name="tokens" value="LITERAL_TRY"/>
<property name="option" value="text"/>
</module>
| Modifier and Type | Field and Description |
|---|---|
static java.lang.String |
MSG_KEY_BLOCK_EMPTY
A key is pointing to the warning message text in "messages.properties"
file.
|
static java.lang.String |
MSG_KEY_BLOCK_NO_STATEMENT
A key is pointing to the warning message text in "messages.properties"
file.
|
private BlockOption |
option
The policy to enforce.
|
| Constructor and Description |
|---|
EmptyBlockCheck() |
| Modifier and Type | Method and Description |
|---|---|
private static boolean |
checkIsAllLinesAreWhitespace(java.lang.String[] lines,
int lineFrom,
int lineTo)
Checks is all lines in array contain whitespaces only.
|
private static DetailAST |
findLeftCurly(DetailAST ast)
Calculates the left curly corresponding to the block to be checked.
|
int[] |
getAcceptableTokens()
The configurable token set.
|
int[] |
getDefaultTokens()
Returns the default token a check is interested in.
|
int[] |
getRequiredTokens()
The tokens that this check must be registered for.
|
protected boolean |
hasText(DetailAST slistAST)
Checks if SLIST token contains any text.
|
void |
setOption(java.lang.String optionStr)
Set the option to enforce.
|
void |
visitToken(DetailAST ast)
Called to process a token.
|
beginTree, destroy, finishTree, getClassLoader, getFileContents, getLine, getLines, getTabWidth, getTokenNames, init, isCommentNodesRequired, leaveToken, log, log, setClassLoader, setFileContents, setMessages, setTabWidth, setTokensgetCustomMessages, getId, getMessageBundle, getSeverity, getSeverityLevel, log, setId, setSeverityconfigure, contextualize, finishLocalSetup, getConfiguration, setupChildpublic static final java.lang.String MSG_KEY_BLOCK_NO_STATEMENT
public static final java.lang.String MSG_KEY_BLOCK_EMPTY
private BlockOption option
public void setOption(java.lang.String optionStr)
optionStr - string to decode option fromjava.lang.IllegalArgumentException - if unable to decodepublic int[] getDefaultTokens()
AbstractCheckgetDefaultTokens in class AbstractCheckTokenTypespublic int[] getAcceptableTokens()
AbstractCheckgetAcceptableTokens in class AbstractCheckTokenTypespublic int[] getRequiredTokens()
AbstractCheckgetRequiredTokens in class AbstractCheckTokenTypespublic void visitToken(DetailAST ast)
AbstractCheckvisitToken in class AbstractCheckast - the token to processprotected boolean hasText(DetailAST slistAST)
slistAST - a DetailAST valueprivate static boolean checkIsAllLinesAreWhitespace(java.lang.String[] lines,
int lineFrom,
int lineTo)
lines - array of lineslineFrom - check from this line numberlineTo - check to this line numbers