public class WhitespaceAfterCheck extends AbstractCheck
Checks that a token is followed by whitespace, with the exception that it does not check for whitespace after the semicolon of an empty for iterator. Use Check EmptyForIteratorPad to validate empty for iterators.
tokens - tokens to check
Type is java.lang.String[].
Validation type is tokenSet.
Default value is:
COMMA,
SEMI,
TYPECAST,
LITERAL_IF,
LITERAL_ELSE,
LITERAL_WHILE,
LITERAL_DO,
LITERAL_FOR,
DO_WHILE.
To configure the check:
<module name="WhitespaceAfter"/>
Example:
public void myTest() {
if (foo) { // OK
//...
} else if(bar) { // violation
//...
}
testMethod(foo, bar); // OK
testMethod(foo,bar); // violation
for (;;){} // OK
for(;;){} // violation, space after 'for' is required
}
To configure the check for whitespace only after COMMA and SEMI tokens:
<module name="WhitespaceAfter"> <property name="tokens" value="COMMA, SEMI"/> </module>
Example:
public void myTest() {
int a; int b; // OK
int a;int b; // violation
testMethod(foo, bar); // OK
testMethod(foo,bar); // violation
for(;;) {} // OK
}
Parent is com.puppycrawl.tools.checkstyle.TreeWalker
Violation Message Keys:
ws.notFollowed
ws.typeCast
AutomaticBean.OutputStreamOptions| Modifier and Type | Field and Description |
|---|---|
static java.lang.String |
MSG_WS_NOT_FOLLOWED
A key is pointing to the warning message text in "messages.properties"
file.
|
static java.lang.String |
MSG_WS_TYPECAST
A key is pointing to the warning message text in "messages.properties"
file.
|
| Constructor and Description |
|---|
WhitespaceAfterCheck() |
| 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.
|
private static boolean |
isFollowedByWhitespace(DetailAST targetAST,
java.lang.String line)
Checks whether token is followed by a whitespace.
|
void |
visitToken(DetailAST ast)
Called to process a token.
|
beginTree, clearViolations, destroy, finishTree, getFileContents, getLine, getLineCodePoints, getLines, getTabWidth, getTokenNames, getViolations, init, isCommentNodesRequired, leaveToken, log, log, log, setFileContents, setTabWidth, setTokensfinishLocalSetup, getCustomMessages, getId, getMessageBundle, getSeverity, getSeverityLevel, setId, setSeverityconfigure, contextualize, getConfiguration, setupChildpublic static final java.lang.String MSG_WS_NOT_FOLLOWED
public static final java.lang.String MSG_WS_TYPECAST
public WhitespaceAfterCheck()
public 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 processprivate static boolean isFollowedByWhitespace(DetailAST targetAST, java.lang.String line)
targetAST - Ast token.line - The line associated with the ast token.Copyright © 2001-2022. All Rights Reserved.