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

Function extractJavaImports

src/resolution/import-resolver.ts:2508–2535  ·  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

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