public class NoArrayTrailingCommaCheck extends AbstractCheck
Checks that array initialization do not contain a trailing comma. Rationale: JLS allows trailing commas in arrays and enumerations, but does not allow them in other locations. To unify the coding style, the use of trailing commas should be prohibited.
int[] foo = new int[] {
1,
2
};
The check demands that there should not be any comma after the last element of an array.
String[] foo = new String[] {
"FOO",
"BAR", //violation
}
To configure the check:
<module name="NoArrayTrailingComma"/>
Which results in the following violations:
String[] foo1 = {
"FOO", // OK
"BAR", // violation
};
String[] foo2 = { "FOO", "BAR", }; // violation
String[] foo3 = {
"FOO", // OK
"BAR" // OK
};
String[] foo4 = { "FOO", "BAR" }; // OK
Parent is com.puppycrawl.tools.checkstyle.TreeWalker
Violation Message Keys:
no.array.trailing.comma
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 |
|---|
NoArrayTrailingCommaCheck() |
| 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 |
visitToken(DetailAST arrayInit)
Called to process a token.
|
beginTree, clearMessages, destroy, finishTree, getFileContents, getLine, getLines, getMessages, getTabWidth, getTokenNames, init, isCommentNodesRequired, leaveToken, log, log, log, setFileContents, setTabWidth, setTokensfinishLocalSetup, getCustomMessages, getId, getMessageBundle, getSeverity, getSeverityLevel, setId, setSeverityconfigure, contextualize, getConfiguration, setupChildpublic static final String MSG_KEY
public NoArrayTrailingCommaCheck()
public int[] getDefaultTokens()
AbstractCheckgetDefaultTokens in class AbstractCheckTokenTypespublic int[] getAcceptableTokens()
AbstractCheckgetAcceptableTokens in class AbstractCheckTokenTypespublic int[] getRequiredTokens()
AbstractCheckgetRequiredTokens in class AbstractCheckTokenTypespublic void visitToken(DetailAST arrayInit)
AbstractCheckvisitToken in class AbstractCheckarrayInit - the token to processCopyright © 2001–2020. All rights reserved.