Skip to content

feat(engine): capture Java enums, records and annotation types - #703

Merged
vibgrate-team merged 1 commit into
vibgrate:mainfrom
noahkhomer18:feat/372-java-enums-records
Nov 26, 2026
Merged

vibgrate-team merged 1 commit into
vibgrate:mainfrom
noahkhomer18:feat/372-java-enums-records

Conversation

@noahkhomer18

Copy link
Copy Markdown
Contributor

Pull Request

Summary

The JAVA block in src/engine/queries.ts now captures enums, records and annotation types, so vg build gives a status enum, a DTO record or a custom annotation like @Audited its own definition.

  • enum_declaration and record_declaration map to class, matching the C# block and its comment (class is the engine's kind for enum-like types).
  • annotation_type_declaration maps to interface. An @interface declares a type that other code refers to by name and carries no implementation, which is closer to an interface than to a class, and vibgrate has no separate annotation kind.

All three node names exist in the bundled tree-sitter-java grammar, so nothing had to be left out.

A side effect worth knowing: methods declared inside an enum or record were indexed as bare top-level names before, because nothing captured their enclosing type. They are now qualified by it (label becomes Status.label, distanceSquared becomes Point.distanceSquared), the same way methods inside a class already are.

Related issues

Closes #372

Checklist

  • pnpm test passes: 596 files, 5923 tests.
  • pnpm lint is clean: 0 errors. The 5 warnings are in src/code/agent.ts, src/code/vgd-code.test.ts, src/engine/duties.ts and src/engine/haile/adapter.ts, none touched here.
  • pnpm typecheck is clean.
  • Docs updated (README / DOCS / ARCHITECTURE) where behavior changed: no docs list the Java definition kinds, so nothing to change.
  • Determinism preserved: the new test serializes graph.json twice and from a reversed fixture write, and all three are byte-identical.
  • No proprietary or internal references.
  • Commits use Conventional Commits and are signed off.

Tests

New fixture test/fixtures/java-defs/ (an enum with a constant-specific method body, a record with a compact constructor and a method, and an @interface) and test/java-defs.test.ts:

  • every definition with its kind, qualified name, file and line:

    class Point                      src/com/example/defs/Point.java:3
    class Status                     src/com/example/defs/Status.java:3
    interface Audited                src/com/example/defs/Audited.java:8
    method Point.distanceSquared     src/com/example/defs/Point.java:10
    method Status.isActive           src/com/example/defs/Status.java:19
    method Status.label              src/com/example/defs/Status.java:17
    method Status.label              src/com/example/defs/Status.java:5   (ACTIVE's own body)
    
  • graph.json byte-identical across two runs and a reversed write.

The first test fails with the queries.ts change reverted.

vg show through the built CLI (pnpm build, then vg build on a copy of the fixture):

Status  (class)       src/com/example/defs/Status.java:3
Point  (class)        src/com/example/defs/Point.java:3
Audited  (interface)  src/com/example/defs/Audited.java:8

packages/test-solutions/java-spring: 232 Java nodes before, 240 after, nothing lost (compared by kind, qualified name and file). The 8 new ones are its records and nested enums:

class CreateProductRequest, ProductDTO, UpdateProductRequest, UserDTO
class GlobalExceptionHandler.ErrorResponse, GlobalExceptionHandler.ValidationErrorResponse
class Order.OrderStatus, User.UserRole

Notes for reviewers

  • Audited starts at line 8, its @Retention line, not at public @interface on line 10. The annotations are part of the declaration node, and an annotated class starts at its first annotation in the same way, so I kept it consistent.
  • Two things I noticed and left alone, since they are outside this issue:
    • SUSPENDED's label() body (line 11) has no node of its own, before or after this change. It has the same qualified name, file and signature as ACTIVE's body, so the two most likely hash to the same node id and only one is kept.
    • A record's compact constructor (public Point { ... }) is a compact_constructor_declaration, which the block does not capture. Happy to add it here or in a follow-up if you'd like it.

The JAVA block only captured methods, constructors, classes and
interfaces, so a status enum, a DTO record or a custom annotation had no
definition of its own and the methods inside them were indexed as bare
top-level names. Capture enum_declaration and record_declaration as
'class', as the C# block does, and annotation_type_declaration as
'interface'.

Closes vibgrate#372

Signed-off-by: Noah Khomer <108771853+noahkhomer18@users.noreply.github.com>
@vibgrate-team
vibgrate-team merged commit aa84964 into vibgrate:main Nov 26, 2026
1 check passed
@vibgrate-team

Copy link
Copy Markdown
Contributor

Thanks so much @noahkhomer18 — Java enums, records and annotation types showing up in the engine's output is a really nice step forward, and the fixtures and tests made this a pleasure to review. Merged, and we'd love to see more from you!

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.

Enhancement: capture Java enums, records, and annotation types as definitions in vg build

2 participants