module
Noir::TreeSitterJaxRsExtractor
Overview
Tree-sitter-backed JAX-RS / Jakarta REST extractor.
Walks @Path resource classes and emits one Endpoint-shaped
Route per HTTP-method-annotated method. Recognises:
- Class-level
@ServerEndpoint("/x")— surfaced asGETwithprotocol = "ws". - Application-level
@ApplicationPath("/api")for analyzer adapters that need to prefix resource routes. - Class-level
@Path("/x")— joined onto each method's path (or@Path("/sub")if the method has one). - Verb annotations:
@GET,@POST,@PUT,@DELETE,@PATCH,@HEAD,@OPTIONS. @Consumes(MediaType.APPLICATION_*)at class or method level to set the body parameter format. Method-level wins.- Parameter annotations:
@PathParam(skipped — URL carries it),@QueryParam,@HeaderParam,@CookieParam,@FormParam, plus@DefaultValue("x")modifier. @BeanParam— expands the bean class's JAX-RS-annotated fields as parameters with the right param_type, looked up viaNoir::TreeSitterJavaDtoIndex-style cross-file resolution.- Un-annotated, non-primitive parameters — treated as the
request body and expanded against a caller-supplied DTO
index (same pipeline as Spring's
@RequestBody).
Out of scope for this first cut: meta-annotations,
@MatrixParam, @Context (always skipped — framework
injection, not user input).
Extended Modules
Defined in:
miniparsers/jaxrs_extractor_ts.crConstant Summary
-
HTTP_VERB_ANNOTATIONS =
{"GET" => "GET", "POST" => "POST", "PUT" => "PUT", "DELETE" => "DELETE", "PATCH" => "PATCH", "HEAD" => "HEAD", "OPTIONS" => "OPTIONS"} -
JAX-RS HTTP-method annotations. Simple names are matched; the walker normalises any package-qualified prefix to the trailing segment.
-
PARAM_ANNOTATION_FORMAT =
{"QueryParam" => "query", "HeaderParam" => "header", "CookieParam" => "cookie", "FormParam" => "form", "RestQuery" => "query", "RestHeader" => "header", "RestCookie" => "cookie", "RestForm" => "form"} -
Both standard JAX-RS names and Quarkus's
@Rest*aliases map to the same param formats. Listing both here keeps the Quarkus analyzer a thin detector layer on top of this extractor. -
PATH_PARAM_ANNOTATIONS =
Set {"PathParam", "RestPath"} -
@PathParamskip-list — Quarkus's@RestPathis a drop-in alias for the same role. Both are URL-carried and never emitted as request parameters. -
PRIMITIVE_TYPES =
Set {"boolean", "byte", "char", "short", "int", "long", "float", "double", "void", "string", "object", "integer", "character"} -
Java primitive type names (lowercased). Anything else with no parameter annotation gets treated as a request-body DTO.
Instance Method Summary
- #extract_application_path(source : String) : String | Nil
- #extract_application_path_from(root : LibTreeSitter::TSNode, source : String) : String | Nil
-
#extract_bean_fields(source : String) : Hash(String, Array(Param))
Read JAX-RS-annotated fields (
@QueryParam,@HeaderParam, ...) from every class in the file as{class_name => Params}. - #extract_class_names(source : String) : Array(String)
-
#extract_routes(source : String, dto_index : Hash(String, Array(TreeSitterJavaParameterExtractor::FieldInfo)) = {} of String => Array(TreeSitterJavaParameterExtractor::FieldInfo), bean_index : Hash(String, Array(Param)) = {} of String => Array(Param), subresource_sources : Hash(String, SourceEntry) = {} of String => SourceEntry, *, include_callees : Bool = false) : Array(Route)
Public entry point — walks
sourceand returns oneRouteper JAX-RS endpoint defined inpath's file. -
#extract_routes_from(root : LibTreeSitter::TSNode, source : String, dto_index : Hash(String, Array(TreeSitterJavaParameterExtractor::FieldInfo)) = {} of String => Array(TreeSitterJavaParameterExtractor::FieldInfo), bean_index : Hash(String, Array(Param)) = {} of String => Array(Param), subresource_sources : Hash(String, SourceEntry) = {} of String => SourceEntry, *, include_callees : Bool = false) : Array(Route)
Same as
#extract_routes, but reuses a Java tree-sitter root the caller already parsed.
Instance Method Detail
Read JAX-RS-annotated fields (@QueryParam, @HeaderParam,
...) from every class in the file as {class_name => Params}.
Used to power @BeanParam expansion across files.
Public entry point — walks source and returns one Route
per JAX-RS endpoint defined in path's file. dto_index maps
class_name → fields for cross-file body / @BeanParam
expansion (typically built via TreeSitterJavaDtoIndex).
Same as #extract_routes, but reuses a Java tree-sitter root the
caller already parsed. Analyzer adapters use this when they also
need to attach method-body callees without reparsing the file.