MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / extractJavaImports

Function extractJavaImports

src/resolution/import-resolver.ts:2506–2533  ·  view source on GitHub ↗

* 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)

Source from the content-addressed store, hash-verified

2504 * (`bar(...)`) can resolve through the same import lookup.
2505 */
2506function extractJavaImports(content: string): ImportMapping[] {
2507 const mappings: ImportMapping[] = [];
2508 // Strip line and block comments so `// import foo;` doesn't false-match.
2509 const stripped = content
2510 .replace(/\/\*[\s\S]*?\*\//g, '')
2511 .replace(/\/\/[^\n]*/g, '');
2512 // `import [static] <fqn>[.*];` — and Kotlin's `import <fqn> [as Alias]`, with no `;`.
2513 const re = /^\s*import\s+(static\s+)?([\w.]+(?:\.\*)?)(?:\s+as\s+([\w]+))?\s*(?:;|$)/gm;
2514 let match: RegExpExecArray | null;
2515 while ((match = re.exec(stripped)) !== null) {
2516 const fqn = match[2]!;
2517 // `import com.example.*;` — wildcard. We can't materialize a single
2518 // local name; skip and let name-matching handle members reachable
2519 // through the wildcard. (Future enhancement: enumerate package files.)
2520 if (fqn.endsWith('.*')) continue;
2521 const parts = fqn.split('.');
2522 const localName = match[3] ?? parts[parts.length - 1];
2523 if (!localName) continue;
2524 mappings.push({
2525 localName,
2526 exportedName: parts[parts.length - 1]!,
2527 source: fqn,
2528 isDefault: false,
2529 isNamespace: false,
2530 });
2531 }
2532 return mappings;
2533}
2534
2535/**
2536 * Extract PHP import mappings (use statements)

Callers 1

extractImportMappingsFunction · 0.85

Calls 2

pushMethod · 0.80
execMethod · 0.65

Tested by

no test coverage detected