Skip to content

fix(java-enum): resolve enum methods from enum_body_declarations#984

Open
sahil-mangla wants to merge 1 commit into
DeusData:mainfrom
sahil-mangla:fix/java-enum-extraction
Open

fix(java-enum): resolve enum methods from enum_body_declarations#984
sahil-mangla wants to merge 1 commit into
DeusData:mainfrom
sahil-mangla:fix/java-enum-extraction

Conversation

@sahil-mangla

Copy link
Copy Markdown
Contributor

What does this PR do?

Resolves extraction and calling-edge issues for Java enums that define methods (e.g., isWeekend or label in cp_enum_method_java).

In tree-sitter-java, an enum's methods are declared within an enum_body_declarations block, which is a nested child of enum_body rather than a direct child of the enum declaration itself. Previously:

  • find_class_body resolved only the raw enum_body node.
  • extract_class_methods iterated over this body, encountering constants and separator tokens, but missing the nested enum_body_declarations block. As a result, method definitions were ignored and calling edges failed to resolve.

This change:

  1. Updates find_class_body to correctly scan and inspect the enum_body for nested enum_body_declarations nodes and return them.
  2. Adds enum_body and enum_body_declarations to the list of recognized body containers in push_class_body_children so the AST traverser pushes all method declarations under the correct enum QN namespace.
  3. Complies with the 100-character column format limit in extract_defs.c.

Checklist

  • Every commit is signed off (git commit -s) — required, CI rejects unsigned commits (DCO, see CONTRIBUTING.md)
  • Tests pass locally (make -f Makefile.cbm test)
  • Lint passes (make -f Makefile.cbm lint-ci)
  • New behavior is covered by a test (reproduce-first for bug fixes)

@sahil-mangla sahil-mangla requested a review from DeusData as a code owner July 9, 2026 17:41
@DeusData DeusData added this to the 0.9.1-rc milestone Jul 9, 2026
@DeusData DeusData added bug Something isn't working parsing/quality Graph extraction bugs, false positives, missing edges priority/normal Standard review queue; useful PR with ordinary maintainer urgency. labels Jul 9, 2026
@DeusData

DeusData commented Jul 9, 2026

Copy link
Copy Markdown
Owner

Thanks. I have triaged this as a 0.9.1-rc Java extraction bug fix. Review should verify that enum_body_declarations handling fixes enum methods without changing normal class/interface method extraction or introducing duplicate method definitions.

@DeusData

DeusData commented Jul 9, 2026

Copy link
Copy Markdown
Owner

Thanks for splitting this out of #893 so quickly — exactly the atomic shape we asked for, and the enum_body_declarations analysis matches tree-sitter-java's grammar. One thing missing before merge: a genuine reproduce-first guard. I ran the existing cp_enum_method_java convergence probe on unmodified main and it already PASSES — its assertions (Enum node exists + ≥1 CALLS edge anywhere) are too loose to detect the bug you're fixing, so nothing in CI currently turns red without your change. Please add an extraction-level test that is RED on main and GREEN with this fix — e.g. in tests/test_extraction.c, extract the Day enum fixture and assert isWeekend/label exist as Method definitions (and/or tighten the probe to assert the enum's methods specifically). With that guard in place this merges immediately.

@DeusData

Copy link
Copy Markdown
Owner

Thanks for this, @sahil-mangla — the Java enum-method extraction fix is genuinely good work, and the java_enum_method test is a proper reproduce-first guard (it fails on main without the enum_body_declarations unwrap). I'd happily merge that part quickly.

One blocker before it can land: the PR also carries an undocumented change to the call-resolution coresrc/pipeline/registry.c (+127/−22), restricting resolve_same_module/resolve_name_lookup on receivers (commits e930bd2 + 078de1c). That's a precision-tightening change to CALLS-edge resolution with all-language blast radius, and it's not mentioned in the PR description. Per our atomic-PR policy it needs to be its own PR so its recall-vs-precision impact can be evaluated on the full corpus independently of the enum fix.

Could you split this into two PRs?

  1. The Java enum fixextract_defs.c (enum_body/enum_body_declarations unwrap + enum-name fallback) + tests/test_extraction.c. This is clean and I'll fast-track it.
  2. The registry resolution-tighteningregistry.c + tests/test_registry.c, with a note on what false positive it targets (looks recursion-related) so we can measure edge impact before merging.

Really appreciate the contribution — just want each change reviewable on its own merits.

@sahil-mangla sahil-mangla force-pushed the fix/java-enum-extraction branch from 41f4196 to 3d6a29c Compare July 16, 2026 10:20
Signed-off-by: sahil-mangla <manglasahil2017@gmail.com>
@sahil-mangla sahil-mangla force-pushed the fix/java-enum-extraction branch from 3d6a29c to 4c01d66 Compare July 16, 2026 10:24
@sahil-mangla

Copy link
Copy Markdown
Contributor Author

@DeusData as per requested the PRs are now strictly atomic! with registry fix being its own isolated PR at #1128

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

Labels

bug Something isn't working parsing/quality Graph extraction bugs, false positives, missing edges priority/normal Standard review queue; useful PR with ordinary maintainer urgency.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants