[kotlin] kmp find usages: implicit component usages

KtDestructuringDeclarationReference has component as second target, thus we need to check all of them

^KTIJ-29947 fixed

GitOrigin-RevId: a743a6453bc55f2051ebbfdc4a67e7c00202f91f
This commit is contained in:
Anna Kozlova
2024-05-15 21:31:00 +00:00
committed by intellij-monorepo-bot
parent 20da499432
commit 9ca963f886
13 changed files with 79 additions and 2 deletions
@@ -67,9 +67,10 @@ abstract class OperatorReferenceSearcher<TReferenceElement : KtElement>(
return consumer.process(reference)
}
val currentTarget = reference.resolve() as? KtDeclaration ?: return true
val currentTargets = (reference as? PsiPolyVariantReference)?.multiResolve(false)?.mapNotNull { it.element as? KtDeclaration } ?: return true
if (targetDeclaration !is KtDeclaration) return true
return if ((targetDeclaration.expectedDeclarationIfAny() ?: targetDeclaration) == (currentTarget.expectedDeclarationIfAny() ?: currentTarget)
val expectedTarget = targetDeclaration.expectedDeclarationIfAny() ?: targetDeclaration
return if (expectedTarget in currentTargets.map { it.expectedDeclarationIfAny() ?: it }
) {
consumer.process(reference)
} else {
@@ -73,6 +73,16 @@ public class FindUsagesMultiModuleFirTestGenerated extends AbstractFindUsagesMul
runTest("../../idea/tests/testData/multiModuleFindUsages/findCompanionObjectUsages/");
}
@TestMetadata("findComponentsByConventionInCommon")
public void testFindComponentsByConventionInCommon() throws Exception {
runTest("../../idea/tests/testData/multiModuleFindUsages/findComponentsByConventionInCommon/");
}
@TestMetadata("findComponentsByConventionInPlatform")
public void testFindComponentsByConventionInPlatform() throws Exception {
runTest("../../idea/tests/testData/multiModuleFindUsages/findComponentsByConventionInPlatform/");
}
@TestMetadata("findDataComponentInJs")
public void testFindDataComponentInJs() throws Exception {
runTest("../../idea/tests/testData/multiModuleFindUsages/findDataComponentInJs/");
@@ -73,6 +73,16 @@ public class FindUsagesMultiModuleTestGenerated extends AbstractFindUsagesMultiM
runTest("testData/multiModuleFindUsages/findCompanionObjectUsages/");
}
@TestMetadata("findComponentsByConventionInCommon")
public void testFindComponentsByConventionInCommon() throws Exception {
runTest("testData/multiModuleFindUsages/findComponentsByConventionInCommon/");
}
@TestMetadata("findComponentsByConventionInPlatform")
public void testFindComponentsByConventionInPlatform() throws Exception {
runTest("testData/multiModuleFindUsages/findComponentsByConventionInPlatform/");
}
@TestMetadata("findDataComponentInJs")
public void testFindDataComponentInJs() throws Exception {
runTest("testData/multiModuleFindUsages/findDataComponentInJs/");
@@ -0,0 +1,9 @@
// PSI_ELEMENT: org.jetbrains.kotlin.psi.KtFunction
// OPTIONS: usages, expected
class DummyClass001
expect operator fun DummyClass001.comp<caret>onent1()
expect operator fun DummyClass001.component2()
fun testDummyClass001() {
val (a, b) = DummyClass001()
DummyClass001().component1()
}
@@ -0,0 +1,6 @@
[common.kt] Function call 8 DummyClass001().component1()
[common.kt] Value read 7 val (a, b) = DummyClass001()
[js.kt] Function call 5 DummyClass001().component1()
[js.kt] Value read 4 val (a, b) = DummyClass001()
[jvm.kt] Function call 5 DummyClass001().component1()
[jvm.kt] Value read 4 val (a, b) = DummyClass001()
@@ -0,0 +1,6 @@
actual operator fun DummyClass001.component1() {}
actual operator fun DummyClass001.component2() {}
fun testDummyClass001Js() {
val (a, b) = DummyClass001()
DummyClass001().component1()
}
@@ -0,0 +1,6 @@
actual operator fun DummyClass001.component1() {}
actual operator fun DummyClass001.component2() {}
fun testDummyClass001Jvm() {
val (a, b) = DummyClass001()
DummyClass001().component1()
}
@@ -0,0 +1,7 @@
class DummyClass001
expect operator fun DummyClass001.component1()
expect operator fun DummyClass001.component2()
fun testDummyClass001() {
val (a, b) = DummyClass001()
DummyClass001().component1()
}
@@ -0,0 +1,8 @@
// PSI_ELEMENT: org.jetbrains.kotlin.psi.KtFunction
// OPTIONS: usages, expected
actual operator fun DummyClass001.compo<caret>nent1() {}
actual operator fun DummyClass001.component2() {}
fun testDummyClass001Js() {
val (a, b) = DummyClass001()
DummyClass001().component1()
}
@@ -0,0 +1,6 @@
[common.kt] Function call 6 DummyClass001().component1()
[common.kt] Value read 5 val (a, b) = DummyClass001()
[js.kt] Function call 7 DummyClass001().component1()
[js.kt] Value read 6 val (a, b) = DummyClass001()
[jvm.kt] Function call 5 DummyClass001().component1()
[jvm.kt] Value read 4 val (a, b) = DummyClass001()
@@ -0,0 +1,6 @@
actual operator fun DummyClass001.component1() {}
actual operator fun DummyClass001.component2() {}
fun testDummyClass001Jvm() {
val (a, b) = DummyClass001()
DummyClass001().component1()
}