Skip to content

Commit

Permalink
Issue #13675: add constructor call token to MethodParamPadCheck
Browse files Browse the repository at this point in the history
  • Loading branch information
strkkk committed May 23, 2024
1 parent c5a873b commit 7e41632
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@
* Default value is:
* <a href="https://checkstyle.org/apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#CTOR_DEF">
* CTOR_DEF</a>,
* <a href="https://checkstyle.org/apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#CTOR_CALL">
* CTOR_CALL</a>,
* <a href="https://checkstyle.org/apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#LITERAL_NEW">
* LITERAL_NEW</a>,
* <a href="https://checkstyle.org/apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#METHOD_CALL">
Expand Down Expand Up @@ -133,6 +135,7 @@ public int[] getDefaultTokens() {
public int[] getAcceptableTokens() {
return new int[] {
TokenTypes.CTOR_DEF,
TokenTypes.CTOR_CALL,
TokenTypes.LITERAL_NEW,
TokenTypes.METHOD_CALL,
TokenTypes.METHOD_DEF,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
type="com.puppycrawl.tools.checkstyle.checks.whitespace.PadOption">
<description>Specify policy on how to pad method parameter.</description>
</property>
<property default-value="CTOR_DEF,LITERAL_NEW,METHOD_CALL,METHOD_DEF,SUPER_CTOR_CALL,ENUM_CONSTANT_DEF,RECORD_DEF"
<property default-value="CTOR_DEF,CTOR_CALL,LITERAL_NEW,METHOD_CALL,METHOD_DEF,SUPER_CTOR_CALL,ENUM_CONSTANT_DEF,RECORD_DEF"
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 @@ -277,7 +277,7 @@
</module>
<module name="MethodParamPad">
<property name="tokens"
value="CTOR_DEF, LITERAL_NEW, METHOD_CALL, METHOD_DEF,
value="CTOR_DEF, LITERAL_NEW, METHOD_CALL, METHOD_DEF, CTOR_CALL,
SUPER_CTOR_CALL, ENUM_CONSTANT_DEF, RECORD_DEF"/>
</module>
<module name="NoWhitespaceBefore">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ public void testMethodParamPadRecords() throws Exception {
"20:34: " + getCheckMessage(MSG_WS_PRECEDED, "("),
"31:17: " + getCheckMessage(MSG_WS_PRECEDED, "("),
"32:14: " + getCheckMessage(MSG_WS_PRECEDED, "("),
"33:18: " + getCheckMessage(MSG_WS_PRECEDED, "("),
"37:17: " + getCheckMessage(MSG_WS_PRECEDED, "("),
"38:33: " + getCheckMessage(MSG_WS_PRECEDED, "("),
"44:17: " + getCheckMessage(MSG_WS_PRECEDED, "("),
Expand All @@ -141,7 +142,9 @@ public void testMethodParamPadRecords() throws Exception {

@Test
public void test1322879() throws Exception {
final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
final String[] expected = {
"28:13: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "("),
};
verifyWithInlineConfigParser(
getPath("InputMethodParamPadWhitespaceAround.java"),
expected);
Expand Down Expand Up @@ -170,6 +173,7 @@ public void testGetAcceptableTokens() {
final int[] actual = methodParamPadCheckObj.getAcceptableTokens();
final int[] expected = {
TokenTypes.CTOR_DEF,
TokenTypes.CTOR_CALL,
TokenTypes.LITERAL_NEW,
TokenTypes.METHOD_CALL,
TokenTypes.METHOD_DEF,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ private boolean inRecord (Object obj) { // violation ''(' is preceded with white
//in ctor
record Mtr2 () { // violation ''(' is preceded with whitespace'
Mtr2 (String s1, String s2, String s3){ // violation ''(' is preceded with whitespace'
this ();
this (); // violation ''(' is preceded with whitespace'
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ protected InputMethodParamPadWhitespaceAround ()

protected InputMethodParamPadWhitespaceAround ( String s)
{
// ok, until https://github.com/checkstyle/checkstyle/issues/13675
this();
this(); // violation ''(' is not preceded with whitespace'
}

public void enhancedFor ()
Expand Down
4 changes: 4 additions & 0 deletions src/xdocs/checks/whitespace/methodparampad.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@
<td>subset of tokens
<a href="../../apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#CTOR_DEF">
CTOR_DEF</a>
, <a href="../../apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#CTOR_CALL">
CTOR_CALL</a>
, <a href="../../apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#LITERAL_NEW">
LITERAL_NEW</a>
, <a href="../../apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#METHOD_CALL">
Expand All @@ -69,6 +71,8 @@
<td>
<a href="../../apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#CTOR_DEF">
CTOR_DEF</a>
, <a href="../../apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#CTOR_CALL">
CTOR_CALL</a>
, <a href="../../apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#LITERAL_NEW">
LITERAL_NEW</a>
, <a href="../../apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#METHOD_CALL">
Expand Down

0 comments on commit 7e41632

Please sign in to comment.