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

Java14 Full Records Support Check Validation: MethodLengthCheck #8519

Closed
nrmancuso opened this issue Jul 16, 2020 · 1 comment
Closed

Java14 Full Records Support Check Validation: MethodLengthCheck #8519

nrmancuso opened this issue Jul 16, 2020 · 1 comment

Comments

@nrmancuso
Copy link
Member

Child of #8452
Check documentation: https://checkstyle.sourceforge.io/config_sizes.html#MethodLength

From check documentation:
Checks for long methods and constructors.

➜  full-record-grammar /usr/lib/jvm/java-14-openjdk/bin/javac --enable-preview --source 14 TestClass.java
Note: TestClass.java uses preview language features.
Note: Recompile with -Xlint:preview for details.
➜  full-record-grammar cat config.xml    
<?xml version="1.0"?>
<!DOCTYPE module PUBLIC
          "-//Checkstyle//DTD Checkstyle Configuration 1.3//EN"
          "https://checkstyle.org/dtds/configuration_1_3.dtd">
<module name="Checker">
  <module name="TreeWalker">
      <module name="MethodLength">
          <property name="tokens" value="METHOD_DEF,CTOR_DEF"/>
          <property name="max" value="2"/>
      </module>
  </module>
</module>
➜  full-record-grammar cat TestClass.java
class MyTestClass {
    void foo(){ // violation
        System.out.println("test");
        System.out.println("test");
        System.out.println("test");
    }
    MyTestClass() { // violation
        System.out.println("test");
        System.out.println("test");
        System.out.println("test");

    }

}

// ctor
record MyTestRecord() {
    public MyTestRecord(){ // violation
        System.out.println("test");
        System.out.println("test");
        System.out.println("test");
    }

}

//compact ctor
record MyTestRecord2() {
    public MyTestRecord2{ // should be a violation
        System.out.println("test");
        System.out.println("test");
        System.out.println("test");
    }
}

//method
record MyTestRecord3() {
    void foo(){ // violation
        System.out.println("test");
        System.out.println("test");
        System.out.println("test");
    }
}
➜  full-record-grammar java $RUN_LOCALE -jar ~/IdeaProjects/checkstyle/target/checkstyle-8.35-SNAPSHOT-all.jar -c config.xml TestClass.java
Starting audit...
[ERROR] /home/nick/Desktop/full-record-grammar/TestClass.java:2:5: Method length is 5 lines (max allowed is 2). [MethodLength]
[ERROR] /home/nick/Desktop/full-record-grammar/TestClass.java:7:5: Method length is 6 lines (max allowed is 2). [MethodLength]
[ERROR] /home/nick/Desktop/full-record-grammar/TestClass.java:18:5: Method length is 5 lines (max allowed is 2). [MethodLength]
[ERROR] /home/nick/Desktop/full-record-grammar/TestClass.java:37:5: Method length is 5 lines (max allowed is 2). [MethodLength]
Audit done.
Checkstyle ends with 4 errors.

This check works as intended within the body of a record definition, but we need to add support for compact constructors.

@pbludov
Copy link
Member

pbludov commented Aug 8, 2020

fix is merged.

@pbludov pbludov closed this as completed Aug 8, 2020
Java 14 syntax features automation moved this from To do to Done Aug 8, 2020
@pbludov pbludov added the bug label Aug 8, 2020
shiliyu pushed a commit to shiliyu/checkstyle that referenced this issue Sep 1, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
No open projects
Development

No branches or pull requests

2 participants