Skip to content

fix(extract): extract Kotlin annotations and primary constructor properties - #3848

Closed
nikhilsaxena04 wants to merge 2 commits into
Graphify-Labs:v8from
nikhilsaxena04:fix/kotlin-annotations-3842
Closed

nikhilsaxena04 wants to merge 2 commits into
Graphify-Labs:v8from
nikhilsaxena04:fix/kotlin-annotations-3842

Conversation

@nikhilsaxena04

Copy link
Copy Markdown
Contributor

Problem

Resolves #3842.

The Kotlin AST for annotations nests the annotation name inside user_type or constructor_invocation -> user_type (unlike Java's marker_annotation). As a result, the Kotlin extractor was completely blind to class and function annotations. Additionally, primary constructor parameters containing val/var properties (e.g., class User(val id: Long)) were explicitly skipped, missing field dependencies.

Implementation

  • Adds a _kotlin_annotation_names helper to correctly extract annotation names for Kotlin, handling raw text resolution correctly (using simple names instead of fully-qualified names to prevent dangling nodes).
  • Safely skips use_site_target prefixes like @field: when extracting names.
  • Correctly parses bracketed annotations with multiple targets (e.g., @[Inject VisibleForTesting]).
  • Updates Kotlin class and function blocks to emit references edges with context='attribute' for annotations.
  • Traverses primary_constructor -> class_parameters to extract val/var property dependencies as context='field' edges, along with their associated annotations.

Verification

  • Added 9 new rigorous test cases in test_languages.py covering all the above scenarios (regular annotations, parameterized annotations, use-site targets, multiple bracketed annotations, and primary constructor fields/annotations).
  • Verified all 45 Kotlin AST parsing tests pass perfectly.
  • Verified no regressions in existing Java/Groovy annotation handling.
  • Verified the code passes uv run ruff check . and uv run pyright cleanly.

Co-Authored-By: Antigravity [email protected]

…erties

Resolves Graphify-Labs#3842.

- Adds `_kotlin_annotation_names` helper to correctly extract annotations for Kotlin.
- Emits references edges with context='attribute' for class, function, and property annotations.
- Correctly skips use-site targets like `@field:` when extracting annotation names.
- Correctly parses bracketed annotations with multiple targets (e.g. `@[Inject VisibleForTesting]`).
- Traverses `primary_constructor` to extract `val`/`var` property dependencies as field edges.
- Resolves annotations using simple names to prevent dangling fully-qualified nodes.

Co-Authored-By: Antigravity <[email protected]>

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

Formal verification. No changes could be formally verified in this run.


Graphify review — findings

Adds Kotlin annotation extraction so classes, functions, and properties emit references edges with attribute context for each annotation, via the new _kotlin_annotation_names helper that handles use-site targets, parameterized invocations, and bracketed lists like @[Inject VisibleForTesting]. Also resolves primary-constructor val/var parameter types into field (or generic_arg) reference edges and emits attribute edges for their annotations. Covers the behaviour with new tests spanning class/function/property annotations, parameterized and use-site-targeted forms, and constructor field/generic type resolution.

Worth a look

  • Top-level Kotlin property annotations create dangling edges — graphify/extractors/engine.py:4858 · Escalate · medium
    • agreed by 2 of 2 members but NOT verified (no proof, no reproducing execution) — consensus is not a verdict; needs human review
  • Bracketed annotation list not handled by _kotlin_annotation_names — graphify/extractors/engine.py:752 · Escalate · medium
    • agreed by 2 of 2 members but NOT verified (no proof, no reproducing execution) — consensus is not a verdict; needs human review
Analysis details — impact, health, verification

Impact & health

Graphify review

Impact — 1062 functions depend on the 809 functions this change touches.

Health — this change adds coupling hotspots:

  • new: _extract_generic() — 18 callers, 29 callees
  • new: extract_js() — 87 callers, 4 callees
  • new: extract_xaml() — 19 callers, 17 callees
  • new: extract_objc() — 27 callers, 9 callees
  • new: extract_julia() — 17 callers, 7 callees
  • new: extract_cpp() — 29 callers, 3 callees
  • new: extract_vue() — 10 callers, 7 callees
  • new: walk() — 1 callers, 64 callees
  • …and 9 more — each is listed as a finding

Verification — 1062 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: 1016 function(s) in the blast radius were not formally verified this run

Test selection

Test selection

25 of 301 test file(s) selected (8%) via static blast radius.

  • tests/test_astro_extraction.py — impact
  • tests/test_build.py — impact
  • tests/test_cjs_module_extension.py — impact
  • tests/test_cpp_nested_and_cli.py — impact
  • tests/test_dotnet.py — impact
  • tests/test_extract.py — impact
  • tests/test_extract_php_closures.py — impact
  • tests/test_import_extension_resolution.py — impact
  • tests/test_indirect_call_block_scoped_shadow.py — impact
  • tests/test_indirect_dispatch.py — impact
  • tests/test_indirect_dispatch_assign_return.py — impact
  • tests/test_indirect_dispatch_getattr.py — impact
  • tests/test_js_exported_scalar_bindings.py — impact
  • tests/test_languages.py — impact, changed-test
  • tests/test_multilang.py — impact
  • tests/test_python_underscore_resolution.py — impact
  • tests/test_rationale.py — impact
  • tests/test_ruby_resolution.py — impact
  • tests/test_scala_self_type.py — impact
  • tests/test_swift_computed_properties.py — impact
  • tests/test_swift_protocol_requirements.py — impact
  • tests/test_trailing_newline_not_a_syntax_error.py — impact
  • tests/test_ts_new_expression_calls.py — impact
  • tests/test_typescript_module_extensions.py — impact
  • tests/test_vue_extraction.py — impact

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.

Formal verification

Could not verify: Could not verify \_extract\_generic.

The verifier did not have enough to check \_extract\_generic, 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: parameter `config` is annotated `LanguageConfig` — outside the synthesizable primitive/collection set

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

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

Looks safe to merge — no coupling regressions and no blocking issues, checked against the code graph (not a self-assessment).


Graphify review — findings

Adds Kotlin annotation extraction so @Entity, parameterized (@Table(...)), use-site-targeted (@field:NotNull), and bracketed-list (@[Inject VisibleForTesting]) annotations on classes, functions, and constructor parameters now emit references edges with attribute context, via the new _kotlin_annotation_names helper. Also emits type-reference edges for primary-constructor val/var properties, tagging them field for plain types and generic_arg for type arguments (List<Order>). Covers each case with new tests.

No blocking issues surfaced. 1 lower-confidence candidate did not survive cross-model review.

Analysis details — impact, health, verification

Impact & health

Graphify review

Impact — 1062 functions depend on the 809 functions this change touches.

Health — this change adds coupling hotspots:

  • new: _extract_generic() — 18 callers, 29 callees
  • new: extract_js() — 87 callers, 4 callees
  • new: extract_xaml() — 19 callers, 17 callees
  • new: extract_objc() — 27 callers, 9 callees
  • new: extract_julia() — 17 callers, 7 callees
  • new: extract_cpp() — 29 callers, 3 callees
  • new: extract_vue() — 10 callers, 7 callees
  • new: walk() — 1 callers, 64 callees
  • …and 9 more — each is listed as a finding

Verification — 1062 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: 1016 function(s) in the blast radius were not formally verified this run

Test selection

Test selection

25 of 301 test file(s) selected (8%) via static blast radius.

  • tests/test_astro_extraction.py — impact
  • tests/test_build.py — impact
  • tests/test_cjs_module_extension.py — impact
  • tests/test_cpp_nested_and_cli.py — impact
  • tests/test_dotnet.py — impact
  • tests/test_extract.py — impact
  • tests/test_extract_php_closures.py — impact
  • tests/test_import_extension_resolution.py — impact
  • tests/test_indirect_call_block_scoped_shadow.py — impact
  • tests/test_indirect_dispatch.py — impact
  • tests/test_indirect_dispatch_assign_return.py — impact
  • tests/test_indirect_dispatch_getattr.py — impact
  • tests/test_js_exported_scalar_bindings.py — impact
  • tests/test_languages.py — impact, changed-test
  • tests/test_multilang.py — impact
  • tests/test_python_underscore_resolution.py — impact
  • tests/test_rationale.py — impact
  • tests/test_ruby_resolution.py — impact
  • tests/test_scala_self_type.py — impact
  • tests/test_swift_computed_properties.py — impact
  • tests/test_swift_protocol_requirements.py — impact
  • tests/test_trailing_newline_not_a_syntax_error.py — impact
  • tests/test_ts_new_expression_calls.py — impact
  • tests/test_typescript_module_extensions.py — impact
  • tests/test_vue_extraction.py — impact

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.

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

safishamsi added a commit that referenced this pull request Sep 26, 2026
… test

Polish on #3848: remove the unused mid-file tree_sitter imports (F401)
and add a negative test asserting a bare constructor param without
val/var is not emitted as a field property.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@safishamsi

Copy link
Copy Markdown
Member

Shipped in v0.9.69 (now on PyPI) via an authorship-preserving cherry-pick, so your commit keeps contributor-graph credit. Thanks @nikhilsaxena04! Landed with two small polish edits: dropped the unused test imports and added a negative test (a bare ctor param without val/var is not a field).

Release: https://github.com/Graphify-Labs/graphify/releases/tag/v0.9.69

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.

Kotlin: annotations and primary-constructor properties are not extracted (JPA relationships lost)

2 participants