From 71d9c4726b9463d9ae217496bd87d90c3683cf1e Mon Sep 17 00:00:00 2001 From: Valentin Kipyatkov Date: Mon, 11 May 2015 15:33:16 +0300 Subject: [PATCH] No more usages of createReturn(text) --- .../frontend/src/org/jetbrains/kotlin/psi/JetPsiFactory.kt | 4 ---- .../introduce/extractionEngine/ExtractableCodeDescriptor.kt | 3 ++- .../refactoring/introduce/extractionEngine/extractorUtil.kt | 3 +-- 3 files changed, 3 insertions(+), 7 deletions(-) diff --git a/compiler/frontend/src/org/jetbrains/kotlin/psi/JetPsiFactory.kt b/compiler/frontend/src/org/jetbrains/kotlin/psi/JetPsiFactory.kt index 50cc0eab4e0..aa17c9551de 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/psi/JetPsiFactory.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/psi/JetPsiFactory.kt @@ -342,10 +342,6 @@ public class JetPsiFactory(private val project: Project) { return JetBlockCodeFragment(project, "fragment.kt", text, null, context) } - public fun createReturn(text: String): JetReturnExpression { - return createExpression("return $text") as JetReturnExpression - } - public fun createReturn(expression: JetExpression): JetReturnExpression { return createExpressionByPattern("return $0", expression) as JetReturnExpression } diff --git a/idea/src/org/jetbrains/kotlin/idea/refactoring/introduce/extractionEngine/ExtractableCodeDescriptor.kt b/idea/src/org/jetbrains/kotlin/idea/refactoring/introduce/extractionEngine/ExtractableCodeDescriptor.kt index 2a4989a0356..37461b9e2a0 100644 --- a/idea/src/org/jetbrains/kotlin/idea/refactoring/introduce/extractionEngine/ExtractableCodeDescriptor.kt +++ b/idea/src/org/jetbrains/kotlin/idea/refactoring/introduce/extractionEngine/ExtractableCodeDescriptor.kt @@ -157,7 +157,8 @@ abstract class OutputValueBoxer(val outputValues: List) { abstract val boxingRequired: Boolean fun getReturnExpression(arguments: List, psiFactory: JetPsiFactory): JetReturnExpression? { - return getBoxingExpressionText(arguments)?.let { psiFactory.createReturn(it) } + val expressionText = getBoxingExpressionText(arguments) ?: return null + return psiFactory.createExpression("return $expressionText") as JetReturnExpression } protected abstract fun extractExpressionByIndex(boxedExpression: JetExpression, index: Int): JetExpression? diff --git a/idea/src/org/jetbrains/kotlin/idea/refactoring/introduce/extractionEngine/extractorUtil.kt b/idea/src/org/jetbrains/kotlin/idea/refactoring/introduce/extractionEngine/extractorUtil.kt index 7e8f28b49a3..aadc0dda702 100644 --- a/idea/src/org/jetbrains/kotlin/idea/refactoring/introduce/extractionEngine/extractorUtil.kt +++ b/idea/src/org/jetbrains/kotlin/idea/refactoring/introduce/extractionEngine/extractorUtil.kt @@ -515,8 +515,7 @@ fun ExtractionGeneratorConfiguration.generateDeclaration( lastExpression to null } - val returnExpression = descriptor.controlFlow.outputValueBoxer.getReturnExpression(getReturnArguments(defaultExpression), psiFactory) - if (returnExpression == null) return + val returnExpression = descriptor.controlFlow.outputValueBoxer.getReturnExpression(getReturnArguments(defaultExpression), psiFactory) ?: return when(generatorOptions.target) { ExtractionTarget.LAZY_PROPERTY, ExtractionTarget.FAKE_LAMBDALIKE_FUNCTION -> {