diff --git a/idea/src/org/jetbrains/kotlin/idea/refactoring/inline/KotlinInlineCallableProcessor.kt b/idea/src/org/jetbrains/kotlin/idea/refactoring/inline/KotlinInlineCallableProcessor.kt index 8435e35f815..349ddcfd5da 100644 --- a/idea/src/org/jetbrains/kotlin/idea/refactoring/inline/KotlinInlineCallableProcessor.kt +++ b/idea/src/org/jetbrains/kotlin/idea/refactoring/inline/KotlinInlineCallableProcessor.kt @@ -70,15 +70,15 @@ class KotlinInlineCallableProcessor( } override fun performRefactoring(usages: Array) { - val simpleNameUsages = usages.mapNotNull { it.element as? KtSimpleNameExpression } + val referenceUsages = usages.mapNotNull { it.element as? KtReferenceExpression } replacementStrategy.replaceUsages( - simpleNameUsages, + referenceUsages, declaration, myProject, commandName, postAction = { if (deleteAfter) { - if (usages.size == simpleNameUsages.size) { + if (usages.size == referenceUsages.size) { declaration.deleteWithCompanion() statementToDelete?.delete() } else { @@ -87,7 +87,7 @@ class KotlinInlineCallableProcessor( null, KotlinBundle.message( "text.cannot.inline.0.1.usages", - usages.size - simpleNameUsages.size, + usages.size - referenceUsages.size, usages.size ), KotlinBundle.message("text.inline.0", kind), diff --git a/idea/testData/refactoring/inline/function/getOperator.kt b/idea/testData/refactoring/inline/function/getOperator.kt new file mode 100644 index 00000000000..c1b1e715b7c --- /dev/null +++ b/idea/testData/refactoring/inline/function/getOperator.kt @@ -0,0 +1,10 @@ +class Declaration { + operator fun get(p: Int) = p +} + +fun call() { + val declaration = Declaration() + val vg1 = declaration.get(4) + val vg2 = declaration[42].let { it + 1 } + val vg3 = Declaration()[42].let { it + 1 } +} \ No newline at end of file diff --git a/idea/testData/refactoring/inline/function/getOperator.kt.after b/idea/testData/refactoring/inline/function/getOperator.kt.after new file mode 100644 index 00000000000..e74de514fa2 --- /dev/null +++ b/idea/testData/refactoring/inline/function/getOperator.kt.after @@ -0,0 +1,10 @@ +class Declaration { +} + +fun call() { + val declaration = Declaration() + val vg1 = 4 + val vg2 = 42.let { it + 1 } + Declaration() + val vg3 = 42.let { it + 1 } +} \ No newline at end of file diff --git a/idea/testData/refactoring/inline/function/setOperator.kt b/idea/testData/refactoring/inline/function/setOperator.kt new file mode 100644 index 00000000000..2ca15b191ca --- /dev/null +++ b/idea/testData/refactoring/inline/function/setOperator.kt @@ -0,0 +1,13 @@ +class Declaration { + operator fun set(i: Int, e: T) { + println(i) + println(e) + } +} + +fun call() { + val declaration = Declaration() + declaration.set(4, "") + declaration[42] = declaration + Declaration()[{ 42 }()] = { 4 } +} \ No newline at end of file diff --git a/idea/testData/refactoring/inline/function/setOperator.kt.after b/idea/testData/refactoring/inline/function/setOperator.kt.after new file mode 100644 index 00000000000..807d7975c9b --- /dev/null +++ b/idea/testData/refactoring/inline/function/setOperator.kt.after @@ -0,0 +1,13 @@ +class Declaration { +} + +fun call() { + val declaration = Declaration() + println(4) + println("") + println(42) + println(declaration) + Declaration() + println({ 42 }()) + println({ 4 }) +} \ No newline at end of file diff --git a/idea/tests/org/jetbrains/kotlin/idea/refactoring/inline/InlineTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/refactoring/inline/InlineTestGenerated.java index 6f002ae76a6..1c8cfd0e378 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/refactoring/inline/InlineTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/refactoring/inline/InlineTestGenerated.java @@ -50,6 +50,11 @@ public class InlineTestGenerated extends AbstractInlineTest { runTest("idea/testData/refactoring/inline/function/ExtensionAndDispatchReceivers.kt"); } + @TestMetadata("getOperator.kt") + public void testGetOperator() throws Exception { + runTest("idea/testData/refactoring/inline/function/getOperator.kt"); + } + @TestMetadata("InStringTemplates.kt") public void testInStringTemplates() throws Exception { runTest("idea/testData/refactoring/inline/function/InStringTemplates.kt"); @@ -145,6 +150,11 @@ public class InlineTestGenerated extends AbstractInlineTest { runTest("idea/testData/refactoring/inline/function/Sequence.kt"); } + @TestMetadata("setOperator.kt") + public void testSetOperator() throws Exception { + runTest("idea/testData/refactoring/inline/function/setOperator.kt"); + } + @TestMetadata("TypeArguments.kt") public void testTypeArguments() throws Exception { runTest("idea/testData/refactoring/inline/function/TypeArguments.kt");