* 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)
| 2775 | * Android's: okhttp's samples are `jvmMain`'s, its `android-test` `androidMain`'s. |
| 2776 | */ |
| 2777 | function pickJvmDeclaration(declarations: Node[], ref: UnresolvedRef): Node { |
| 2778 | const actuals = declarations.filter((n) => n.decorators?.includes('actual')); |
| 2779 | if (actuals.length === 0 || actuals.length === declarations.length) return pickClosestJvmCandidate(declarations, ref.filePath); |
| 2780 | const set = kmpSourceSet(ref.filePath); |
| 2781 | const target = set === null ? null : kmpBuildTarget(set); |
| 2782 | const targetOf = (n: Node): string => kmpBuildTarget(kmpSourceSet(n.filePath) ?? ''); |
| 2783 | if (target?.startsWith('common') || (target === null && ref.language !== 'java')) return pickClosestJvmCandidate(declarations, ref.filePath); |
| 2784 | const own = actuals.filter((n) => targetOf(n) === target); |
| 2785 | if (own.length > 0) return pickClosestJvmCandidate(own, ref.filePath); |
| 2786 | if (ref.language === 'java' || target === 'main' || target === 'test') { |
| 2787 | const jvm = actuals.filter((n) => KMP_JVM_TARGET.test(targetOf(n))); |
| 2788 | const android = /android/i.test(ref.filePath); |
| 2789 | const named = jvm.filter((n) => targetOf(n).startsWith('android') === android); |
| 2790 | return pickClosestJvmCandidate(named.length > 0 ? named : jvm.length > 0 ? jvm : actuals, ref.filePath); |
| 2791 | } |
| 2792 | const above = actuals.filter((n) => targetOf(n) !== '' && target!.startsWith(targetOf(n))); |
| 2793 | return pickClosestJvmCandidate(above.length > 0 ? above : declarations, ref.filePath); |
| 2794 | } |
| 2795 | |
| 2796 | /** |
| 2797 | * PHP scoped calls are encoded as "Alias.method" by both extractors. A use |
no test coverage detected