Plain search inside members and extensions
This commit is contained in:
+6
-1
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,3 +3,13 @@
|
||||
package pack
|
||||
|
||||
data class A(val <caret>n: Int, val s: String, val o: Any)
|
||||
|
||||
fun A.ext1() {
|
||||
val (x, y) = getThis()
|
||||
}
|
||||
|
||||
fun List<A>.ext1() {
|
||||
val (x, y) = get(0)
|
||||
}
|
||||
|
||||
fun <T> T.getThis(): T = this
|
||||
@@ -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<A>()) {
|
||||
[dataClass.1.kt] Value read 8 val (x, y) = a
|
||||
[dataClass.2.kt] Function call 6 a.component1()
|
||||
|
||||
+7
-1
@@ -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.<caret>component2(): Int = 1
|
||||
@@ -12,3 +14,7 @@ fun f() = X()
|
||||
fun test() {
|
||||
val (x, y) = f()
|
||||
}
|
||||
|
||||
fun Y.ext() {
|
||||
val (a, b) = this
|
||||
}
|
||||
|
||||
+2
-1
@@ -1 +1,2 @@
|
||||
Value read 13 val (x, y) = f()
|
||||
Value read 15 val (x, y) = f()
|
||||
Value read 19 val (a, b) = this
|
||||
+10
-1
@@ -4,10 +4,19 @@
|
||||
open class X {
|
||||
operator fun <caret>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()
|
||||
|
||||
+5
-3
@@ -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()
|
||||
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
|
||||
Reference in New Issue
Block a user