public class NoWhitespaceBeforeCheck extends AbstractCheck
Checks that there is no whitespace before a token. More specifically, it checks that it is not preceded with whitespace, or (if line breaks are allowed) all characters on the line before are whitespace. To allow line breaks before a token, set property allowLineBreaks to true. No check occurs before semi-colons in empty for loop initializers or conditions.
By default the check will check the following operators:
COMMA
,
SEMI
,
POST_DEC
,
POST_INC
,
ELLIPSIS
.
DOT
is also an acceptable token in a configuration
of this check.
An example of how to configure the check is:
<module name="NoWhitespaceBefore"/>
An example of how to configure the check to allow line breaks before
a DOT
token is:
<module name="NoWhitespaceBefore"> <property name="tokens" value="DOT"/> <property name="allowLineBreaks" value="true"/> </module>
AutomaticBean.OutputStreamOptions
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 |
---|
NoWhitespaceBeforeCheck() |
Modifier and Type | Method and Description |
---|---|
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.
|
void |
setAllowLineBreaks(boolean allowLineBreaks)
Control whether whitespace is flagged at line breaks.
|
void |
visitToken(DetailAST ast)
Called to process a token.
|
beginTree, clearMessages, destroy, finishTree, getClassLoader, getFileContents, getLine, getLines, getMessages, getTabWidth, getTokenNames, init, isCommentNodesRequired, leaveToken, log, log, log, setClassLoader, setFileContents, setTabWidth, setTokens
finishLocalSetup, getCustomMessages, getId, getMessageBundle, getSeverity, getSeverityLevel, setId, setSeverity
configure, contextualize, getConfiguration, setupChild
public static final String MSG_KEY
public NoWhitespaceBeforeCheck()
public int[] getDefaultTokens()
AbstractCheck
getDefaultTokens
in class AbstractCheck
TokenTypes
public int[] getAcceptableTokens()
AbstractCheck
getAcceptableTokens
in class AbstractCheck
TokenTypes
public int[] getRequiredTokens()
AbstractCheck
getRequiredTokens
in class AbstractCheck
TokenTypes
public void visitToken(DetailAST ast)
AbstractCheck
visitToken
in class AbstractCheck
ast
- the token to processpublic void setAllowLineBreaks(boolean allowLineBreaks)
allowLineBreaks
- whether whitespace should be
flagged at line breaks.Copyright © 2001–2018. All rights reserved.