refactor: use NESTING_TYPES.has() in getComplexityIncrement for Java and Python#458
Merged
askpt merged 2 commits intoJul 17, 2026
Conversation
…and Python Eliminate duplication between NESTING_TYPES Set and the getComplexityIncrement switch-case in javaAnalyzer.ts and pythonAnalyzer.ts. Previously, each file maintained two lists of the same node types: once in NESTING_TYPES (used to bump nesting level) and again as switch cases in getComplexityIncrement (to return 1 + nesting). This made the two sources easy to get out of sync when adding new constructs. Now getComplexityIncrement checks NESTING_TYPES.has() first — a single O(1) Set lookup — and returns 1 + nesting for all structural-increment nodes. Only the flat and special-case increments remain in the switch. No behavior change; all 175 unit tests pass. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
7 tasks
…20260713-5678cf1bebee9248
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #458 +/- ##
==========================================
- Coverage 81.54% 81.50% -0.05%
==========================================
Files 13 13
Lines 4276 4265 -11
Branches 441 428 -13
==========================================
- Hits 3487 3476 -11
Misses 787 787
Partials 2 2 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Contributor
There was a problem hiding this comment.
Pull request overview
This PR refactors the Java and Python cognitive complexity analyzers to remove duplicated “structural increment” node-type lists by using each analyzer’s existing NESTING_TYPES Set as the single source of truth in getComplexityIncrement().
Changes:
- Java: Replace the structural
switchcases ingetComplexityIncrement()with an earlyNESTING_TYPES.has(node.type)guard. - Python: Replace the structural
switchcases ingetComplexityIncrement()with an earlyNESTING_TYPES.has(node.type)guard. - Update the related doc comments to clarify that structural increments are driven by
NESTING_TYPES.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/metricsAnalyzer/languages/pythonAnalyzer.ts | Uses NESTING_TYPES.has() to handle structural increments in getComplexityIncrement() and updates the method’s documentation accordingly. |
| src/metricsAnalyzer/languages/javaAnalyzer.ts | Uses NESTING_TYPES.has() to handle structural increments in getComplexityIncrement() and updates the method’s documentation accordingly. |
askpt
approved these changes
Jul 17, 2026
askpt
deleted the
repo-assist/improve-nesting-types-increment-20260713-5678cf1bebee9248
branch
July 17, 2026 12:01
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🤖 This is an automated pull request from Repo Assist.
Summary
Removes duplicated node-type listings in
getComplexityIncrement()for the Java and Python analyzers, using the existingNESTING_TYPESstatic Set as the single source of truth.Motivation
Both
javaAnalyzer.tsandpythonAnalyzer.tsmaintained the same list of node types in two places:NESTING_TYPES— aReadonlySet<string>that controls nesting-level bumps for child traversal.getComplexityIncrement()— a switch statement that returns1 + this.nestingfor exactly those same node types.Adding a new construct (e.g. a new loop type) required updating both locations. Missing one would silently produce wrong nesting increments.
Change
Replace the redundant switch cases with a single
NESTING_TYPES.has()guard at the top ofgetComplexityIncrement(). The Set is an O(1) lookup — no performance impact.Java (
javaAnalyzer.ts): eliminates 9 case statements (8 nesting-group cases + the identical separatelambda_expressioncase)Python (
pythonAnalyzer.ts): eliminates 9 case statements (the 9 NESTING_TYPES cases)Only flat increments (
ternary_expression,elif_clause,else_clause,conditional_expression) and special-case increments (binary_expression,boolean_operator) remain in the switch.No behavior change
The
NESTING_TYPESsets are unchanged;getComplexityIncrementreturns identical values for all inputs.Test Status
Warning
Firewall blocked 1 domain
The following domain was blocked by the firewall during workflow execution:
releaseassets.githubusercontent.comSee Network Configuration for more information.
Add this agentic workflows to your repo
To install this agentic workflow, run