Skip to content

[java] New rule: CStyleArrayDeclaration - #7031

Merged
UncleOwen merged 8 commits into
mainfrom
copilot/java-array-type-style-rule
Sep 8, 2026
Merged

UncleOwen merged 8 commits into
mainfrom
copilot/java-array-type-style-rule

Conversation

Copilot AI commented Sep 4, 2026 •

Copy link
Copy Markdown
Contributor

This adds a Java codestyle rule to enforce the preferred array declaration style: int[] values instead of the C-style int values[]. The rule covers both field/variable declarations and array-returning method declarations.

  • Summary

    • Enforces Java-style array declarations in Java code.
    • Flags C-style declarations in both variable/field and method return positions.
  • Changes

    • Added ArrayTypeStyle to the Java codestyle ruleset.
    • Implemented the rule as an XPath-based check that matches ArrayDimensions on VariableId and MethodDeclaration.
    • Registered the rule metadata and documentation entry in the codestyle ruleset.
    • Added focused regression tests covering valid Java-style declarations and invalid C-style declarations.
  • Example

class Numbers {
    double doubles[];      // bad
    int[] ints;            // good

    double getDoubles()[] { // bad
        return new double[] { 1.0 };
    }

    int[] getInts() {      // good
        return new int[] { 1 };
    }
}

Copilot AI linked an issue Sep 4, 2026 that may be closed by this pull request
Copilot AI changed the title [WIP] Add new rule for array type style in Java Add ArrayTypeStyle Java codestyle rule Sep 4, 2026
Copilot AI requested a review from zbynek September 4, 2026 18:18
@zbynek
zbynek marked this pull request as ready for review September 4, 2026 18:23
@pmd-actions-helper

pmd-actions-helper Bot commented Sep 4, 2026 •

Copy link
Copy Markdown
Contributor

Documentation Preview

Compared to main:
This changeset changes 0 violations,
introduces 850 new violations, 0 new errors and 0 new configuration errors,
removes 0 violations, 16 errors and 9 configuration errors.
There are 0 changed duplications, 0 new duplications and 0 removed duplications.
There are 0 changed CPD errors, 0 new CPD errors and 0 removed CPD errors.

Regression Tester Report

(comment created at 2026-09-08 08:14:21+00:00 for f45ad4e)

@zbynek zbynek changed the title Add ArrayTypeStyle Java codestyle rule [java] New rule: ArrayTypeStyle Sep 4, 2026

@UncleOwen UncleOwen left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not a fan of the name. When I first saw the name, I didn't know, what this rule was about.

Maybe do what IntelliJ does instead? https://www.jetbrains.com/help/inspectopedia/CStyleArrayDeclaration.html

@UncleOwen

Copy link
Copy Markdown
Member

And again, changelog :)

@zbynek zbynek changed the title [java] New rule: ArrayTypeStyle [java] New rule: CStyleArrayDeclaration Sep 5, 2026
@zbynek
zbynek force-pushed the copilot/java-array-type-style-rule branch from 88b9376 to 236830a Compare September 6, 2026 23:56
@zbynek
zbynek force-pushed the copilot/java-array-type-style-rule branch from 236830a to 23616a7 Compare September 7, 2026 06:10

@UncleOwen UncleOwen left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@UncleOwen UncleOwen added this to the 7.28.0 milestone Sep 8, 2026
@UncleOwen
UncleOwen merged commit 908c77b into main Sep 8, 2026
22 checks passed
@UncleOwen
UncleOwen deleted the copilot/java-array-type-style-rule branch September 8, 2026 10:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[java] New rule: CStyleArrayDeclaration

3 participants