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

Function pickJvmDeclaration

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

* Which of a declaration's same-named Kotlin Multiplatform declarations a JVM * reference reaches. A file compiled for common code sees the `expect`, so * commonMain and commonTest keep the nearest declaration, the `expect` on a * tie. Anything built for a platform sees the `actual`: Kotlin of th

(declarations: Node[], ref: UnresolvedRef)

Source from the content-addressed store, hash-verified

2862 * Android's: okhttp's samples are `jvmMain`'s, its `android-test` `androidMain`'s.
2863 */
2864function pickJvmDeclaration(declarations: Node[], ref: UnresolvedRef): Node {
2865 const actuals = declarations.filter((n) => n.decorators?.includes('actual'));
2866 if (actuals.length === 0 || actuals.length === declarations.length) return pickClosestJvmCandidate(declarations, ref.filePath);
2867 const set = kmpSourceSet(ref.filePath);
2868 const target = set === null ? null : kmpBuildTarget(set);
2869 const targetOf = (n: Node): string => kmpBuildTarget(kmpSourceSet(n.filePath) ?? '');
2870 if (target?.startsWith('common') || (target === null && ref.language !== 'java')) return pickClosestJvmCandidate(declarations, ref.filePath);
2871 const own = actuals.filter((n) => targetOf(n) === target);
2872 if (own.length > 0) return pickClosestJvmCandidate(own, ref.filePath);
2873 if (ref.language === 'java' || target === 'main' || target === 'test') {
2874 const jvm = actuals.filter((n) => KMP_JVM_TARGET.test(targetOf(n)));
2875 const android = /android/i.test(ref.filePath);
2876 const named = jvm.filter((n) => targetOf(n).startsWith('android') === android);
2877 return pickClosestJvmCandidate(named.length > 0 ? named : jvm.length > 0 ? jvm : actuals, ref.filePath);
2878 }
2879 const above = actuals.filter((n) => targetOf(n) !== '' && target!.startsWith(targetOf(n)));
2880 return pickClosestJvmCandidate(above.length > 0 ? above : declarations, ref.filePath);
2881}
2882
2883/**
2884 * PHP scoped calls are encoded as "Alias.method" by both extractors. A use

Callers 2

resolveJvmImportFunction · 0.85

Calls 4

pickClosestJvmCandidateFunction · 0.85
kmpSourceSetFunction · 0.85
kmpBuildTargetFunction · 0.85
targetOfFunction · 0.70

Tested by

no test coverage detected