[kotlin] kmp find usages: distinguish references to platform companion objects

^KTIJ-29834 fixed

GitOrigin-RevId: 7293ca30df0dbdf512fe0680bd889ef43b9f8fb7
This commit is contained in:
Anna Kozlova
2024-05-08 23:30:17 +02:00
committed by intellij-monorepo-bot
parent 7fb3e939a4
commit 118b52cfa1
9 changed files with 58 additions and 2 deletions

View File

@@ -58,6 +58,11 @@ public class FindUsagesMultiModuleFirTestGenerated extends AbstractFindUsagesMul
runTest("../../idea/tests/testData/multiModuleFindUsages/findCommonSuperclass/");
}
@TestMetadata("findCompanionObjectUsages")
public void testFindCompanionObjectUsages() throws Exception {
runTest("../../idea/tests/testData/multiModuleFindUsages/findCompanionObjectUsages/");
}
@TestMetadata("findDataComponentInJs")
public void testFindDataComponentInJs() throws Exception {
runTest("../../idea/tests/testData/multiModuleFindUsages/findDataComponentInJs/");

View File

@@ -58,6 +58,11 @@ public class FindUsagesMultiModuleTestGenerated extends AbstractFindUsagesMultiM
runTest("testData/multiModuleFindUsages/findCommonSuperclass/");
}
@TestMetadata("findCompanionObjectUsages")
public void testFindCompanionObjectUsages() throws Exception {
runTest("testData/multiModuleFindUsages/findCompanionObjectUsages/");
}
@TestMetadata("findDataComponentInJs")
public void testFindDataComponentInJs() throws Exception {
runTest("testData/multiModuleFindUsages/findDataComponentInJs/");

View File

@@ -0,0 +1,9 @@
expect class Clazz006 {
companion object {
val AA_A: Int
}
}
fun useCompanionInCommon() {
println(Clazz006.AA_A)
}

View File

@@ -0,0 +1,3 @@
[common.kt] Companion object 8 println(Clazz006.AA_A)
[js.kt] Companion object 12 println(Clazz006.AA_A)
[jvm.kt] Companion object 9 println(Clazz006.AA_A)

View File

@@ -0,0 +1,15 @@
// PSI_ELEMENT: org.jetbrains.kotlin.psi.KtClass
// OPTIONS: usages, expected
actual class Clazz006<caret> {
actual companion object {
actual val AA_A: Int
get() = TODO("Not yet implemented")
}
}
fun useCompanionInJs() {
println(Clazz006.AA_A)
}
// IGNORE_K1

View File

@@ -0,0 +1,2 @@
[common.kt] Companion object 8 println(Clazz006.AA_A)
[js.kt] Companion object 12 println(Clazz006.AA_A)

View File

@@ -0,0 +1,10 @@
actual class Clazz006 {
actual companion object {
actual val AA_A: Int
get() = TODO("Not yet implemented")
}
}
fun useCompanionInJvm() {
println(Clazz006.AA_A)
}

View File

@@ -89,8 +89,14 @@ internal class KotlinK2SearchUsagesSupport : KotlinSearchUsagesSupport {
declaration: KtNamedDeclaration
): Boolean = declaration.isExpectDeclaration() &&
reference.unwrappedTargets.any { target ->
target is KtDeclaration && ExpectActualSupport.getInstance(declaration.project)
.expectedDeclarationIfAny(target) == declaration
if (target is KtDeclaration) {
val expectedDeclaration = ExpectActualSupport.getInstance(declaration.project)
.expectedDeclarationIfAny(target)
expectedDeclaration == declaration ||
//repeat logic of AbstractKtReference.isReferenceTo for calls on companion objects
expectedDeclaration is KtObjectDeclaration && expectedDeclaration.isCompanion() && expectedDeclaration.getNonStrictParentOfType<KtClass>() == declaration
}
else false
}
override fun isCallableOverrideUsage(reference: PsiReference, declaration: KtNamedDeclaration): Boolean {