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
.
The check processes ARRAY_DECLARATOR and INDEX_OP tokens specially from other tokens. Actually it is checked that there is no whitespace before this tokens, not after them. Space after the ANNOTATIONS before ARRAY_DECLARATOR and INDEX_OP will be ignored.
allowLineBreaks
- Control whether whitespace is allowed
if the token is at a linebreak.
Type is boolean
.
Default value is true
.
tokens
- tokens to check
Type is int[]
.
Default value is:
ARRAY_INIT,
AT,
INC,
DEC,
UNARY_MINUS,
UNARY_PLUS,
BNOT,
LNOT,
DOT,
ARRAY_DECLARATOR,
INDEX_OP.
To configure the check:
<module name="NoWhitespaceAfter"/>
To configure the check to forbid linebreaks after a DOT token:
<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
Parent is com.puppycrawl.tools.checkstyle.TreeWalker
Violation Message Keys:
ws.followed
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)
Setter to control whether whitespace is allowed if the token is at a linebreak.
|
void |
visitToken(DetailAST ast)
Called to process a token.
|
beginTree, clearMessages, destroy, finishTree, getFileContents, getLine, getLines, getMessages, getTabWidth, getTokenNames, init, isCommentNodesRequired, leaveToken, log, log, log, 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–2020. All rights reserved.