* Extract Java / Kotlin import mappings. * * Java/Kotlin imports carry the full qualified name of the imported * symbol — `import com.example.dao.converter.FooConverter;` — which is * exactly the disambiguation signal we need when two packages both * declare a `FooConverter`. Pre-#314 the resol
(content: string)
| 2417 | * (`bar(...)`) can resolve through the same import lookup. |
| 2418 | */ |
| 2419 | function extractJavaImports(content: string): ImportMapping[] { |
| 2420 | const mappings: ImportMapping[] = []; |
| 2421 | // Strip line and block comments so `// import foo;` doesn't false-match. |
| 2422 | const stripped = content |
| 2423 | .replace(/\/\*[\s\S]*?\*\//g, '') |
| 2424 | .replace(/\/\/[^\n]*/g, ''); |
| 2425 | // `import [static] <fqn>[.*];` — and Kotlin's `import <fqn> [as Alias]`, with no `;`. |
| 2426 | const re = /^\s*import\s+(static\s+)?([\w.]+(?:\.\*)?)(?:\s+as\s+([\w]+))?\s*(?:;|$)/gm; |
| 2427 | let match: RegExpExecArray | null; |
| 2428 | while ((match = re.exec(stripped)) !== null) { |
| 2429 | const fqn = match[2]!; |
| 2430 | // `import com.example.*;` — wildcard. We can't materialize a single |
| 2431 | // local name; skip and let name-matching handle members reachable |
| 2432 | // through the wildcard. (Future enhancement: enumerate package files.) |
| 2433 | if (fqn.endsWith('.*')) continue; |
| 2434 | const parts = fqn.split('.'); |
| 2435 | const localName = match[3] ?? parts[parts.length - 1]; |
| 2436 | if (!localName) continue; |
| 2437 | mappings.push({ |
| 2438 | localName, |
| 2439 | exportedName: parts[parts.length - 1]!, |
| 2440 | source: fqn, |
| 2441 | isDefault: false, |
| 2442 | isNamespace: false, |
| 2443 | }); |
| 2444 | } |
| 2445 | return mappings; |
| 2446 | } |
| 2447 | |
| 2448 | /** |
| 2449 | * Extract PHP import mappings (use statements) |
no test coverage detected