-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Closed
Description
Child of #8452
Check documentation: https://checkstyle.sourceforge.io/config_coding.html#DeclarationOrder
From check documentation:
Checks that the parts of a class or interface declaration appear in the order suggested by the Code Conventions for the Java Programming Language
➜ 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="DeclarationOrder"/>
</module>
</module>
➜ full-record-grammar cat TestClass.java
public class TestClass {
public record MyRecord1() {
private static int a;
void m(){}
public MyRecord1(){} // constructor definition in wrong order
private static int b; // instance variable definition in wrong order
}
public record MyRecord2(){
private static int a;
void m(){}
public MyRecord2{} // compact constructor definition in wrong order, should be violation
private static int b; // instance variable definition in wrong order
}
}
➜ 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:5:13: Constructor definition in wrong order. [DeclarationOrder]
[ERROR] /home/nick/Desktop/full-record-grammar/TestClass.java:6:13: Static variable definition in wrong order. [DeclarationOrder]
[ERROR] /home/nick/Desktop/full-record-grammar/TestClass.java:13:9: Static variable definition in wrong order. [DeclarationOrder]
Audit done.
Checkstyle ends with 3 errors.
This check works as intended within the body of a record definition, but we need to add support for compact constructors to this check.