Skip to content

#286: Implement external methods called metric#1285

Merged
yegor256 merged 3 commits into
cqfn:masterfrom
ogluvu-ship-it:fix-issue-286-external-methods-ast
Jul 23, 2026
Merged

#286: Implement external methods called metric#1285
yegor256 merged 3 commits into
cqfn:masterfrom
ogluvu-ship-it:fix-issue-286-external-methods-ast

Conversation

@ogluvu-ship-it

@ogluvu-ship-it ogluvu-ship-it commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

Summary by CodeRabbit

  • New Features
    • Metrics can now be calculated directly from a parsed AST (with continued support for running from source files).
  • Bug Fixes
    • Improved external method call counting so calls to locally defined methods aren’t misclassified.
    • Added correct handling for superclass (super) method invocations.
  • Tests
    • Added new fixtures for local and super method call scenarios.
    • Updated and extended the test suite to use parsed ASTs and added a filepath-based assertion.

@ogluvu-ship-it ogluvu-ship-it changed the title I#286: mplement external methods called metric #286: Implement external methods called metric Jul 17, 2026
@coderabbitai

coderabbitai Bot commented Jul 17, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@ogluvu-ship-it, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 6 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 1c323a2c-aa5e-4928-a125-6617668f415d

📥 Commits

Reviewing files that changed from the base of the PR and between 91b4098 and ac7b1c0.

📒 Files selected for processing (4)
  • aibolit/metrics/halsteadvolume/pom.xml
  • aibolit/metrics/npath/npath.xml
  • aibolit/metrics/npath/pom.xml
  • scripts/ruleset.xml
📝 Walkthrough

Walkthrough

The external method metric now accepts AST or filepath inputs, derives external names from method invocations minus declared methods, and returns an integer count. Tests cover AST construction, filepath compatibility, local calls, super calls, and test module loading.

Changes

External method counting

Layer / File(s) Summary
Metric input and counting logic
aibolit/metrics/external_methods_called/external_methods_called.py
ExternalMethodsCalled.value accepts AST or filepath inputs, while counting uses invocation member names excluding locally declared method names and includes super method invocations.
Metric behavior coverage
test/metrics/external_methods_called/test_external_methods_called.py, test/metrics/external_methods_called/LocalMethodCall.java, test/metrics/external_methods_called/SuperMethodCall.java
Tests use constructed ASTs, retain filepath coverage, and verify local calls are excluded while super calls are counted.
Metric test module loading
test/scripts/test_calculate_metrics.py
The test loader is captured locally before executing the module.

Estimated code review effort: 3 (Moderate) | ~20 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: implementing the external methods called metric.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
aibolit/metrics/external_methods_called/external_methods_called.py (1)

15-18: 🎯 Functional Correctness | 🔵 Trivial | 💤 Low value

Widen the value input type
value accepts non-AST inputs and converts them with build_ast, so the signature should reflect AST | str (or similar) instead of AST.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@aibolit/metrics/external_methods_called/external_methods_called.py` around
lines 15 - 18, Update ExternalMethodsCalled.value to annotate its ast parameter
as accepting both AST instances and source strings (AST | str or the project’s
equivalent input type), matching the existing isinstance conversion and
build_ast handling while preserving the current return behavior.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@aibolit/metrics/external_methods_called/external_methods_called.py`:
- Around line 28-34: Update _external_method_names_called to inspect both
METHOD_INVOCATION and SUPER_METHOD_INVOCATION AST node types, while preserving
the existing local-method filtering and member-name collection behavior.

---

Nitpick comments:
In `@aibolit/metrics/external_methods_called/external_methods_called.py`:
- Around line 15-18: Update ExternalMethodsCalled.value to annotate its ast
parameter as accepting both AST instances and source strings (AST | str or the
project’s equivalent input type), matching the existing isinstance conversion
and build_ast handling while preserving the current return behavior.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 60d4f2cc-0c2a-4452-9daa-110644a1ef6b

📥 Commits

Reviewing files that changed from the base of the PR and between be4499d and cb35141.

📒 Files selected for processing (3)
  • aibolit/metrics/external_methods_called/external_methods_called.py
  • test/metrics/external_methods_called/LocalMethodCall.java
  • test/metrics/external_methods_called/test_external_methods_called.py

Comment thread aibolit/metrics/external_methods_called/external_methods_called.py
@ogluvu-ship-it

Copy link
Copy Markdown
Contributor Author

@yegor256 awaiting approval

@ogluvu-ship-it

Copy link
Copy Markdown
Contributor Author

@yegor256 awaiting approval

@yegor256
yegor256 merged commit c6b01a2 into cqfn:master Jul 23, 2026
14 checks passed
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.

3 participants