Skip to content

Commit

Permalink
Issue #11666: Added LITERAL_CASE support for WhitespaceAfter check
Browse files Browse the repository at this point in the history
  • Loading branch information
as23415672 authored and romani committed May 29, 2022
1 parent 3ca6f75 commit cddf6a5
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@
* LITERAL_SYNCHRONIZED</a>,
* <a href="https://checkstyle.org/apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#LITERAL_TRY">
* LITERAL_TRY</a>,
* <a href="https://checkstyle.org/apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#LITERAL_CASE">
* LITERAL_CASE</a>,
* <a href="https://checkstyle.org/apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#LAMBDA">
* LAMBDA</a>.
* </li>
Expand Down Expand Up @@ -210,6 +212,7 @@ public int[] getAcceptableTokens() {
TokenTypes.LITERAL_SWITCH,
TokenTypes.LITERAL_SYNCHRONIZED,
TokenTypes.LITERAL_TRY,
TokenTypes.LITERAL_CASE,
TokenTypes.LAMBDA,
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
EmptyForIteratorPad&lt;/a&gt; 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
2 changes: 1 addition & 1 deletion src/main/resources/google_checks.xml
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@
value="COMMA, SEMI, TYPECAST, LITERAL_IF, LITERAL_ELSE, LITERAL_RETURN,
LITERAL_WHILE, LITERAL_DO, LITERAL_FOR, LITERAL_FINALLY, DO_WHILE, ELLIPSIS,
LITERAL_SWITCH, LITERAL_SYNCHRONIZED, LITERAL_TRY, LITERAL_CATCH, LAMBDA,
LITERAL_YIELD"/>
LITERAL_YIELD, LITERAL_CASE"/>
</module>
<module name="WhitespaceAround">
<property name="allowEmptyConstructors" value="true"/>
Expand Down
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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;
}
}
}
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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 cddf6a5

Please sign in to comment.