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:
- The recommended order of class members is: Fields → Constructors → Factory methods → Other Methods. -
DeclarationOrder, ConstructorsDeclarationGrouping, OverloadMethodsDeclarationOrder
- Related fields should be grouped together. Ordering fields primarily according to access modifiers or identifier is not required. The same applies to methods. -
DeclarationOrder
- 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. |
|
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:
DeclarationOrder,ConstructorsDeclarationGrouping,OverloadMethodsDeclarationOrderDeclarationOrderChecks to add to
openjdk_checks.xmlTreeWalker-level:
Coverage Gaps
DeclarationOrdertreats all methods as one group.ignoreModifiers="true"allows non-modifier-based ordering, but no check enforces that related fields must actually be grouped together (requires semantic understanding).InnerTypeLastenforces the opposite (nested types at the bottom). No check supports "at the top" or "before first use."Progress Tracker
DeclarationOrder,ConstructorsDeclarationGrouping,OverloadMethodsDeclarationOrderDeclarationOrder