Skip to content

fix(extract): emit Java enum constants as nodes with case_of edges#1719

Closed
ivanzhl wants to merge 1 commit into
Graphify-Labs:v8from
ivanzhl:fix/java-enum-constants
Closed

fix(extract): emit Java enum constants as nodes with case_of edges#1719
ivanzhl wants to merge 1 commit into
Graphify-Labs:v8from
ivanzhl:fix/java-enum-constants

Conversation

@ivanzhl

@ivanzhl ivanzhl commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Addresses #1700 (Java only)

Problem

Java enum constants aren't extracted as nodes. The enum type node is created,
but its members (ErrorCode.GAME_DONE) don't exist in the graph, so
"where is this constant defined/used" can't find them. enum_declaration is in
Java's class_types, so the walker recurses into the enum body, but
enum_constant matches no handled type and falls through, dropping the constant.

Fix

Add _java_extra_walk (dispatched for tree_sitter_java) that emits each
enum_constant as a child node with a case_of edge to the enum, mirroring the
existing Swift enum_entry handling.

Before:
NODE ErrorCode
EDGE ErrorCode.java --contains--> ErrorCode

After:
NODE ErrorCode
NODE OK
NODE GAME_DONE
EDGE ErrorCode.java --contains--> ErrorCode
EDGE ErrorCode --case_of--> OK
EDGE ErrorCode --case_of--> GAME_DONE

Note for reviewer

For a constant with an anonymous body (MONDAY { void greet(){} }), the handler
descends into the body and attaches its methods to the constant node rather than
letting them fall to file scope. Without descending, those methods would be dropped. Side effect: it de-collides a
constant's method from a same-named enum method.

Out of scope

  • Kotlin enum entries — same root gap, not addressed here; can follow up separately.
  • Usage edges (isSystem() --references--> SYSTEM) — definitions only.
  • Pre-existing duplicate file --contains--> enum edge (constructor shares the enum's name) — unrelated, untouched.

@safishamsi

Copy link
Copy Markdown
Collaborator

Merged into v8 (cf36d10), authorship preserved — thanks @ivanzhl. Clean fix, mirrors the existing _ruby_extra_walk/_swift_extra_walk pattern. One note from review: the anonymous-body case (MONDAY { void greet(){} }) emits the constant + case_of edge correctly, but the body's methods didn't come through in my probe — not a regression (they weren't captured before), just flagging as a follow-up. This closes the Java half of #1700; the Kotlin half stays open.

@safishamsi safishamsi closed this Jul 8, 2026
safishamsi added a commit that referenced this pull request Jul 8, 2026
Correctness batch since 0.9.9: TS/JS builtin-typed receiver no longer collapses
onto a same-named user symbol (#1726); no cross-language calls edges (#1718);
build_merge ambiguous-alias no longer merges unrelated files (#1713); base-class
stubs tagged with origin_file (#1707); Java enum constants as nodes (#1719);
rebuild recovers from a deleted hook cwd (#1703); per-chunk semantic-cache
checkpoint (#1715); SECURITY.md http-transport doc + GRAPHIFY_MAX_GRAPH_BYTES
tests (#1714, #1722). Nine merged PRs plus #1726.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.

2 participants