Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Check Support for Java 21 Record Pattern : MethodParamPad #14966

Closed
mahfouz72 opened this issue Jun 9, 2024 · 1 comment · Fixed by #15168
Closed

Add Check Support for Java 21 Record Pattern : MethodParamPad #14966

mahfouz72 opened this issue Jun 9, 2024 · 1 comment · Fixed by #15168
Assignees
Milestone

Comments

@mahfouz72
Copy link
Member

mahfouz72 commented Jun 9, 2024

child of #14890

I have read check documentation: https://checkstyle.org/checks/whitespace/methodparampad.html#MethodParamPad
I have downloaded the latest checkstyle from: https://checkstyle.org/cmdline.html#Download_and_Run
I have executed the cli and showed it below, as cli describes the problem better than 1,000 words

PS D:\CS\test> javac src/RecordPatterns.java
PS D:\CS\test> cat src/RecordPatterns.java
import java.util.List;

public class RecordPatterns {
    class A { }
    sealed interface I permits C, D { }
    final class C implements I { }
    final class D implements I { }
    record Pair<T> (T x, T y) { } // violation

    void test() {
        C c = new C();
        D d = new D();

        Pair<I> p2 = new Pair<>(c, d);

        switch (p2) {
            case Pair (I i, C _) -> System.out.println("Pair (C|D, C)");    // expected violation
            case Pair(I i, D j) -> System.out.println("Pair (C|D, D)");
        }

    }
}
PS D:\CS\test> cat config.xml
<?xml version="1.0"?>
<!DOCTYPE module PUBLIC
          "-//Puppy Crawl//DTD Check Configuration 1.3//EN"
          "http://www.puppycrawl.com/dtds/configuration_1_3.dtd">

<module name="Checker">
    <property name="charset" value="UTF-8"/>
 <module name="TreeWalker">
    <module name="MethodParamPad"/>
 </module>
</module>
PS D:\CS\test>  java  -jar checkstyle-10.14.2-all.jar -c config.xml  src/RecordPatterns.java
Starting audit...
[ERROR] D:\CS\test\src\RecordPatterns.java:8:20: '(' is preceded with whitespace. [MethodParamPad]
Audit done.
Checkstyle ends with 1 errors.

Describe what you expect in detail.

I want a violation on the record pattern


@nrmancuso
Copy link
Member

We need to make sure that we update the docs to mention that we check record deconstruction patterns.

@nrmancuso nrmancuso moved this from Needs Triage to Todo in Java 21 Language Features Support Jun 11, 2024
mahfouz72 added a commit to mahfouz72/checkstyle that referenced this issue Jun 29, 2024
mahfouz72 added a commit to mahfouz72/checkstyle that referenced this issue Jun 29, 2024
@mahfouz72 mahfouz72 moved this from Todo to In Progress in Java 21 Language Features Support Jun 29, 2024
mahfouz72 added a commit to mahfouz72/checkstyle that referenced this issue Jun 30, 2024
mahfouz72 added a commit to mahfouz72/checkstyle that referenced this issue Jun 30, 2024
mahfouz72 added a commit to mahfouz72/checkstyle that referenced this issue Jun 30, 2024
mahfouz72 added a commit to mahfouz72/checkstyle that referenced this issue Jun 30, 2024
mahfouz72 added a commit to mahfouz72/checkstyle that referenced this issue Jun 30, 2024
mahfouz72 added a commit to mahfouz72/checkstyle that referenced this issue Jun 30, 2024
@github-project-automation github-project-automation bot moved this from In Progress to Done in Java 21 Language Features Support Jul 1, 2024
@github-actions github-actions bot added this to the 10.18.0 milestone Jul 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
No open projects
Development

Successfully merging a pull request may close this issue.

3 participants