module
Noir::TreeSitterKotlinRouteExtractor
Overview
Tree-sitter-backed Kotlin route extractor.
Scope for this first cut: Spring-style annotation routing —
class-level @RequestMapping-family annotations composing with
method-level mapping annotations. Mirrors TreeSitterJavaRouteExtractor
but for Kotlin's distinct AST shape (annotations live in
modifiers, functions use function_declaration, primary
constructors carry DTO fields, etc.).
Covered:
@GetMapping,@PostMapping,@PutMapping,@DeleteMapping,@PatchMapping— each fixes the HTTP verb@RequestMapping— generic; verb frommethod = RequestMethod.X(single or array form), or GET when absent- Class-level mapping annotations contribute a prefix joined
onto the per-method path with exactly one
/separator - Path supplied positionally (
@GetMapping("/x")) or viavalue = "/x"/path = "/x"keyword arguments, including string arrays (value = ["/a", "/b"]) - Multi-line annotations — the grammar eats whitespace for us
Not covered yet (follow-ups):
- Ktor's DSL
routing { get("/x") { ... } }. That's a different authoring style and lives in a separate walker. - Meta-annotations (custom annotations composing
@RequestMapping).
Extended Modules
Defined in:
miniparsers/kotlin_route_extractor_ts.crConstant Summary
-
ANNOTATION_VERBS =
{"GetMapping" => "GET", "PostMapping" => "POST", "PutMapping" => "PUT", "DeleteMapping" => "DELETE", "PatchMapping" => "PATCH", "RequestMapping" => nil} -
Spring mapping annotation names → HTTP verb.
nilmeans look at the annotation'smethod =argument. Same table as the Java extractor for consistency.
Instance Method Summary
- #extract_routes(source : String, string_constants = Hash(String, String).new) : Array(Route)
-
#extract_routes_from(root : LibTreeSitter::TSNode, source : String, string_constants = Hash(String, String).new) : Array(Route)
_from(root, source)— accept a pre-parsed root so the Kotlin Spring analyzer can amortise the parse across multiple extractions on the same file. - #extract_string_constants(source : String) : Hash(String, String)
Instance Method Detail
_from(root, source) — accept a pre-parsed root so the Kotlin
Spring analyzer can amortise the parse across multiple
extractions on the same file. Tree lifetime is the caller's
responsibility.