Skip to content

feat: Add Java language support - #53

Open
jhouserizer wants to merge 1 commit into
NanoNets:mainfrom
jhouserizer:feat/java-language-support
Open

feat: Add Java language support#53
jhouserizer wants to merge 1 commit into
NanoNets:mainfrom
jhouserizer:feat/java-language-support

Conversation

@jhouserizer

@jhouserizer jhouserizer commented Aug 5, 2026

Copy link
Copy Markdown

Adds tree-sitter-java (v0.21.0, peer-compatible with tree-sitter@0.21.x) and implements Java extraction in the Tier-1 code graph, bringing Java to parity with the existing TypeScript/Python/Go support.

What's supported

Definitions (nodes)

  • class, interface, record, enum, and @interface (annotation type) declarations
    • recordclass kind; @interfaceinterface kind
  • method and constructor declarations, including interface/abstract methods with no body and annotation elements (String value() default "";)

Edges

  • Heritage: extends (superclass) + implements (super_interfaces) on classes; extends (extends_interfaces) on interfaces; implements on enums
  • Calls: method_invocation with receiver resolution via this, this.x, bare identifiers, and field_access
  • Imports: import_declaration (scoped_identifier path, incl. wildcard .* and static imports)
  • Contains: structural file → type → method hierarchy

Bindings (receiver-type resolution)

  • Fields, local variables, parameters, varargs (Foo... args), try-with-resources, enhanced-for loop variables, and catch parameters
  • var / new X() initializer fallback when no type annotation is present
  • generic_type and array_type unwrapping to bare names (com.example.Base<Bar>Base; Foo[]Foo)

Visibility: public modifier → exported: true (matching the existing C#/TS rule)

Resolution: JDK collection/utility types (List, Map, String, Exception, …) added to the builtin-container blocklist so their methods never wire to repo symbols; bare Java calls search method kind (Java has no function kind)

Scopes: pom.xml, build.gradle, and build.gradle.kts project markers

Verification

Tests

  • 19 Java tests added in test/graph-java.test.ts covering classes/interfaces/enums/records, methods/constructors/visibility, heritage edges (class/interface/enum/annotation/generic/scoped-generic), call edges (member + receiver resolution, bare/static calls, this-qualified in enum/interface methods), import edges (incl. wildcard), contains edges, varargs, try-with-resources, enhanced-for, and catch parameter binding
  • All pre-existing tests / language support pass successfully

End-to-end on spring-framework and quartz-scheduler (large/modest sized popular Java repos)

Built the graph for spring-projects/spring-framework (9,192 .java files) end-to-end:

Metric Value
Files parsed 9,192
Parse errors 0
Nodes 121,316
Edges 303,946
Call edges (all resolved) 100,866
Extends resolved 3,760 / 4,734
Implements resolved 3,484 / 4,961
Nested classes captured 24,787
Annotation types (@interface) captured as interface kind

Unresolved extends/implements targets are external JDK types (RuntimeException, Exception, Serializable, …) — expected and correct. graft ask, graft skeleton, and graft map all return correct, useful results on the generated graph.

Files changed

File What
package.json / package-lock.json tree-sitter-java@^0.21.0 dependency
src/graph/extract.ts Language type, languageOf, JAVA_KINDS, GRAMMARS, describeJava, heritageEdges (java branch), calleeName (java branch), javaReceiver, isImport, importSpecifier, javaExported, javaTypeName
src/graph/bindings.ts defName, isClassNode, handleJava dispatch, handleJava, javaTypeName, javaNewTypeName
src/graph/types.ts Kind type comments updated for Java
src/graph/scopes.ts pom.xml + build.gradle + build.gradle.kts project markers
src/graph/resolve.ts Java builtin container types; bare Java calls search method kind
test/graph-java.test.ts 19 test cases (new file)

Notes

  • One peer dependency added (tree-sitter-java), version-pinned to ^0.21.0 for tree-sitter@0.21.x compatibility.
  • No changes to the existing TS/Python/Go paths — the Java branches are additive, dispatched on ctx.lang === "java".
  • The javaTypeName helper is duplicated across extract.ts and bindings.ts (not imported) per the existing no-value-import-of-extract rule that keeps bindings.ts free of a value import on extract.ts.

Adds tree-sitter-java (v0.21.0, peer-compatible with tree-sitter@0.21.x) and
implements Java extraction in the Tier-1 code graph.

Supported constructs:
- class, interface, record, enum, annotation type declarations
  (record -> class kind; @interface -> interface kind)
- method, constructor, annotation element declarations
  (interface/abstract methods with no body)
- superclass (extends) + super_interfaces (implements) heritage edges
- extends_interfaces on interfaces (extends -> interface edges)
- implements on enums (super_interfaces only, no extends)
- import_declaration imports (scoped_identifier path, incl. wildcard `.*`)
- method_invocation calls with member_access / field_access / this resolution
- visibility detection (public modifier = exported)
- field, local variable, parameter, varargs, try-with-resources, enhanced-for,
  and catch parameter type bindings (incl. var/new X() fallback)
- generic_type and array_type unwrapping for bare type-name extraction
  (com.example.Base<Bar> -> Base; Foo[] -> Foo)
- JDK collection / utility types in the builtin-container blocklist
  (List, Map, String, etc.) so their methods never wire to repo symbols
- build.gradle.kts scope marker (Kotlin-DSL Gradle) alongside pom.xml /
  build.gradle

Files changed:
- package.json: tree-sitter-java@^0.21.0 dependency
- src/graph/extract.ts: Language type, languageOf, JAVA_KINDS, GRAMMARS,
  describeJava, heritageEdges (java branch), calleeName (java branch),
  javaReceiver, isImport, importSpecifier, javaExported, javaTypeName
- src/graph/bindings.ts: defName, isClassNode, handleJava dispatch,
  handleJava, javaTypeName, javaNewTypeName
- src/graph/types.ts: Kind type comments updated for Java
- src/graph/scopes.ts: pom.xml + build.gradle + build.gradle.kts project markers
- src/graph/resolve.ts: Java builtin container types; bare Java calls search
  method kind (Java has no function kind)
- test/graph-java.test.ts: 19 test cases covering classes/interfaces/enums/
  records, methods/constructors/visibility, heritage edges (class/interface/
  enum/annotation/generic/scoped-generic), call edges (member + receiver
  resolution, bare/static calls, this-qualified in enum/interface methods),
  import edges (incl. wildcard), contains edges, varargs, try-with-resources,
  enhanced-for, catch parameter binding

Verified: 538/539 tests pass on this repo (the 1 failure is a pre-existing
flaky lock-release test unrelated to this change). TypeScript build clean.
Tested end-to-end on spring-framework (9,192 .java files): 121,316 nodes,
303,946 edges, 100,866 call edges all resolved, 0 parse errors.
@jhouserizer
jhouserizer force-pushed the feat/java-language-support branch from d697cce to 22e493b Compare August 5, 2026 14:47
@tdel

tdel commented Aug 9, 2026

Copy link
Copy Markdown

This PR is working without any errors for me. Thanks !

@tdel

tdel commented Aug 11, 2026

Copy link
Copy Markdown

Can you update this PR and resolved conflicts ?

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