public class SingleSpaceSeparatorCheck extends AbstractCheck
Checks that non-whitespace characters are separated by no more than one whitespace. Separating characters by tabs or multiple spaces will be reported. Currently the check doesn't permit horizontal alignment. To inspect whitespaces before and after comments, set the property validateComments to true.
Setting validateComments to false will ignore cases like:
int i; // Multiple whitespaces before comment tokens will be ignored. private void foo(int /* whitespaces before and after block-comments will be ignored */ i) {
Sometimes, users like to space similar items on different lines to the same column position for easier reading. This feature isn't supported by this check, so both braces in the following case will be reported as violations.
public long toNanos(long d) { return d; } // 2 violations public long toMicros(long d) { return d / (C1 / C0); }
Check have following options:
true
, whitespaces
surrounding comments will be ignored. Default value is false
.To configure the check:
<module name="SingleSpaceSeparator"/>
To configure the check so that it validates comments:
<module name="SingleSpaceSeparator"> <property name="validateComments" 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 |
---|
SingleSpaceSeparatorCheck() |
Modifier and Type | Method and Description |
---|---|
void |
beginTree(DetailAST rootAST)
Called before the starting to process a tree.
|
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.
|
boolean |
isCommentNodesRequired()
Whether comment nodes are required or not.
|
void |
setValidateComments(boolean validateComments)
Sets whether or not to validate surrounding whitespaces at comments.
|
clearMessages, destroy, finishTree, getClassLoader, getFileContents, getLine, getLines, getMessages, getTabWidth, getTokenNames, init, leaveToken, log, log, log, setClassLoader, setFileContents, setTabWidth, setTokens, visitToken
finishLocalSetup, getCustomMessages, getId, getMessageBundle, getSeverity, getSeverityLevel, setId, setSeverity
configure, contextualize, getConfiguration, setupChild
public static final String MSG_KEY
public SingleSpaceSeparatorCheck()
public void setValidateComments(boolean validateComments)
validateComments
- true
to validate surrounding whitespaces at comments.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 boolean isCommentNodesRequired()
AbstractCheck
isCommentNodesRequired
in class AbstractCheck
public void beginTree(DetailAST rootAST)
AbstractCheck
beginTree
in class AbstractCheck
rootAST
- the root of the treeCopyright © 2001–2018. All rights reserved.