* 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)
| 3110 | * Android's: okhttp's samples are `jvmMain`'s, its `android-test` `androidMain`'s. |
| 3111 | */ |
| 3112 | function pickJvmDeclaration(declarations: Node[], ref: UnresolvedRef): Node { |
| 3113 | const actuals = declarations.filter((n) => n.decorators?.includes('actual')); |
| 3114 | if (actuals.length === 0 || actuals.length === declarations.length) return pickClosestJvmCandidate(declarations, ref.filePath); |
| 3115 | const set = kmpSourceSet(ref.filePath); |
| 3116 | const target = set === null ? null : kmpBuildTarget(set); |
| 3117 | const targetOf = (n: Node): string => kmpBuildTarget(kmpSourceSet(n.filePath) ?? ''); |
| 3118 | if (target?.startsWith('common') || (target === null && ref.language !== 'java')) return pickClosestJvmCandidate(declarations, ref.filePath); |
| 3119 | const own = actuals.filter((n) => targetOf(n) === target); |
| 3120 | if (own.length > 0) return pickClosestJvmCandidate(own, ref.filePath); |
| 3121 | if (ref.language === 'java' || target === 'main' || target === 'test') { |
| 3122 | const jvm = actuals.filter((n) => KMP_JVM_TARGET.test(targetOf(n))); |
| 3123 | const android = /android/i.test(ref.filePath); |
| 3124 | const named = jvm.filter((n) => targetOf(n).startsWith('android') === android); |
| 3125 | return pickClosestJvmCandidate(named.length > 0 ? named : jvm.length > 0 ? jvm : actuals, ref.filePath); |
| 3126 | } |
| 3127 | const above = actuals.filter((n) => targetOf(n) !== '' && target!.startsWith(targetOf(n))); |
| 3128 | return pickClosestJvmCandidate(above.length > 0 ? above : declarations, ref.filePath); |
| 3129 | } |
| 3130 | |
| 3131 | /** |
| 3132 | * PHP scoped calls are encoded as "Alias.method" by both extractors. A use |
no test coverage detected