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

Function extractJavaImports

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

2752 * (`bar(...)`) can resolve through the same import lookup.
2753 */
2754function extractJavaImports(content: string): ImportMapping[] {
2755 const mappings: ImportMapping[] = [];
2756 // Strip line and block comments so `// import foo;` doesn't false-match.
2757 const stripped = content
2758 .replace(/\/\*[\s\S]*?\*\//g, '')
2759 .replace(/\/\/[^\n]*/g, '');
2760 // `import [static] <fqn>[.*];` — and Kotlin's `import <fqn> [as Alias]`, with no `;`.
2761 const re = /^\s*import\s+(static\s+)?([\w.]+(?:\.\*)?)(?:\s+as\s+([\w]+))?\s*(?:;|$)/gm;
2762 let match: RegExpExecArray | null;
2763 while ((match = re.exec(stripped)) !== null) {
2764 const fqn = match[2]!;
2765 // `import com.example.*;` — wildcard. We can't materialize a single
2766 // local name; skip and let name-matching handle members reachable
2767 // through the wildcard. (Future enhancement: enumerate package files.)
2768 if (fqn.endsWith('.*')) continue;
2769 const parts = fqn.split('.');
2770 const localName = match[3] ?? parts[parts.length - 1];
2771 if (!localName) continue;
2772 mappings.push({
2773 localName,
2774 exportedName: parts[parts.length - 1]!,
2775 source: fqn,
2776 isDefault: false,
2777 isNamespace: false,
2778 });
2779 }
2780 return mappings;
2781}
2782
2783/**
2784 * 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