public class NoWhitespaceAfterCheck extends AbstractCheck
Checks that there is no whitespace after a token. More specifically, it checks that it is not followed by whitespace, or (if linebreaks are allowed) all characters on the line after are whitespace. To forbid linebreaks after a token, set property allowLineBreaks to false.
By default the check will check the following operators:
ARRAY_INIT
,
AT
,
BNOT
,
DEC
,
DOT
,
INC
,
LNOT
,
UNARY_MINUS
,
UNARY_PLUS
,
TYPECAST
,
ARRAY_DECLARATOR
,
INDEX_OP
.
The check processes
ARRAY_DECLARATOR
,
INDEX_OP
specially from other tokens. Actually it is checked that there is
no whitespace before this tokens, not after them.
Spaces after the ANNOTATIONS
before ARRAY_DECLARATOR
and INDEX_OP
will be ignored.
An example of how to configure the check is:
<module name="NoWhitespaceAfter"/>
An example of how to configure the check to forbid linebreaks after
a DOT
token is:
<module name="NoWhitespaceAfter"> <property name="tokens" value="DOT"/> <property name="allowLineBreaks" value="false"/> </module>
If the annotation is between the type and the array, the check will skip validation for spaces:
public void foo(final char @NotNull [] param) {} // No violation
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 |
---|
NoWhitespaceAfterCheck() |
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 linebreaks.
|
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 NoWhitespaceAfterCheck()
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 setAllowLineBreaks(boolean allowLineBreaks)
allowLineBreaks
- whether whitespace should be
flagged at linebreaks.public void visitToken(DetailAST ast)
AbstractCheck
visitToken
in class AbstractCheck
ast
- the token to processCopyright © 2001–2018. All rights reserved.