Skip to content

SONARJAVA-6431 Centralize Tree.Kind assignments - #5886

Open
aurelien-coet-sonarsource wants to merge 6 commits into
masterfrom
ac/SONARJAVA-6431
Open

SONARJAVA-6431 Centralize Tree.Kind assignments#5886
aurelien-coet-sonarsource wants to merge 6 commits into
masterfrom
ac/SONARJAVA-6431

Conversation

@aurelien-coet-sonarsource

@aurelien-coet-sonarsource aurelien-coet-sonarsource commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Summary by Gitar

  • API enhancements:
    • Added centralized lists CLASS_KINDS and ASSIGNMENT_KINDS to Tree.Kind for cleaner visitor node registration.
  • Refactoring:
    • Replaced explicit lists of class-like and assignment kinds across Java checks and frontend visitors with the new centralized constants.

This will update automatically on new commits.

@hashicorp-vault-sonar-prod

hashicorp-vault-sonar-prod Bot commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

SONARJAVA-6431

return Arrays.asList(
Tree.Kind.CLASS,
Tree.Kind.RECORD,
return ListUtils.concat(Tree.Kind.CLASS_KINDS, Tree.Kind.ASSIGNMENT_KINDS, List.of(

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Bug: ExpressionComplexityCheck now scopes enum/interface bodies

Previously nodesToVisit() and the visitNode/leaveNode/isInsideEquals branches only treated CLASS and RECORD as complexity-reset boundaries; switching to Tree.Kind.CLASS_KINDS additionally treats ENUM, INTERFACE, ANNOTATION_TYPE and IMPLICIT_CLASS as boundaries that push/pop a fresh count/level scope. This changes how S1067 counts operators for expressions inside enum/interface/annotation bodies, so reported issues may differ, yet no test accompanies this behavior change (unlike RedundantNullabilityAnnotationsCheck). Confirm the new scoping is intended and add a test covering an expression inside an enum/interface, or restrict this check to the previous CLASS/RECORD set if the broadening is unintended.

Was this helpful? React with 👍 / 👎

@gitar-bot

gitar-bot Bot commented Aug 5, 2026

Copy link
Copy Markdown
Code Review 👍 Approved with suggestions 0 resolved / 1 findings

Centralizes class-like and assignment kinds into Tree.Kind and updates Java checks and frontend visitors to use them. ExpressionComplexityCheck now scopes enum and interface bodies alongside CLASS and RECORD.

💡 Bug: ExpressionComplexityCheck now scopes enum/interface bodies

📄 java-checks/src/main/java/org/sonar/java/checks/ExpressionComplexityCheck.java:58 📄 java-checks/src/main/java/org/sonar/java/checks/ExpressionComplexityCheck.java:111 📄 java-checks/src/main/java/org/sonar/java/checks/ExpressionComplexityCheck.java:124 📄 java-checks/src/main/java/org/sonar/java/checks/ExpressionComplexityCheck.java:143

Previously nodesToVisit() and the visitNode/leaveNode/isInsideEquals branches only treated CLASS and RECORD as complexity-reset boundaries; switching to Tree.Kind.CLASS_KINDS additionally treats ENUM, INTERFACE, ANNOTATION_TYPE and IMPLICIT_CLASS as boundaries that push/pop a fresh count/level scope. This changes how S1067 counts operators for expressions inside enum/interface/annotation bodies, so reported issues may differ, yet no test accompanies this behavior change (unlike RedundantNullabilityAnnotationsCheck). Confirm the new scoping is intended and add a test covering an expression inside an enum/interface, or restrict this check to the previous CLASS/RECORD set if the broadening is unintended.

🤖 Prompt for agents
Code Review: Centralizes class-like and assignment kinds into Tree.Kind and updates Java checks and frontend visitors to use them. ExpressionComplexityCheck now scopes enum and interface bodies alongside CLASS and RECORD.

1. 💡 Bug: ExpressionComplexityCheck now scopes enum/interface bodies
   Files: java-checks/src/main/java/org/sonar/java/checks/ExpressionComplexityCheck.java:58, java-checks/src/main/java/org/sonar/java/checks/ExpressionComplexityCheck.java:111, java-checks/src/main/java/org/sonar/java/checks/ExpressionComplexityCheck.java:124, java-checks/src/main/java/org/sonar/java/checks/ExpressionComplexityCheck.java:143

   Previously nodesToVisit() and the visitNode/leaveNode/isInsideEquals branches only treated CLASS and RECORD as complexity-reset boundaries; switching to Tree.Kind.CLASS_KINDS additionally treats ENUM, INTERFACE, ANNOTATION_TYPE and IMPLICIT_CLASS as boundaries that push/pop a fresh count/level scope. This changes how S1067 counts operators for expressions inside enum/interface/annotation bodies, so reported issues may differ, yet no test accompanies this behavior change (unlike RedundantNullabilityAnnotationsCheck). Confirm the new scoping is intended and add a test covering an expression inside an enum/interface, or restrict this check to the previous CLASS/RECORD set if the broadening is unintended.

Options

Auto-apply is off → Gitar will not commit updates to this branch.
Display: compact → Showing less information.

Comment with these commands to change the behavior for this request:

Auto-apply Compact
gitar auto-apply:on         
gitar display:verbose         

Was this helpful? React with 👍 / 👎 | Gitar

@sonarqube-next

sonarqube-next Bot commented Aug 5, 2026

Copy link
Copy Markdown

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

✅, but I believe the base branch needs to be ac/SONARJAVA-6430

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.

2 participants