public class NoWhitespaceBeforeCaseDefaultColonCheck extends AbstractCheck
Checks that there is no whitespace before the colon in a switch block.
To configure the check:
<module name="NoWhitespaceBeforeCaseDefaultColon"/>
Example:
class Test {
{
switch(1) {
case 1 : // violation, whitespace before ':' is not allowed here
break;
case 2: // ok
break;
default : // violation, whitespace before ':' is not allowed here
break;
}
switch(2) {
case 2: // ok
break;
case 3, 4
: break; // violation, whitespace before ':' is not allowed here
case 4,
5: break; // ok
default
: // violation, whitespace before ':' is not allowed here
break;
}
switch(day) {
case MONDAY, FRIDAY, SUNDAY: System.out.println(" 6"); break;
case TUESDAY : System.out.println(" 7"); break; // violation
}
}
Parent is com.puppycrawl.tools.checkstyle.TreeWalker
Violation Message Keys:
ws.preceded
AutomaticBean.OutputStreamOptions| Modifier and Type | Field and Description |
|---|---|
static java.lang.String |
MSG_KEY
A key is pointing to the warning message text in "messages.properties"
file.
|
| Constructor and Description |
|---|
NoWhitespaceBeforeCaseDefaultColonCheck() |
| Modifier and Type | Method and Description |
|---|---|
int[] |
getAcceptableTokens()
The configurable token set.
|
int[] |
getDefaultTokens()
Returns the default token a check is interested in.
|
private static int |
getLastColumnNumberOf(DetailAST ast)
Returns the last column number of an ast.
|
int[] |
getRequiredTokens()
The tokens that this check must be registered for.
|
boolean |
isCommentNodesRequired()
Whether comment nodes are required or not.
|
private static boolean |
isInSwitch(DetailAST colonAst)
Checks if the colon is inside a switch block.
|
private static boolean |
isOnDifferentLineWithPreviousToken(DetailAST colonAst)
Checks if the colon is on same line as of case or default.
|
private static boolean |
isWhiteSpaceBeforeColon(DetailAST colonAst)
Checks if there is a whitespace before the colon of a switch case or switch default.
|
private static boolean |
isWhitespaceBeforeColonOfCase(DetailAST colonAst)
Checks if there is a whitespace before the colon of a switch case.
|
private static boolean |
isWhitespaceBeforeColonOfDefault(DetailAST colonAst)
Checks if there is a whitespace before the colon of a switch default.
|
void |
visitToken(DetailAST ast)
Called to process a token.
|
beginTree, clearViolations, destroy, finishTree, getFileContents, getLine, getLineCodePoints, getLines, getTabWidth, getTokenNames, getViolations, init, leaveToken, log, log, log, setFileContents, setTabWidth, setTokensfinishLocalSetup, getCustomMessages, getId, getMessageBundle, getSeverity, getSeverityLevel, setId, setSeverityconfigure, contextualize, getConfiguration, setupChildpublic static final java.lang.String MSG_KEY
public NoWhitespaceBeforeCaseDefaultColonCheck()
public int[] getDefaultTokens()
AbstractCheckgetDefaultTokens in class AbstractCheckTokenTypespublic int[] getAcceptableTokens()
AbstractCheckgetAcceptableTokens in class AbstractCheckTokenTypespublic int[] getRequiredTokens()
AbstractCheckgetRequiredTokens in class AbstractCheckTokenTypespublic boolean isCommentNodesRequired()
AbstractCheckisCommentNodesRequired in class AbstractCheckpublic void visitToken(DetailAST ast)
AbstractCheckvisitToken in class AbstractCheckast - the token to processprivate static boolean isInSwitch(DetailAST colonAst)
colonAst - DetailAST to check.private static boolean isWhiteSpaceBeforeColon(DetailAST colonAst)
colonAst - DetailAST to check.private static boolean isWhitespaceBeforeColonOfCase(DetailAST colonAst)
colonAst - DetailAST to check.private static boolean isWhitespaceBeforeColonOfDefault(DetailAST colonAst)
colonAst - DetailAST to check.private static boolean isOnDifferentLineWithPreviousToken(DetailAST colonAst)
colonAst - DetailAST to check.private static int getLastColumnNumberOf(DetailAST ast)
ast - DetailAST to check.Copyright © 2001-2022. All Rights Reserved.