Supported usages as destructuring declaration for other class
This commit is contained in:
+16
-3
@@ -44,6 +44,7 @@ import org.jetbrains.kotlin.idea.util.fuzzyExtensionReceiverType
|
||||
import org.jetbrains.kotlin.idea.util.toFuzzyType
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
import org.jetbrains.kotlin.psi.psiUtil.*
|
||||
import org.jetbrains.kotlin.resolve.dataClassUtils.getComponentIndex
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.isExtension
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
import org.jetbrains.kotlin.util.isValidOperator
|
||||
@@ -278,7 +279,21 @@ private class Processor(
|
||||
//TODO: what about Scala and other JVM-languages?
|
||||
val declarationUsageScope = GlobalSearchScope.projectScope(declaration.project).restrictToKotlinSources()
|
||||
ReferencesSearch.search(declaration, declarationUsageScope).forEach { reference ->
|
||||
(reference.element as? KtReferenceExpression)?.let { processSuspiciousExpression(it) }
|
||||
if (reference is KtDestructuringDeclarationReference) { // declaration usage in form of destructuring declaration
|
||||
val entries = reference.element.entries
|
||||
val componentIndex = when (declaration) {
|
||||
is KtParameter -> declaration.dataClassComponentFunction()?.name?.asString()?.let { getComponentIndex(it) }
|
||||
is KtFunction -> declaration.name?.let { getComponentIndex(it) }
|
||||
//TODO: java component functions (see KT-13605)
|
||||
else -> null
|
||||
}
|
||||
if (componentIndex != null && componentIndex <= entries.size) {
|
||||
processDeclarationOfTypeWithDataClass(entries[componentIndex - 1])
|
||||
}
|
||||
}
|
||||
else {
|
||||
(reference.element as? KtReferenceExpression)?.let { processSuspiciousExpression(it) }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -313,8 +328,6 @@ private class Processor(
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//TODO: entry of data type
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,4 +8,4 @@ class JavaClass {
|
||||
}
|
||||
|
||||
public void takeA(A a){}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import pack.A
|
||||
|
||||
fun test(javaClass: JavaClass) {
|
||||
fun test(javaClass: JavaClass, javaClass2: JavaClass2) {
|
||||
val a = A(1, "2", Any())
|
||||
a.n
|
||||
a.component1()
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
package pack
|
||||
|
||||
data class B(val a: A, val n: Int)
|
||||
|
||||
class C {
|
||||
operator fun component1(): A = TODO()
|
||||
operator fun component2() = 0
|
||||
}
|
||||
|
||||
fun f(b: B, c: C) {
|
||||
val (a, n) = b
|
||||
val (x, y, z) = a
|
||||
|
||||
val (a1, n1) = c
|
||||
val (x1, y1, z1) = a1
|
||||
}
|
||||
+3
-1
@@ -12,4 +12,6 @@
|
||||
[dataClass.2.kt] Value read 33 val (x, y) = list[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()
|
||||
[dataClass.2.kt] Value read 9 val (x1, y1, z1) = f()
|
||||
[dataClass.3.kt] Value read 12 val (x, y, z) = a
|
||||
[dataClass.3.kt] Value read 15 val (x1, y1, z1) = a1
|
||||
Reference in New Issue
Block a user