(filePath, content)
| 212 | }, |
| 213 | |
| 214 | extract(filePath, content) { |
| 215 | // Spring config files (application.yml / application.properties / |
| 216 | // bootstrap.yml + per-profile variants) are extracted on the framework |
| 217 | // path, not in the language extractor, so the keys become first-class |
| 218 | // nodes a `@Value("${k}")` reference can resolve to. |
| 219 | if (isSpringConfigFile(filePath)) { |
| 220 | return extractSpringConfig(filePath, content); |
| 221 | } |
| 222 | // Spring Boot is used from both Java and Kotlin (identical @GetMapping etc. |
| 223 | // annotations); the difference is method syntax — Kotlin `fun name(...)` vs |
| 224 | // Java `public X name(...)` — handled in the method regex below. |
| 225 | if (!filePath.endsWith('.java') && !filePath.endsWith('.kt')) return { nodes: [], references: [] }; |
| 226 | const nodes: Node[] = []; |
| 227 | const references: UnresolvedRef[] = []; |
| 228 | const now = Date.now(); |
| 229 | const lang: 'java' | 'kotlin' = filePath.endsWith('.kt') ? 'kotlin' : 'java'; |
| 230 | const safe = stripCommentsForRegex(content, 'java'); |
| 231 | const consts = new Map<string, string>(); |
| 232 | for (const m of safe.matchAll(/\bstatic\s+final\s+String\s+(\w+)\s*=\s*"([^"]*)"\s*;/g)) { |
| 233 | consts.set(m[1]!, m[2]!); |
| 234 | } |
| 235 | |
| 236 | // Class-level @RequestMapping prefix (an @RequestMapping whose tail leads to a |
| 237 | // `class`). Joined onto each method's path — and, crucially, NOT treated as a |
| 238 | // route itself (the old regex did, creating one bogus class route and missing |
| 239 | // every BARE method mapping like `@PostMapping` with the path on the class). |
| 240 | const cls = /@RequestMapping\s*\(([^)]*)\)\s*(?:@[\w.]+(?:\([^)]*\))?\s*)*(?:public\s+|final\s+|abstract\s+|open\s+|data\s+|sealed\s+)*class\b/.exec(safe); |
| 241 | const classPrefixes = cls ? parseMappingPaths(cls[1]!, consts) : ['']; |
| 242 | |
| 243 | const VERB: Record<string, string> = { |
| 244 | GetMapping: 'GET', PostMapping: 'POST', PutMapping: 'PUT', PatchMapping: 'PATCH', DeleteMapping: 'DELETE', |
| 245 | }; |
| 246 | // Verb-specific method mappings — always method-level, BARE or with a path. |
| 247 | const mappingRegex = /@(GetMapping|PostMapping|PutMapping|PatchMapping|DeleteMapping)\b/g; |
| 248 | let match: RegExpExecArray | null; |
| 249 | while ((match = mappingRegex.exec(safe)) !== null) { |
| 250 | const annotation = readAnnotation(safe, match.index, lang); |
| 251 | if (!annotation) continue; |
| 252 | const method = VERB[match[1]!]!; |
| 253 | const paths = parseMappingPaths(annotation.args, consts); |
| 254 | const line = safe.slice(0, match.index).split('\n').length; |
| 255 | // The method it decorates: the declaration it is written on (#851). |
| 256 | const handler = annotatedMethodName(safe, match.index, lang); |
| 257 | for (const routePath of classPrefixes.flatMap(prefix => paths.map(sub => joinPath(prefix, sub)))) { |
| 258 | const routeNode: Node = { |
| 259 | id: `route:${filePath}:${line}:${method}:${routePath}`, |
| 260 | kind: 'route', |
| 261 | name: `${method} ${routePath}`, |
| 262 | qualifiedName: `${filePath}::route:${routePath}`, |
| 263 | filePath, |
| 264 | startLine: line, |
| 265 | endLine: line, |
| 266 | startColumn: 0, |
| 267 | endColumn: annotation.end - match.index, |
| 268 | language: lang, |
| 269 | updatedAt: now, |
| 270 | }; |
| 271 | nodes.push(routeNode); |
nothing calls this directly
no test coverage detected