Callable references handled
This commit is contained in:
+13
@@ -314,6 +314,19 @@ private class Processor(
|
||||
return true // companion object member or static member access - ignore it
|
||||
}
|
||||
}
|
||||
|
||||
is KtCallableReferenceExpression -> {
|
||||
when (element) {
|
||||
parent.receiverExpression -> { // usage in receiver of callable reference (before "::") - ignore it
|
||||
return true
|
||||
}
|
||||
|
||||
parent.callableReference -> { // usage after "::" in callable reference - should be reference to constructor of our data class
|
||||
processSuspiciousExpression(element)
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (element.getStrictParentOfType<KtImportDirective>() != null) return true // ignore usage in import
|
||||
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
// PSI_ELEMENT: org.jetbrains.kotlin.psi.KtParameter
|
||||
// OPTIONS: usages
|
||||
|
||||
data class A(val <caret>a: Int, val b: Int) {
|
||||
fun f() {}
|
||||
}
|
||||
|
||||
fun f1(): A = A(1, 2)
|
||||
|
||||
class X {
|
||||
fun f2() = A(0, 0)
|
||||
}
|
||||
|
||||
fun foo(x: X) {
|
||||
val fun1 = A::f
|
||||
|
||||
val fun2 = ::f1
|
||||
val fun3 = x::f2
|
||||
val (a1, b1) = fun2()
|
||||
val (a2, b2) = fun3()
|
||||
|
||||
val constructor = ::A
|
||||
val (a3, b3) = constructor(1, 2)
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
Checked type of (a1, b1)
|
||||
Checked type of (a2, b2)
|
||||
Checked type of (a3, b3)
|
||||
Checked type of X.f2()
|
||||
Checked type of constructor
|
||||
Checked type of fun2
|
||||
Checked type of fun3
|
||||
Searched inheritors of A
|
||||
Searched references to A
|
||||
Searched references to X.f2() in Kotlin files
|
||||
Searched references to constructor in Kotlin files
|
||||
Searched references to f1() in Kotlin files
|
||||
Searched references to fun2 in Kotlin files
|
||||
Searched references to fun3 in Kotlin files
|
||||
Used plain search in LocalSearchScope:
|
||||
CLASS:A
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
Value read 19 val (a1, b1) = fun2()
|
||||
Value read 20 val (a2, b2) = fun3()
|
||||
Value read 23 val (a3, b3) = constructor(1, 2)
|
||||
@@ -170,6 +170,12 @@ public class FindUsagesTestGenerated extends AbstractFindUsagesTest {
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/findUsages/kotlin/conventions/components"), Pattern.compile("^(.+)\\.0\\.kt$"), true);
|
||||
}
|
||||
|
||||
@TestMetadata("callableReferences.0.kt")
|
||||
public void testCallableReferences() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/findUsages/kotlin/conventions/components/callableReferences.0.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("companionObjectAccess.0.kt")
|
||||
public void testCompanionObjectAccess() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/findUsages/kotlin/conventions/components/companionObjectAccess.0.kt");
|
||||
|
||||
Reference in New Issue
Block a user