public class WhitespaceAroundCheck extends Check
Checks that a token is surrounded by whitespace.
By default the check will check the following operators:
ASSERT
,
ASSIGN
,
BAND
,
BAND_ASSIGN
,
BOR
,
BOR_ASSIGN
,
BSR
,
BSR_ASSIGN
,
BXOR
,
BXOR_ASSIGN
,
COLON
,
DIV
,
DIV_ASSIGN
,
DO_WHILE
,
EQUAL
,
GE
,
GT
,
LAND
,
LCURLY
,
LE
,
LITERAL_CATCH
,
LITERAL_DO
,
LITERAL_ELSE
,
LITERAL_FINALLY
,
LITERAL_FOR
,
LITERAL_IF
,
LITERAL_RETURN
,
LITERAL_SWITCH
,
LITERAL_SYNCHRONIZED
,
LITERAL_TRY
,
LITERAL_WHILE
,
LOR
,
LT
,
MINUS
,
MINUS_ASSIGN
,
MOD
,
MOD_ASSIGN
,
NOT_EQUAL
,
PLUS
,
PLUS_ASSIGN
,
QUESTION
,
RCURLY
,
SL
,
SLIST
,
SL_ASSIGN
,
SR
,
SR_ASSIGN
,
STAR
,
STAR_ASSIGN
,
LITERAL_ASSERT
,
TYPE_EXTENSION_AND
.
An example of how to configure the check is:
<module name="WhitespaceAround"/>
An example of how to configure the check for whitespace only around assignment operators is:
<module name="WhitespaceAround"> <property name="tokens" value="ASSIGN,DIV_ASSIGN,PLUS_ASSIGN,MINUS_ASSIGN,STAR_ASSIGN,MOD_ASSIGN,SR_ASSIGN,BSR_ASSIGN,SL_ASSIGN,BXOR_ASSIGN,BOR_ASSIGN,BAND_ASSIGN"/> </module>
In addition, this check can be configured to allow empty methods, types, for, while, do-while loops and constructor bodies. For example:
public MyClass() {} // empty constructor
public void func() {} // empty method
public interface Foo {} // empty interface
public class Foo {} // empty class
public enum Foo {} // empty enum
MyClass c = new MyClass() {}; // empty anonymous class
while (i = 1) {} // empty while loop
for (int i = 1; i > 1; i++) {} // empty for loop
do {} while (i = 1); // empty do-while loop
public @interface Beta {} // empty annotation type
To configure the check to allow empty method blocks use
<property name="allowEmptyMethods" value="true" />
To configure the check to allow empty constructor blocks use
<property name="allowEmptyConstructors" value="true" />
To configure the check to allow empty type blocks use
<property name="allowEmptyTypes" value="true" />
To configure the check to allow empty loop blocks use
<property name="allowEmptyLoops" value="true" />
Also, this check can be configured to ignore the colon in an enhanced for loop. The colon in an enhanced for loop is ignored by default
To configure the check to ignore the colon
<property name="ignoreEnhancedForColon" value="true" />
Constructor and Description |
---|
WhitespaceAroundCheck() |
Modifier and Type | Method and Description |
---|---|
int[] |
getDefaultTokens()
Returns the default token a check is interested in.
|
void |
setAllowEmptyConstructors(boolean allow)
Sets whether or not empty constructor bodies are allowed.
|
void |
setAllowEmptyLoops(boolean allow)
Sets whether or not empty loop bodies are allowed.
|
void |
setAllowEmptyMethods(boolean allow)
Sets whether or not empty method bodies are allowed.
|
void |
setAllowEmptyTypes(boolean allow)
Sets whether or not empty type bodies are allowed.
|
void |
setIgnoreEnhancedForColon(boolean ignore)
Sets whether or not to ignore the whitespace around the
colon in an enhanced for loop.
|
void |
visitToken(DetailAST ast)
Called to process a token.
|
beginTree, destroy, finishTree, getAcceptableTokens, getClassLoader, getFileContents, getLine, getLines, getRequiredTokens, getTabWidth, getTokenNames, init, isCommentNodesRequired, leaveToken, log, log, setClassLoader, setFileContents, setMessages, setTabWidth, setTokens
getCustomMessages, getId, getMessageBundle, getSeverity, getSeverityLevel, log, setId, setSeverity
configure, contextualize, finishLocalSetup, getConfiguration, setupChild
public WhitespaceAroundCheck()
public int[] getDefaultTokens()
Check
getDefaultTokens
in class Check
TokenTypes
public void setAllowEmptyMethods(boolean allow)
allow
- true
to allow empty method bodies.public void setAllowEmptyConstructors(boolean allow)
allow
- true
to allow empty constructor bodies.public void setIgnoreEnhancedForColon(boolean ignore)
ignore
- true
to ignore enhanced for colon.public void setAllowEmptyTypes(boolean allow)
allow
- true
to allow empty type bodies.public void setAllowEmptyLoops(boolean allow)
allow
- true
to allow empty loops bodies.public void visitToken(DetailAST ast)
Check
visitToken
in class Check
ast
- the token to processCopyright © 2001–2015. All rights reserved.