Skip to content

refactor: share findEnclosingTypeName helper between C# and Java analyzers - #654

Merged
askpt merged 1 commit into
mainfrom
repo-assist/refactor-shared-enclosing-type-helper-20260918-138c0ce9c7a8f7f2
Sep 18, 2026
Merged

askpt merged 1 commit into
mainfrom
repo-assist/refactor-shared-enclosing-type-helper-20260918-138c0ce9c7a8f7f2

Conversation

@github-actions

Copy link
Copy Markdown
Contributor

🤖 This pull request was created by Repo Assist, an automated AI assistant.

Summary

Extracts a shared findEnclosingTypeName() helper into complexityHelpers.ts and updates csharpAnalyzer.ts and javaAnalyzer.ts to use it, removing a duplicated "walk up the AST to the enclosing type declaration" pattern.

What was duplicated

Both CSharpMetricsAnalyzer.getEnclosingTypeName() and JavaMetricsAnalyzer.getMethodName() independently walked node.parent until hitting a type-declaration node type (from each analyzer's own TYPE_DECLARATION_TYPES set), then read the name field and substringed it from sourceText. The logic was byte-for-byte identical aside from formatting the returned name at the call site.

This mirrors the duplication already centralized in prior runs for isOutermostInSameOperatorChain, getBinaryLogicalOperator, and hasLabelChild — this was the one remaining "walk up to enclosing type" duplication not yet unified.

Fix

Added findEnclosingTypeName(node, typeDeclarationTypes, sourceText) to complexityHelpers.ts, taking the ReadonlySet<string> of type-declaration node types as a parameter (matching the existing pattern for shared helpers). Both analyzers now call it and format the qualified name (ClassName.methodName) at their call sites. Purely mechanical, behavior-preserving — same node-type sets, same childForFieldName("name") + substring convention, same traversal order.

Trade-offs

None — no behavior change, no new dependencies, three files touched (one new shared helper, two call-site simplifications).

Test Status

npm run compile   ✅ (0 errors)
npm run lint      ✅ (0 warnings)
npm run test:unit ✅ 250 passing, 0 failing

Coverage: 99.26% statements / 96.35% branches / 100% functions / 99.26% lines (thresholds 95/88/97/95 in .c8rc.json — met, and slightly improved vs. baseline 99.2/96.2/100/99.2 since javaAnalyzer.ts is now fully branch-covered by existing tests).

Warning

Firewall blocked 1 domain

The following domain was blocked by the firewall during workflow execution:

  • releaseassets.githubusercontent.com

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "releaseassets.githubusercontent.com"

See Network Configuration for more information.

Generated by 🌈 Repo Assist, see workflow run. Learn more.
Comment /repo-assist to run again

Add this agentic workflow to your repo

To install this agentic workflow, run

gh aw add githubnext/agentics/workflows/repo-assist.md@42c2ab5b4e4c9273534c39259b2e0df7f20f07e9

Both csharpAnalyzer.getEnclosingTypeName() and javaAnalyzer.getMethodName()
independently walked up the AST looking for a type-declaration node type and
reading its name field, duplicating identical parent-walk/childForFieldName/
substring logic. Extracted the shared walk into complexityHelpers.ts as
findEnclosingTypeName(), following the same pattern already used for
isOutermostInSameOperatorChain/getBinaryLogicalOperator/hasLabelChild.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@askpt askpt changed the title [repo-assist] refactor: share findEnclosingTypeName helper between C# and Java analyzers refactor: share findEnclosingTypeName helper between C# and Java analyzers Sep 18, 2026
@codecov

codecov Bot commented Sep 18, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.77%. Comparing base (afaab35) to head (2d84d93).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #654      +/-   ##
==========================================
+ Coverage   98.72%   98.77%   +0.05%     
==========================================
  Files          12       12              
  Lines        3912     3920       +8     
  Branches      441      438       -3     
==========================================
+ Hits         3862     3872      +10     
+ Misses         50       48       -2     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@askpt
askpt marked this pull request as ready for review September 18, 2026 06:19
@askpt
askpt self-requested a review as a code owner September 18, 2026 06:19
Copilot AI balanced review requested due to automatic review settings September 18, 2026 06:19

Copilot AI left a comment

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.

🟢 Approved

The refactor preserves traversal and naming behavior with existing test coverage.

Pull request overview

Centralizes enclosing-type lookup while preserving C# and Java analyzer behavior.

Changes:

  • Adds shared findEnclosingTypeName().
  • Replaces duplicated analyzer traversal logic.
File summaries
File Description
complexityHelpers.ts Adds shared AST helper.
csharpAnalyzer.ts Uses shared helper.
javaAnalyzer.ts Uses shared helper for qualified names.
Review details
  • Files reviewed: 3/3 changed files
  • Comments generated: 0
  • Review effort level: Balanced

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@askpt
askpt merged commit 8eba5d1 into main Sep 18, 2026
25 checks passed
@askpt
askpt deleted the repo-assist/refactor-shared-enclosing-type-helper-20260918-138c0ce9c7a8f7f2 branch September 18, 2026 06:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants