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 edc25a45388..bae61788438 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 @@ -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() != null) return true // ignore usage in import diff --git a/idea/testData/findUsages/kotlin/conventions/components/callableReferences.0.kt b/idea/testData/findUsages/kotlin/conventions/components/callableReferences.0.kt new file mode 100644 index 00000000000..e431e787dc3 --- /dev/null +++ b/idea/testData/findUsages/kotlin/conventions/components/callableReferences.0.kt @@ -0,0 +1,24 @@ +// PSI_ELEMENT: org.jetbrains.kotlin.psi.KtParameter +// OPTIONS: usages + +data class A(val 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) +} \ No newline at end of file diff --git a/idea/testData/findUsages/kotlin/conventions/components/callableReferences.log b/idea/testData/findUsages/kotlin/conventions/components/callableReferences.log new file mode 100644 index 00000000000..7bcdaff658f --- /dev/null +++ b/idea/testData/findUsages/kotlin/conventions/components/callableReferences.log @@ -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 diff --git a/idea/testData/findUsages/kotlin/conventions/components/callableReferences.results.txt b/idea/testData/findUsages/kotlin/conventions/components/callableReferences.results.txt new file mode 100644 index 00000000000..c0ca32a393d --- /dev/null +++ b/idea/testData/findUsages/kotlin/conventions/components/callableReferences.results.txt @@ -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) diff --git a/idea/tests/org/jetbrains/kotlin/findUsages/FindUsagesTestGenerated.java b/idea/tests/org/jetbrains/kotlin/findUsages/FindUsagesTestGenerated.java index 9a82e957ffa..88a0bc73b42 100644 --- a/idea/tests/org/jetbrains/kotlin/findUsages/FindUsagesTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/findUsages/FindUsagesTestGenerated.java @@ -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");