fix(extract): extract Spring routes from Kotlin controllers#566
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #565.
What
Spring MVC routing annotations on Kotlin
@RestControllerclasses were not extracted as routes, while the same annotations on Java controllers worked.Root cause:
try_route_from_annotationresolved the annotation name via thenamefield (ts_node_child_by_field_name(annotation, "name")). tree-sitter-kotlin annotation nodes have nonamefield — the name lives in a nestedtype_identifierunderuser_type/constructor_invocation— so the lookup returned null and every Kotlin route was dropped (0 decorator-source routes). Arguments are likewise carried underconstructor_invocation'svalue_arguments(each wrapped invalue_argument), not Java'sargument_list.Change (
internal/cbm/extract_defs.c)annotation_name_node()— falls back to the Kotlin nested-type_identifiershape when thenamefield is absent (Java path unchanged).annotation_args_node()— resolves Kotlin'svalue_argumentsunderconstructor_invocation.extract_route_path_from_args()— unwrapsvalue_argument(also handles the namedvalue = "/x"form) before reading the path string.No API or pipeline changes.
Verification
Minimal Kotlin + Java controllers indexed with the built binary:
route_method/route_path; Java works.createConnector→POST,getConnectorById→GET /{id},deleteConnector→DELETE /{id}.Added a
handles_spring_kotlinregression test intests/test_edge_types_probe.c.scripts/test.shreports 5652 passed; the single failure is the pre-existingtest_incrementalRSS-budget assertion (environment-dependent, unrelated to this change).Note (separate follow-up)
Class-level
@RequestMappingbase paths are still not merged with method-level paths (this affects Java too — a bare@PostMappingyields path/). I can address that in a separate PR.