[kotlin] kmp find usages: find actual counterpart for expect annotation default property

^KTIJ-28958 fixed

GitOrigin-RevId: 9bcabbbc3d4718543e4c9785d7505d35a27ef784
This commit is contained in:
Anna Kozlova
2024-02-29 13:50:01 +00:00
committed by intellij-monorepo-bot
parent 5b2688ea85
commit f435ea3aef
10 changed files with 44 additions and 1 deletions
@@ -374,7 +374,26 @@ class KotlinReferencesSearcher : QueryExecutorBase<PsiReference, ReferencesSearc
@RequiresReadLock
private fun searchPropertyAccessorMethods(origin: KtParameter) {
origin.toLightElements().filterDataClassComponentsIfDisabled(kotlinOptions).forEach(::searchNamedElement)
val lightMethods = if (origin.isExpectDeclaration()) {
ExpectActualSupport.getInstance(origin.project)
.actualsForExpected(origin)
.filterIsInstance<KtParameter>()
.flatMap { it.toLightElements() }
.toList()
} else origin.toLightElements()
val namedElements = lightMethods.filterDataClassComponentsIfDisabled(kotlinOptions)
for (element in namedElements) {
searchMethodAware(element)
}
}
@RequiresReadLock
private fun searchMethodAware(element: PsiNamedElement) {
if (element is PsiMethod) {
MethodReferencesSearch.search(element, queryParameters.effectiveSearchScope, true).forEach(consumer)
} else {
searchNamedElement(element)
}
}
@RequiresReadLock
@@ -45,6 +45,10 @@ open class FindUsagesMultiModuleTest : AbstractFindUsagesMultiModuleTest() {
doTest()
}
fun testFindExpectAnnotationValue() {
doTest()
}
fun testFindExpectPropertyInJvm() {
doTest()
}
@@ -7,6 +7,7 @@ fun f(a: A) {
val (a1, n1) = a
val (a2, n2) =
a?.a ?: return
val (a3, n3) = a1 ?: return
}
@@ -1,11 +1,16 @@
Checked type of a1
Checked type of a2
Checked type of a3
Checked type of n1
Checked type of n2
Checked type of n3
ExpressionOfTypeProcessor is already started for A. Exit for operator parameter a of A(val a: A?, val n: Int).
Resolved (a1, n1)
Resolved (a2, n2)
Resolved (a3, n3)
Searched references to A
Searched references to a1 in non-Java files
Searched references to a2 in non-Java files
Searched references to parameter a of A(val a: A?, val n: Int) in non-Java files
Searched references to parameter a of f(a: A) in non-Java files
Used plain search of parameter a of A(val a: A?, val n: Int) in LocalSearchScope:
@@ -1,3 +1,4 @@
Value read 10 val (a3, n3) = a1 ?: return
Value read 7 val (a1, n1) = a
Value read 8 val (a2, n2) =
Value read 9 a?.a ?: return
@@ -0,0 +1,4 @@
// PSI_ELEMENT: org.jetbrains.kotlin.psi.KtParameter
// OPTIONS: usages
expect annotation class A(val valu<caret>e: String)
@@ -0,0 +1,2 @@
[Main.java] Unclassified 1 @A("main")
[jvm.kt] Unclassified 3 @A("a")
@@ -0,0 +1,2 @@
@A("main")
class Main { }
@@ -0,0 +1,4 @@
actual annotation class A(actual val value: String)
@A("a")
fun m() {}