Skip to content

Add checks for OpenJDK Style §3.4 - Class structure #19624

@aclfe

Description

@aclfe

Parent issue: #19604

Description

Add Checkstyle checks for all rules under §3.4 - Class structure of the OpenJDK Java Style Guidelines v6.

Rules covered

From §3.4 - Class structure:

  1. The recommended order of class members is: Fields → Constructors → Factory methods → Other Methods. - DeclarationOrder, ConstructorsDeclarationGrouping, OverloadMethodsDeclarationOrder
  2. Related fields should be grouped together. Ordering fields primarily according to access modifiers or identifier is not required. The same applies to methods. - DeclarationOrder
  3. Nested types are put at the top of the class or right before it is first used. - No checks available.

Checks to add to openjdk_checks.xml

TreeWalker-level:

<module name="TreeWalker">
  <!-- Class member order: Fields → Constructors → Methods -->
  <module name="DeclarationOrder">
    <!-- Allow ordering by logical grouping rather than access modifiers -->
    <property name="ignoreModifiers" value="true"/>
  </module>

Coverage Gaps

  • Factory methods before other methods: No existing check can identify "factory methods" and enforce they come before other methods. DeclarationOrder treats all methods as one group.
  • Related fields grouped together (semantic grouping): Partial coverage: ignoreModifiers="true" allows non-modifier-based ordering, but no check enforces that related fields must actually be grouped together (requires semantic understanding).
  • Nested types at the top or before first use: No coverage. InnerTypeLast enforces the opposite (nested types at the bottom). No check supports "at the top" or "before first use."

Progress Tracker

Check Rule Coverage PR
DeclarationOrder, ConstructorsDeclarationGrouping, OverloadMethodsDeclarationOrder The recommended order of class members is: Fields → Constructors → Factory Methods → Other Methods Partial. cannot distinguish factory methods from other methods
DeclarationOrder Related fields should be grouped together; ordering by access modifiers or identifier is not required Partial .allows logical grouping but cannot enforce semantic relatedness
(none) Nested types are put at the top of the class or right before first use None. no existing check supports this. InnerTypeLast inforces bottom.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions