diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/search/usagesSearch/destructuringDeclarationUsages.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/search/usagesSearch/destructuringDeclarationUsages.kt index 883cc778268..3ca6ebfa80d 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/search/usagesSearch/destructuringDeclarationUsages.kt +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/search/usagesSearch/destructuringDeclarationUsages.kt @@ -23,6 +23,7 @@ import com.intellij.psi.search.searches.ClassInheritorsSearch import com.intellij.psi.search.searches.ReferencesSearch import com.intellij.util.Processor import org.jetbrains.kotlin.KtNodeTypes +import org.jetbrains.kotlin.asJava.classes.KtLightClass import org.jetbrains.kotlin.asJava.elements.KtLightMethod import org.jetbrains.kotlin.asJava.namedUnwrappedElement import org.jetbrains.kotlin.asJava.toLightClass @@ -139,6 +140,9 @@ private class Processor( true } }) + + // we must use plain search inside our data class (and inheritors) because implicit 'this' can happen anywhere + (classToSearch as? KtLightClass)?.kotlinOrigin?.let { usePlainSearch(it) } } // we use index instead of iterator because elements are added during iteration @@ -192,7 +196,8 @@ private class Processor( } typeRefParent.receiverTypeReference -> { - //TODO: search usages inside extensions and member functions of our class & derived + // we must use plain search inside extensions because implicit 'this' can happen anywhere + usePlainSearch(typeRefParent) return true } } diff --git a/idea/testData/findUsages/kotlin/conventions/components/dataClass.0.kt b/idea/testData/findUsages/kotlin/conventions/components/dataClass.0.kt index e50e162c8a7..97d8a141022 100644 --- a/idea/testData/findUsages/kotlin/conventions/components/dataClass.0.kt +++ b/idea/testData/findUsages/kotlin/conventions/components/dataClass.0.kt @@ -3,3 +3,13 @@ package pack data class A(val n: Int, val s: String, val o: Any) + +fun A.ext1() { + val (x, y) = getThis() +} + +fun List.ext1() { + val (x, y) = get(0) +} + +fun T.getThis(): T = this \ No newline at end of file diff --git a/idea/testData/findUsages/kotlin/conventions/components/dataClass.results.txt b/idea/testData/findUsages/kotlin/conventions/components/dataClass.results.txt index fe2e13a98e7..fd8d50ff9a7 100644 --- a/idea/testData/findUsages/kotlin/conventions/components/dataClass.results.txt +++ b/idea/testData/findUsages/kotlin/conventions/components/dataClass.results.txt @@ -1,3 +1,5 @@ +[dataClass.0.kt] Value read 12 val (x, y) = get(0) +[dataClass.0.kt] Value read 8 val (x, y) = getThis() [dataClass.1.kt] Value read 4 for ((x, y, z) in arrayOf()) { [dataClass.1.kt] Value read 8 val (x, y) = a [dataClass.2.kt] Function call 6 a.component1() diff --git a/idea/testData/findUsages/kotlin/conventions/components/extensionComponentFun.0.kt b/idea/testData/findUsages/kotlin/conventions/components/extensionComponentFun.0.kt index e63dc6c4a1e..6d9626df86c 100644 --- a/idea/testData/findUsages/kotlin/conventions/components/extensionComponentFun.0.kt +++ b/idea/testData/findUsages/kotlin/conventions/components/extensionComponentFun.0.kt @@ -1,7 +1,9 @@ // PSI_ELEMENT: org.jetbrains.kotlin.psi.KtFunction // OPTIONS: usages -class X +open class X + +class Y : X() operator fun X.component1(): Int = 0 operator fun X.component2(): Int = 1 @@ -12,3 +14,7 @@ fun f() = X() fun test() { val (x, y) = f() } + +fun Y.ext() { + val (a, b) = this +} diff --git a/idea/testData/findUsages/kotlin/conventions/components/extensionComponentFun.results.txt b/idea/testData/findUsages/kotlin/conventions/components/extensionComponentFun.results.txt index 82090aac119..77f0bdc7dcf 100644 --- a/idea/testData/findUsages/kotlin/conventions/components/extensionComponentFun.results.txt +++ b/idea/testData/findUsages/kotlin/conventions/components/extensionComponentFun.results.txt @@ -1 +1,2 @@ -Value read 13 val (x, y) = f() +Value read 15 val (x, y) = f() +Value read 19 val (a, b) = this \ No newline at end of file diff --git a/idea/testData/findUsages/kotlin/conventions/components/memberComponentFun.0.kt b/idea/testData/findUsages/kotlin/conventions/components/memberComponentFun.0.kt index fdc48840e02..bba1d359e23 100644 --- a/idea/testData/findUsages/kotlin/conventions/components/memberComponentFun.0.kt +++ b/idea/testData/findUsages/kotlin/conventions/components/memberComponentFun.0.kt @@ -4,10 +4,19 @@ open class X { operator fun component1(): Int = 0 operator fun component2(): Int = 1 + + fun foo() { + val (x, y) = this + } } open class Y : X() -open class Z : Y() + +open class Z : Y() { + fun bar() { + val (x, y) = this + } +} fun f() = X() fun g() = Y() diff --git a/idea/testData/findUsages/kotlin/conventions/components/memberComponentFun.results.txt b/idea/testData/findUsages/kotlin/conventions/components/memberComponentFun.results.txt index f1e88ad8305..766aad64399 100644 --- a/idea/testData/findUsages/kotlin/conventions/components/memberComponentFun.results.txt +++ b/idea/testData/findUsages/kotlin/conventions/components/memberComponentFun.results.txt @@ -1,3 +1,5 @@ -Value read 17 val (x, y) = f() -Value read 18 val (x1, y1) = g() -Value read 19 val (x2, y2) = h() \ No newline at end of file +Value read 17 val (x, y) = this +Value read 26 val (x, y) = f() +Value read 27 val (x1, y1) = g() +Value read 28 val (x2, y2) = h() +Value read 9 val (x, y) = this \ No newline at end of file