Skip to content

Add ModifiersOrderOperation (java:S1124)#159

Merged
RadikalJin merged 1 commit into
mainfrom
feature/s1124-modifiers-order
Jun 15, 2026
Merged

Add ModifiersOrderOperation (java:S1124)#159
RadikalJin merged 1 commit into
mainfrom
feature/s1124-modifiers-order

Conversation

@RadikalJin

Copy link
Copy Markdown
Member

Implements SonarQube rule java:S1124 — modifiers must appear in the JLS canonical order (public/protected/private, abstract, default, static, final, transient, volatile, synchronized, native, strictfp).

Visits every BodyDeclaration node, extracts keyword modifiers, sorts them by the canonical index, and uses ASTRewrite ListRewrite to replace each out-of-order modifier in-place, leaving annotations at their original positions.

Mirrors SonarJava's ModifiersOrderCheck detection logic (iterate through modifiers against the canonical enum order; report first violation).

Tests cover: static/public swap on methods, final/static and final/public/static on fields, synchronized/static, native/static, volatile/transient, nested-class abstract/static/public reordering, and nested method reordering. Noop cases confirm already-correct orderings and single-modifier declarations are untouched.

Implements SonarQube rule java:S1124 — modifiers must appear in the JLS
canonical order (public/protected/private, abstract, default, static,
final, transient, volatile, synchronized, native, strictfp).

Visits every BodyDeclaration node, extracts keyword modifiers, sorts them
by the canonical index, and uses ASTRewrite ListRewrite to replace each
out-of-order modifier in-place, leaving annotations at their original
positions.

Mirrors SonarJava's ModifiersOrderCheck detection logic (iterate through
modifiers against the canonical enum order; report first violation).

Tests cover: static/public swap on methods, final/static and
final/public/static on fields, synchronized/static, native/static,
volatile/transient, nested-class abstract/static/public reordering, and
nested method reordering. Noop cases confirm already-correct orderings
and single-modifier declarations are untouched.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@RadikalJin RadikalJin merged commit af2cdea into main Jun 15, 2026
@RadikalJin RadikalJin deleted the feature/s1124-modifiers-order branch June 15, 2026 15:27
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.

1 participant