From 8b6fa6e0bb3acc29f93fb529046dfb4bac1a0109 Mon Sep 17 00:00:00 2001 From: henry Date: Tue, 26 May 2026 16:33:49 +0800 Subject: [PATCH] fix(group): handle named annotation args in Java Spring route extraction The Java HTTP plugin only matched positional `@RequestMapping("/path")` syntax for class-level prefixes and method-level routes. Named argument forms (`path = "/path"` and `value = "/path"`) produce an `element_value_pair` AST node that the tree-sitter queries did not cover, causing the class prefix to be lost and named-arg method routes to be missed entirely during cross-repo contract extraction. Add a second pattern to both SPRING_CLASS_PREFIX_PATTERNS and SPRING_METHOD_ROUTE_PATTERNS matching the element_value_pair structure. --- .../group/extractors/http-patterns/java.ts | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/gitnexus/src/core/group/extractors/http-patterns/java.ts b/gitnexus/src/core/group/extractors/http-patterns/java.ts index 484f74fb2..bbb686be8 100644 --- a/gitnexus/src/core/group/extractors/http-patterns/java.ts +++ b/gitnexus/src/core/group/extractors/http-patterns/java.ts @@ -30,6 +30,11 @@ const METHOD_ANNOTATION_TO_HTTP: Record = { }; // ─── Provider: Spring class-level @RequestMapping prefix ────────────── +// Two patterns are needed because the AST shape differs depending on +// whether the annotation uses a positional argument or a named one: +// @RequestMapping("/api") → (annotation_argument_list (string_literal)) +// @RequestMapping(path = "/api") → (annotation_argument_list (element_value_pair value: (string_literal))) +// @RequestMapping(value = "/api") → same as above const SPRING_CLASS_PREFIX_PATTERNS = compilePatterns({ name: 'java-spring-class-prefix', language: Java, @@ -44,10 +49,23 @@ const SPRING_CLASS_PREFIX_PATTERNS = compilePatterns({ arguments: (annotation_argument_list (string_literal) @prefix)))) @class `, }, + { + meta: {}, + query: ` + (class_declaration + (modifiers + (annotation + name: (identifier) @ann (#eq? @ann "RequestMapping") + arguments: (annotation_argument_list + (element_value_pair + value: (string_literal) @prefix))))) @class + `, + }, ], } satisfies LanguagePatterns>); // ─── Provider: Spring @(Get|Post|...)Mapping method annotations ─────── +// Same dual-pattern approach: positional vs named argument. const SPRING_METHOD_ROUTE_PATTERNS = compilePatterns({ name: 'java-spring-method-route', language: Java, @@ -63,6 +81,19 @@ const SPRING_METHOD_ROUTE_PATTERNS = compilePatterns({ name: (identifier) @method_name) @method `, }, + { + meta: {}, + query: ` + (method_declaration + (modifiers + (annotation + name: (identifier) @ann (#match? @ann "^(Get|Post|Put|Delete|Patch)Mapping$") + arguments: (annotation_argument_list + (element_value_pair + value: (string_literal) @path)))) + name: (identifier) @method_name) @method + `, + }, ], } satisfies LanguagePatterns>);