Skip to content

Commit

Permalink
Issue checkstyle#11666: Added LITERAL_CASE support for WhitespaceAfte…
Browse files Browse the repository at this point in the history
…r check
  • Loading branch information
as23415672 committed May 24, 2022
1 parent 1f81858 commit d66d803
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 1 deletion.
Expand Up @@ -210,6 +210,7 @@ public int[] getAcceptableTokens() {
TokenTypes.LITERAL_SWITCH,
TokenTypes.LITERAL_SYNCHRONIZED,
TokenTypes.LITERAL_TRY,
TokenTypes.LITERAL_CASE,
TokenTypes.LAMBDA,
};
}
Expand Down
Expand Up @@ -11,7 +11,7 @@
EmptyForIteratorPad</a> to validate empty for iterators.
&lt;/p&gt;</description>
<properties>
<property default-value="COMMA,SEMI,TYPECAST,LITERAL_IF,LITERAL_ELSE,LITERAL_WHILE,LITERAL_DO,LITERAL_FOR,LITERAL_FINALLY,LITERAL_RETURN,LITERAL_YIELD,LITERAL_CATCH,DO_WHILE,ELLIPSIS,LITERAL_SWITCH,LITERAL_SYNCHRONIZED,LITERAL_TRY,LAMBDA"
<property default-value="COMMA,SEMI,TYPECAST,LITERAL_IF,LITERAL_ELSE,LITERAL_WHILE,LITERAL_DO,LITERAL_FOR,LITERAL_FINALLY,LITERAL_RETURN,LITERAL_YIELD,LITERAL_CATCH,DO_WHILE,ELLIPSIS,LITERAL_SWITCH,LITERAL_SYNCHRONIZED,LITERAL_TRY,LITERAL_CASE,LAMBDA"
name="tokens"
type="java.lang.String[]"
validation-type="tokenSet">
Expand Down
Expand Up @@ -215,6 +215,26 @@ public void testLiteralCatch() throws Exception {
expected);
}

@Test
public void testLiteralCase() throws Exception {
final String[] expected = {
"15:13: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "case"),
};
verifyWithInlineConfigParser(
getPath("InputWhitespaceAfterLiteralCase.java"),
expected);
}

@Test
public void testLiteralCase2() throws Exception {
final String[] expected = {
"13:13: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "case"),
};
verifyWithInlineConfigParser(
getPath("InputWhitespaceAfterLiteralCase2.java"),
expected);
}

@Test
public void testEmptyForIterator() throws Exception {
final String[] expected = {
Expand Down
@@ -0,0 +1,21 @@
/*
WhitespaceAfter
tokens = LITERAL_CASE
*/

package com.puppycrawl.tools.checkstyle.checks.whitespace.whitespaceafter;

public class InputWhitespaceAfterLiteralCase {
public static void main(String... args) {
switch(args[0]) {
case "123": // OK
return;
case"1": // violation ''case' is not followed by whitespace'
return;
default:
return;
}
}
}
@@ -0,0 +1,21 @@
/*
WhitespaceAfter
tokens = LITERAL_CASE
*/

package com.puppycrawl.tools.checkstyle.checks.whitespace.whitespaceafter;

public class InputWhitespaceAfterLiteralCase2 {
public static void main(String... args) {
switch(args[0]) {
case"123": // violation ''case' is not followed by whitespace'
return;
case "1": // OK
return;
default:
return;
}
}
}
4 changes: 4 additions & 0 deletions src/xdocs/config_whitespace.xml
Expand Up @@ -2991,6 +2991,8 @@ class Bar {
LITERAL_SYNCHRONIZED</a>
, <a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#LITERAL_TRY">
LITERAL_TRY</a>
, <a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#LITERAL_CASE">
LITERAL_CASE</a>
, <a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#LAMBDA">
LAMBDA</a>
.
Expand Down Expand Up @@ -3031,6 +3033,8 @@ class Bar {
LITERAL_SYNCHRONIZED</a>
, <a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#LITERAL_TRY">
LITERAL_TRY</a>
, <a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#LITERAL_CASE">
LITERAL_CASE</a>
, <a href="apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#LAMBDA">
LAMBDA</a>
.
Expand Down

0 comments on commit d66d803

Please sign in to comment.