Skip to content

fix(extract): resolve Java/Kotlin imports and calls across the JVM (#4874) - #4879

Closed
Deepjyoti-Sarmah wants to merge 5 commits into
Graphify-Labs:v8from
Deepjyoti-Sarmah:fix/4874-jvm-resolution
Closed

Deepjyoti-Sarmah wants to merge 5 commits into
Graphify-Labs:v8from
Deepjyoti-Sarmah:fix/4874-jvm-resolution

Conversation

@Deepjyoti-Sarmah

Copy link
Copy Markdown
Contributor

Summary

Java and Kotlin share package names, class names, and call sites. Graphify built its cross-file type index from one extension at a time, so each language could not see the other:

before
KotlinUser.kt --imports--> Logger.java              (file node)
JavaUser.java --imports--> com.example.ui.BaseScreen (source-less stub)
JavaUser     --inherits--> com.example.ui.BaseScreen (source-less stub)
KotlinUser.run() --/--> Logger.info()

after
KotlinUser.kt --imports--> Logger      (class node)
JavaUser.java --imports--> BaseScreen  (class node)
JavaUser     --inherits--> BaseScreen  (class node)
KotlinUser.run() --calls--> Logger.info()

This PR builds one JVM-wide package and type index and uses it before the shared call-evidence pass runs. That gives imports, inheritance, references, and member calls one place to resolve the same namespace.

Closes #4874.

What does this PR do?

  • Adds _jvm_package_name, _jvm_imports_by_file, and _resolve_jvm_references in graphify/extract.py.
  • Indexes sourced Java and Kotlin type nodes by (package, type name).
  • Repoints Java and Kotlin import, inheritance, and reference edges only when the written FQN names exactly one sourced type.
  • Keeps file-level import edges where they already exist, so affected <File> still reaches importers.
  • Lets _resolve_kotlin_member_calls accept JVM receiver types instead of only .kt and .kts files.
  • Leaves external imports on their stubs. A bare or same-named local class is never chosen.
  • Adds a regression suite that uses the issue's four-file project plus external, ambiguous, and non-JVM controls.

Type of change

  • Bug fix
  • New feature
  • Documentation
  • Tests or CI
  • Refactor
  • Security fix

Evidence

Before: affected "Logger" returned only JavaUser.java. affected "BaseScreen" returned only KotlinUser.kt.

After:

affected "Logger"
  KotlinUser.kt [imports]
  JavaUser.java [imports]
  .run() [calls] JavaUser.java
  .run() [calls] KotlinUser.kt

affected "BaseScreen"
  KotlinUser.kt [imports]
  JavaUser.java [imports]
  JavaUser [inherits]
  KotlinUser [inherits]

The regression suite is 9 tests:

tests/test_4874_jvm_resolution.py    9 passed

Full suite:

8975 passed, 17 skipped, 1 xfailed in 510.20s

Verification & Invariants

The invariant: if a Java or Kotlin file imports a type that exists in the scanned corpus, and exactly one sourced declaration matches the written package and type name, the edge must reach that declaration node. If the candidate is missing or ambiguous, the reference stays unresolved.

  • Read the CONTRIBUTING.md guide.
  • Reproduced the issue on clean 0.9.97 (0a8cd4e1) before changing code.
  • Made the smallest fix that covers both directions of the JVM namespace.
  • Added a regression test for each failure and for the controls.
  • Kept the PR description synchronized with the final implementation.
  • Documented limitations below.

The exact FQN is the only key used. Source-less stubs are not candidates, and two candidates produce no edge. That keeps these existing behaviours:

  • org.springframework.stereotype.Component does not bind to a local Component.
  • a.Logger and b.Logger are separated by the import package.
  • A Kotlin call cannot bind to a same-named Python class.

No AST cache schema changes. Resolution runs on every extraction, so a full rebuild is enough to heal an existing graph.

Known limitations:

  • Nested JVM types are not indexed as package.Outer.Inner yet.
  • The shared index reads this run's per_file results. Unchanged JVM declarations still need to be added through resolution_context_nodes for warm updates to resolve exactly like a cold build.
  • Java package and import facts are read from source with a small regex instead of a second tree-sitter parse. The tests cover the normal declaration forms, not every legal Java formatting variant.

How was this tested?

PYTHONPATH=. .venv/bin/python -m pytest -q tests/test_4874_jvm_resolution.py
9 passed

PYTHONPATH=. .venv/bin/python -m pytest -q
8975 passed, 17 skipped, 1 xfailed in 510.20s

graphify update <fixture>
graphify affected Logger --depth 2
graphify affected BaseScreen --depth 2

The CLI output matches the expected result in #4874.

Merge Danger

Door: two-way. Reverting the branch restores the previous edges, and no persisted schema or cache format changes.

Blast Radius: resolver. Mixed Java/Kotlin repositories get new class-level edges. Single-language repositories and non-JVM languages keep their existing behaviour.

A graph built before this change may keep its old edges until a full rebuild. A warm --update is not guaranteed to repair it.

Graphify-specific checklist

  • I updated generated skill artifacts (uv run python -m tools.skillgen --bless) when changing their source fragments.
  • I confirmed that AST/structural extraction remains deterministic (no ambient state dependencies like ENV variables).
  • I reviewed changes for security implications (no unsafe interpolation into shell/Python).
  • I confirmed no API keys or local-only graph data are included.
  • I disclosed AI authorship in my commit messages. The commit trailers still need this before merge.

@github-actions github-actions Bot added the contributor Pull request from a returning community contributor label Oct 30, 2026
@github-actions

Copy link
Copy Markdown

Thanks for the pull request, @Deepjyoti-Sarmah. A maintainer will review it soon.

Want to talk it through while it is in review? Come join us on our Discord server. For longer-form discussion there is also GitHub Discussions.

A couple of things that speed up review: make sure the test suite passes on Python 3.10 and 3.13, and that the change keeps extraction deterministic.

@graphify-labs graphify-labs 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.

Graphify reviewed this change.

Worth a look — the grounded gate found no coupling regressions or blocking issues, but 2 advisory finding(s) below merit a look before merge.

Not checked: tests were not run; formal verification proved 0 of 2 changed function(s) (1 sampled, not proven, 1 not verified).

Formal verification. PR-changed functions: 1/2 verified (0 proven, 1 may-equivalent, 0 distinguished) · 1 not verified (1 vacuous).

Not verified on this run: \_resolve\_kotlin\_member\_calls (vacuous: never exercised).


Graphify review — findings

Adds a JVM-wide resolution pass, _resolve_jvm_references, that indexes Java and Kotlin type nodes by package-qualified name and repoints imports, inherits, extends, implements and references edges to the declaring class. This lets Kotlin reach Java classes and Java reach Kotlin classes, and it only repoints when the written name matches exactly one sourced type. Ambiguous or unmatched names are left as they were, and the pass keeps the file-level import edge while adding a class-level one, so the duplicate-import risk lands on the Kotlin resolver that runs afterwards. Widens the Kotlin member-call class index to cover any JVM source file instead of just .kt/.kts, so Kotlin calls can bind to Java static methods. A class name that was previously unique to Kotlin can now collide with a Java class and become ambiguous. Adds tests/test_4874_jvm_resolution.py, which builds the issue's four-file Java/Kotlin project and checks that imports, inheritance and affected reach the class nodes, with controls for external imports, same-named classes across packages, and non-JVM definitions.

Worth a look

  • Import edges are duplicated when the Kotlin import resolver runs after the JVM pass — graphify/extract.py:6980 · Escalate · medium
    • NOT verified (no proof, no reproducing execution) — needs human review
  • Kotlin member-call class index now includes Java classes, making previously-unique Kotlin classes ambiguous — graphify/extract.py:7807 · Escalate · medium
    • NOT verified (no proof, no reproducing execution) — needs human review
Analysis details — impact, health, verification

Impact & health

Graphify review

Impact — 3381 functions depend on the 362 functions this change touches.

Health — this change adds coupling hotspots:

  • worse: extract() — 1055 callers, 63 callees

Verification — 3381 functions in the blast radius were not formally verified this run (proofs are advisory here).

Gate & verification

graphify gate

PASS — objectively clean (no health regressions, tests not run — proofs not run this pass (advisory)). Grounded, not self-assessed.

Advisory (not blocking):

  • verification_scope: 3126 function(s) in the blast radius were not formally verified this run

Test selection

Test selection

222 of 470 test file(s) selected (47%) via static blast radius.

  • tests/test_4874_jvm_resolution.py — impact, changed-test
  • tests/test_affected_overrides.py — impact
  • tests/test_astro_extraction.py — impact
  • tests/test_astro_import_ids.py — impact
  • tests/test_blade_extractor.py — impact
  • tests/test_build.py — impact
  • tests/test_builtin_global_type_refs.py — impact
  • tests/test_c_include_resolution.py — impact
  • tests/test_cache.py — impact
  • tests/test_case_sensitive_resolution.py — impact
  • tests/test_cjs_module_extension.py — impact
  • tests/test_cobol_extractor.py — impact
  • tests/test_cpp_method_declarations.py — impact
  • tests/test_cpp_nested_and_cli.py — impact
  • tests/test_cpp_objc_cross_file_calls.py — impact
  • tests/test_cpp_template_type_params.py — impact
  • tests/test_cpp_type_alias.py — impact
  • tests/test_cross_extension_reexport_self_cycle.py — impact
  • tests/test_cross_language_call_resolution.py — impact
  • tests/test_cross_repo_external_call_guards.py — impact
  • tests/test_cross_repo_member_calls.py — impact
  • tests/test_csharp_call_site_generic_args.py — impact
  • tests/test_csharp_delegate_declarations.py — impact
  • tests/test_csharp_enum_members.py — impact
  • tests/test_csharp_field_generic_args.py — impact
  • tests/test_csharp_foreach_loop_variable.py — impact
  • tests/test_csharp_generic_callsites.py — impact
  • tests/test_csharp_interface_dispatch.py — impact
  • tests/test_csharp_member_calls.py — impact
  • tests/test_csharp_member_chain_calls.py — impact
  • tests/test_csharp_member_nodes.py — impact
  • tests/test_csharp_object_creation.py — impact
  • tests/test_csharp_overloads.py — impact
  • tests/test_csharp_partial_classes.py — impact
  • tests/test_csharp_tuple_type_refs.py — impact
  • tests/test_csharp_type_resolution.py — impact
  • tests/test_csharp_underscore_collisions.py — impact
  • tests/test_csharp_var_call_return_type.py — impact
  • tests/test_csharp_verbatim_interpolation.py — impact
  • tests/test_definition_file_portability.py — impact
  • tests/test_detect.py — impact
  • tests/test_dotnet.py — impact
  • tests/test_duplicate_annotation_edges.py — impact
  • tests/test_ejs_extractor.py — impact
  • tests/test_elixir_defdelegate.py — impact
  • tests/test_elixir_import_resolution.py — impact
  • tests/test_elixir_keyword_def_calls.py — impact
  • tests/test_elixir_qualified_calls.py — impact
  • tests/test_elixir_unqualified_call_scope.py — impact
  • tests/test_erlang_extractor.py — impact
  • … and 172 more

Selection is safe under the controlled-regression assumption; always-run tests + a periodic full run are the backstops. Advisory — it never changes the check verdict.

Docs that may be stale (advisory)

Formal verification

Could not verify: Could not verify \_resolve\_kotlin\_member\_calls.

The verifier did not have enough to check \_resolve\_kotlin\_member\_calls, so it is saying so rather than guessing. No false assurance is the whole point.

Guarantee: No guarantee either way, this is an honest abstention, not a pass.

Note: Reason: no capturable inputs from the test suite; property tier: non-vacuity: domain too small (only 1 distinct inputs exercised, need 3) — 'no divergence' would be near-vacuous

No difference found (not proven): No behavior difference found in extract (not a proof).

The verifier ran both versions of extract on many inputs and saw identical behavior every time. Strong evidence the change is safe, but evidence, not a proof.

Guarantee: Empirical: differential testing (both versions run on many generated inputs). A divergence on an untested input remains possible, so this is 'no counterexample found', not 'proven equivalent'.

Note: An input the sampler did not try could still differ.

· 1 more finding(s) on lines outside this diff (see the check run).

@safishamsi

Copy link
Copy Markdown
Member

Landed in v0.9.100, now on PyPI (pip install graphifyy==0.9.100). Java and Kotlin imports, extends/implements and member calls resolve across files and languages. Thanks for the fix, @Deepjyoti-Sarmah.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

contributor Pull request from a returning community contributor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Java/Kotlin imports do not resolve to the class node, so affected silently omits dependents

2 participants