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: InnerTypeLastCheck #8482

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

Java14 Full Records Support Check Validation: InnerTypeLastCheck #8482

nrmancuso opened this issue Jul 15, 2020 · 1 comment
Milestone

Comments

@nrmancuso
Copy link
Member

nrmancuso commented Jul 15, 2020

Child of #8452
Check documentation: https://checkstyle.sourceforge.io/config_design.html#InnerTypeLast

From check documentation:
Checks nested (internal) classes/interfaces are declared at the bottom of the primary (top-level) class after all method and field declarations.

➜  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="InnerTypeLast"/>
  </module>
</module>
➜  full-record-grammar cat TestClass.java
public class TestClass{
    record Test (){
        private static String s; // OK
        record InnerTest1() {}
        public void test() {} // should be violation, method should be declared before inner types.
    }

    public void test() {} // should be violation, method should be declared before inner types.

    record Test3 (){
        private static String s; // ok
        class InnerTest1 {}
        public void test() {} // violation, method should be declared before inner types.
    }

    record Test4 (){
        private static String s; // ok
        record MyInnerRecord(){}
        static Test3 innerRecord = new Test3(); //ok
        public void test() {}// should be a violation, method should be declared before inner types.
    }
    record Test5 (){
        private static String s; // ok
        static Test3 myRecordTest = new Test3(); //ok
        public void test() {} // ok
    }
}%                                                                                                                            ➜  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:13:9: Fields and methods should be before inner classes. [InnerTypeLast]
Audit done.
Checkstyle ends with 1 errors.


We need to add support for record declarations and bodies to this check.

@esilkensen
Copy link
Member

Fix is merged

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
None yet
Development

No branches or pull requests

3 participants