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: UnnecessarySemicolonAfterTypeMemberDeclarationCheck #8476

Closed
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_coding.html#UnnecessarySemicolonAfterTypeMemberDeclaration

From documentation:
Checks if unnecessary semicolon is used after type member declaration.

➜  full-record-grammar /usr/lib/jvm/java-14-openjdk/bin/javac --enable-preview --source 14 MyRecord.java
Note: MyRecord.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="UnnecessarySemicolonAfterTypeMemberDeclaration"/>
  </module>
</module>
➜  full-record-grammar cat MyRecord.java
 public record MyRecord() {
     ; // violation, standalone semicolon
     static {}; // violation, extra semicolon after init block
     static {}; // violation, extra semicolon after static init block
     public MyRecord{}; // violation, extra semicolon after compact constructor definition
     public MyRecord(Object o){this();}; // violation, extra semicolon after constructor definition
     void method() {}; // violation, extra semicolon after method definition
     static int field = 10;; // violation, extra semicolon after field declaration

     static {
         ; // no violation, it is empty statement inside init block
     }

     static {
         ; // no violation, it is empty statement inside static init block
     }

     void anotherMethod() {
         ; // no violation, it is empty statement
         if(true); // no violation, it is empty statement
     }
}; // ok, this check does not apply to outer types


➜  full-record-grammar java $RUN_LOCALE -jar ~/IdeaProjects/checkstyle/target/checkstyle-8.35-SNAPSHOT-all.jar -c config.xml MyRecord.java
Starting audit...
[ERROR] /home/nick/Desktop/full-record-grammar/MyRecord.java:3:15: Unnecessary semicolon. [UnnecessarySemicolonAfterTypeMemberDeclaration]
[ERROR] /home/nick/Desktop/full-record-grammar/MyRecord.java:4:15: Unnecessary semicolon. [UnnecessarySemicolonAfterTypeMemberDeclaration]
[ERROR] /home/nick/Desktop/full-record-grammar/MyRecord.java:6:40: Unnecessary semicolon. [UnnecessarySemicolonAfterTypeMemberDeclaration]
[ERROR] /home/nick/Desktop/full-record-grammar/MyRecord.java:7:22: Unnecessary semicolon. [UnnecessarySemicolonAfterTypeMemberDeclaration]
[ERROR] /home/nick/Desktop/full-record-grammar/MyRecord.java:8:28: Unnecessary semicolon. [UnnecessarySemicolonAfterTypeMemberDeclaration]
Audit done.
Checkstyle ends with 5 errors.

So, this check works in the body of record definitions, but does not work on compact constructors(line #5). We need to add support for compact constructors to this check.

@pbludov pbludov added the bug label Aug 20, 2020
nrmancuso added a commit to nrmancuso/checkstyle that referenced this issue Aug 21, 2020
esilkensen pushed a commit that referenced this issue Aug 22, 2020
@esilkensen esilkensen added this to the 8.36 milestone Aug 22, 2020
@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