Initial implementation of faster component function usage search

This commit is contained in:
Valentin Kipyatkov
2016-08-23 22:52:23 +03:00
parent 77bb9b8092
commit 1674beb64b
32 changed files with 609 additions and 121 deletions
@@ -1,4 +0,0 @@
fun test() {
for ((x, y, z) in arrayOf<A>()) {
}
}
@@ -1,4 +0,0 @@
[componentFunctions.0.kt] Function call 9 a.component1()
[componentFunctions.0.kt] Value read 10 val (x, y, z) = a
[componentFunctions.0.kt] Value read 8 a.n
[componentFunctions.1.kt] Value read 2 for ((x, y, z) in arrayOf<A>()) {
@@ -0,0 +1,13 @@
// PSI_ELEMENT: org.jetbrains.kotlin.psi.KtFunction
// OPTIONS: usages
class X<T>
operator fun <T> X<T>.<caret>component1(): Int = 0
operator fun <T> X<T>.component2(): Int = 0
fun f() = X<String>()
fun test() {
val (x, y) = f()
}
@@ -0,0 +1 @@
Value read 12 val (x, y) = f()
@@ -0,0 +1,18 @@
// PSI_ELEMENT: org.jetbrains.kotlin.psi.KtFunction
// OPTIONS: usages
class X<T>
operator fun X<Int>.<caret>component1(): Int = 0
operator fun X<Int>.component2(): Int = 0
operator fun X<String>.component1(): Int = 0
operator fun X<String>.component2(): Int = 0
fun f() = X<Int>()
fun g() = X<String>()
fun test() {
val (x1, y1) = f()
val (x2, y2) = g()
}
@@ -0,0 +1 @@
Value read 16 val (x1, y1) = f()
@@ -0,0 +1,11 @@
import java.util.List;
import pack.A;
class JavaClass {
public List<A> getA() {
A a = new A(1, "", "");
return Collections.singletonList(a);
}
public void takeA(A a){}
}
@@ -1,11 +1,5 @@
// PSI_ELEMENT: org.jetbrains.kotlin.psi.KtParameter
// OPTIONS: usages
package pack
data class A(val <caret>n: Int, val s: String, val o: Any)
fun test() {
val a = A(1, "2", Any())
a.n
a.component1()
val (x, y, z) = a
}
@@ -0,0 +1,10 @@
import pack.A
fun test() {
for ((x, y, z) in arrayOf<A>()) {
}
for (a in listOf<A>()) {
val (x, y) = a
}
}
@@ -0,0 +1,22 @@
import pack.A
fun test(javaClass: JavaClass) {
val a = A(1, "2", Any())
a.n
a.component1()
val (x, y, z) = a
val (x1, y1, z1) = f()
val (x2, y2, z2) = g()
val (x3, y3, z3) = h()
val (x4, y4, z4) = listOfA()[0]
val (x5, y5, z5) = javaClass.getA()[0]
}
fun f(): A = TODO()
fun g() = A()
fun h() = g()
fun listOfA() = listOf<A>(A(1, "", ""))
@@ -0,0 +1,10 @@
[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()
[dataClass.2.kt] Value read 10 val (x2, y2, z2) = g()
[dataClass.2.kt] Value read 11 val (x3, y3, z3) = h()
[dataClass.2.kt] Value read 13 val (x4, y4, z4) = listOfA()[0]
[dataClass.2.kt] Value read 15 val (x5, y5, z5) = javaClass.getA()[0]
[dataClass.2.kt] Value read 5 a.n
[dataClass.2.kt] Value read 8 val (x, y, z) = a
[dataClass.2.kt] Value read 9 val (x1, y1, z1) = f()
@@ -0,0 +1,14 @@
// PSI_ELEMENT: org.jetbrains.kotlin.psi.KtFunction
// OPTIONS: usages
class X
operator fun X.component1(): Int = 0
operator fun X.<caret>component2(): Int = 1
fun f() = X()
fun test() {
val (x, y) = f()
}
@@ -0,0 +1 @@
Value read 13 val (x, y) = f()
@@ -0,0 +1,20 @@
// PSI_ELEMENT: org.jetbrains.kotlin.psi.KtFunction
// OPTIONS: usages
open class X {
operator fun <caret>component1(): Int = 0
operator fun component2(): Int = 1
}
open class Y : X()
open class Z : Y()
fun f() = X()
fun g() = Y()
fun h() = Z()
fun test() {
val (x, y) = f()
val (x1, y1) = g()
val (x2, y2) = h()
}
@@ -0,0 +1,3 @@
Value read 17 val (x, y) = f()
Value read 18 val (x1, y1) = g()
Value read 19 val (x2, y2) = h()
@@ -1,34 +0,0 @@
// all these are unused, but have conventional names, so they won't be marked as unused
fun inc() {
}
fun dec() {
}
fun component1() {
}
fun component100() {
}
fun equals() {
}
fun invoke() {
}
fun iterator() {
}
fun compareTo() {
}
fun get() {
}
fun set() {
}
fun plusAssign() {
}
@@ -0,0 +1,9 @@
// all these are unused but are operators
operator fun String.inc() = ""
operator fun String.dec() = ""
operator fun String.component1() = 0
operator fun String.component100() = 0
+10
View File
@@ -0,0 +1,10 @@
class A
operator fun A.<caret>component1(): Int = 0
operator fun A.component2(): Int = 1
fun test() {
val a = A()
a.component1()
val (x, y) = a
}