Skip to content

Add missing checks to sun_checks.xml: DeclarationOrder, FallThrough, OneStatementPerLine #18559

@vivek-0509

Description

@vivek-0509

The sun_checks.xml configuration file is missing several checks that are required by the Code Conventions for the Java TM Programming Language. These checks already exist in Checkstyle but have not been added to the official Sun configuration.


1. DeclarationOrder - Section 3.1.3

Convention Reference: Section 3.1.3 - Class and Interface Declarations

What the convention states:

The parts of a class or interface declaration should appear in the following order:

  1. Class (static) variables - First public, then protected, then package level, and then private.
  2. Instance variables - First public, then protected, then package level, and then private.
  3. Constructors
  4. Methods

What needs to be done:
Add <module name="DeclarationOrder"/> to sun_checks.xml


2. FallThrough - Section 7.8

Convention Reference: Section 7.8 - switch Statements

What the convention states:

Every time a case falls through (doesn't include a break statement), add a comment where the break statement would normally be. This is shown in the preceding code example with the /* falls through */ comment.

What needs to be done:
Add <module name="FallThrough"/> to sun_checks.xml


3. OneStatementPerLine - Section 7.1

Convention Reference: Section 7.1 - Simple Statements

What the convention states:

Each line should contain at most one statement. Example:

argv++;       // Correct
argc--;       // Correct  
argv++; argc--;       // AVOID!

What needs to be done:
Add <module name="OneStatementPerLine"/> to sun_checks.xml


Proposed Changes

Add the following modules to src/main/resources/sun_checks.xml

<!-- Section 3.1.3 - Class and Interface Declarations -->
<module name="DeclarationOrder"/>

<!-- Section 7.1 - Simple Statements -->
<module name="OneStatementPerLine"/>

<!-- Section 7.8 - switch Statements -->
<module name="FallThrough"/>

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions