Skip to content

fix(extract): extract Spring routes from Kotlin controllers#566

Merged
DeusData merged 1 commit into
DeusData:mainfrom
jsw6701:fix/kotlin-spring-routes
Jun 23, 2026
Merged

fix(extract): extract Spring routes from Kotlin controllers#566
DeusData merged 1 commit into
DeusData:mainfrom
jsw6701:fix/kotlin-spring-routes

Conversation

@jsw6701

@jsw6701 jsw6701 commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

Fixes #565.

What

Spring MVC routing annotations on Kotlin @RestController classes were not extracted as routes, while the same annotations on Java controllers worked.

Root cause: try_route_from_annotation resolved the annotation name via the name field (ts_node_child_by_field_name(annotation, "name")). tree-sitter-kotlin annotation nodes have no name field — the name lives in a nested type_identifier under user_type / constructor_invocation — so the lookup returned null and every Kotlin route was dropped (0 decorator-source routes). Arguments are likewise carried under constructor_invocation's value_arguments (each wrapped in value_argument), not Java's argument_list.

Change (internal/cbm/extract_defs.c)

  • annotation_name_node() — falls back to the Kotlin nested-type_identifier shape when the name field is absent (Java path unchanged).
  • annotation_args_node() — resolves Kotlin's value_arguments under constructor_invocation.
  • extract_route_path_from_args() — unwraps value_argument (also handles the named value = "/x" form) before reading the path string.

No API or pipeline changes.

Verification

Minimal Kotlin + Java controllers indexed with the built binary:

  • Before — Kotlin methods have empty route_method/route_path; Java works.
  • AftercreateConnectorPOST, getConnectorByIdGET /{id}, deleteConnectorDELETE /{id}.

Added a handles_spring_kotlin regression test in tests/test_edge_types_probe.c. scripts/test.sh reports 5652 passed; the single failure is the pre-existing test_incremental RSS-budget assertion (environment-dependent, unrelated to this change).

Note (separate follow-up)

Class-level @RequestMapping base paths are still not merged with method-level paths (this affects Java too — a bare @PostMapping yields path /). I can address that in a separate PR.

try_route_from_annotation read the annotation name via the "name" field
(ts_node_child_by_field_name). tree-sitter-kotlin annotation nodes have no
"name" field: the name lives in a nested type_identifier under (user_type)
or (constructor_invocation (user_type ...)). The lookup returned null, so
every Kotlin @RestController route was dropped (0 decorator-source routes)
while Java worked. Args are likewise under constructor_invocation as
value_arguments (each wrapped in value_argument), not Java argument_list.

Add annotation_name_node()/annotation_args_node() that fall back to the
Kotlin AST shape (Java path unchanged) and unwrap value_argument when
scanning for the route path. Kotlin @GetMapping/@PostMapping/etc. now yield
Route nodes and HANDLES edges. Adds handles_spring_kotlin regression test.

Signed-off-by: jsw6701 <86887824+jsw6701@users.noreply.github.com>
@DeusData DeusData merged commit 879c3cb into DeusData:main Jun 23, 2026
13 checks passed
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.

Spring routes on Kotlin controllers are not extracted (Route nodes empty for @RestController Kotlin classes)

2 participants