diff --git a/plugins/kotlin/idea/tests/test/org/jetbrains/kotlin/idea/refactoring/introduce/ExtractionTestGenerated.java b/plugins/kotlin/idea/tests/test/org/jetbrains/kotlin/idea/refactoring/introduce/ExtractionTestGenerated.java index a57f1d1ea2b6..6c4e14d7e880 100644 --- a/plugins/kotlin/idea/tests/test/org/jetbrains/kotlin/idea/refactoring/introduce/ExtractionTestGenerated.java +++ b/plugins/kotlin/idea/tests/test/org/jetbrains/kotlin/idea/refactoring/introduce/ExtractionTestGenerated.java @@ -1177,6 +1177,11 @@ public abstract class ExtractionTestGenerated extends AbstractExtractionTest { runTest("testData/refactoring/extractFunction/basic/privateSetter.kt"); } + @TestMetadata("quotedName.kt") + public void testQuotedName() throws Exception { + runTest("testData/refactoring/extractFunction/basic/quotedName.kt"); + } + @TestMetadata("refInReturn.kt") public void testRefInReturn() throws Exception { runTest("testData/refactoring/extractFunction/basic/refInReturn.kt"); diff --git a/plugins/kotlin/idea/tests/testData/refactoring/extractFunction/basic/quotedName.kt b/plugins/kotlin/idea/tests/testData/refactoring/extractFunction/basic/quotedName.kt new file mode 100644 index 000000000000..3f47cdb677b2 --- /dev/null +++ b/plugins/kotlin/idea/tests/testData/refactoring/extractFunction/basic/quotedName.kt @@ -0,0 +1,18 @@ + +data class Person(val name: String, val pets: List) +data class Pet(val name: String) + +fun main() { + val `⍼` = listOf( + Person("Alice", listOf(Pet("Rex"), Pet("Fluffy"))), + Person("Bob", listOf(Pet("Max"))) + ) + + `⍼`.forEach { + println("Person: ${it.name}") + it.pets.forEach { + println("Pet: ${it.name}") + } + } +} +// IGNORE_K1 \ No newline at end of file diff --git a/plugins/kotlin/idea/tests/testData/refactoring/extractFunction/basic/quotedName.kt.after b/plugins/kotlin/idea/tests/testData/refactoring/extractFunction/basic/quotedName.kt.after new file mode 100644 index 000000000000..52ecaee18b4d --- /dev/null +++ b/plugins/kotlin/idea/tests/testData/refactoring/extractFunction/basic/quotedName.kt.after @@ -0,0 +1,22 @@ +data class Person(val name: String, val pets: List) +data class Pet(val name: String) + +fun main() { + val `⍼` = people() + + `⍼`.forEach { + println("Person: ${it.name}") + it.pets.forEach { + println("Pet: ${it.name}") + } + } +} + +private fun people(): List { + val `⍼` = listOf( + Person("Alice", listOf(Pet("Rex"), Pet("Fluffy"))), + Person("Bob", listOf(Pet("Max"))) + ) + return `⍼` +} +// IGNORE_K1 \ No newline at end of file diff --git a/plugins/kotlin/refactorings/kotlin.refactorings.common/src/org/jetbrains/kotlin/idea/refactoring/introduce/extractionEngine/ExtractFunctionGenerator.kt b/plugins/kotlin/refactorings/kotlin.refactorings.common/src/org/jetbrains/kotlin/idea/refactoring/introduce/extractionEngine/ExtractFunctionGenerator.kt index 305b34e1504d..fb6511e03108 100644 --- a/plugins/kotlin/refactorings/kotlin.refactorings.common/src/org/jetbrains/kotlin/idea/refactoring/introduce/extractionEngine/ExtractFunctionGenerator.kt +++ b/plugins/kotlin/refactorings/kotlin.refactorings.common/src/org/jetbrains/kotlin/idea/refactoring/introduce/extractionEngine/ExtractFunctionGenerator.kt @@ -150,7 +150,7 @@ abstract class ExtractFunctionGenerator resultExpression is Jump -> if (it.conditional) psiFactory.createExpression("false") else null is ParameterUpdate -> psiFactory.createExpression(it.parameter.nameForRef) - is Initializer -> psiFactory.createExpression(it.initializedDeclaration.name!!) + is Initializer -> psiFactory.createExpression(it.initializedDeclaration.name!!.quoteIfNeeded()) else -> throw IllegalArgumentException("Unknown output value: $it") } } diff --git a/plugins/kotlin/refactorings/kotlin.refactorings.tests.k2/test/org/jetbrains/kotlin/idea/k2/refactoring/introduce/K2IntroduceFunctionTestGenerated.java b/plugins/kotlin/refactorings/kotlin.refactorings.tests.k2/test/org/jetbrains/kotlin/idea/k2/refactoring/introduce/K2IntroduceFunctionTestGenerated.java index 234d2c97cea8..2581378751c3 100644 --- a/plugins/kotlin/refactorings/kotlin.refactorings.tests.k2/test/org/jetbrains/kotlin/idea/k2/refactoring/introduce/K2IntroduceFunctionTestGenerated.java +++ b/plugins/kotlin/refactorings/kotlin.refactorings.tests.k2/test/org/jetbrains/kotlin/idea/k2/refactoring/introduce/K2IntroduceFunctionTestGenerated.java @@ -293,6 +293,11 @@ public abstract class K2IntroduceFunctionTestGenerated extends AbstractK2Introdu runTest("../../idea/tests/testData/refactoring/extractFunction/basic/privateSetter.kt"); } + @TestMetadata("quotedName.kt") + public void testQuotedName() throws Exception { + runTest("../../idea/tests/testData/refactoring/extractFunction/basic/quotedName.kt"); + } + @TestMetadata("refInReturn.kt") public void testRefInReturn() throws Exception { runTest("../../idea/tests/testData/refactoring/extractFunction/basic/refInReturn.kt");