diff --git a/compiler/frontend/src/org/jetbrains/kotlin/psi/KtPsiFactory.kt b/compiler/frontend/src/org/jetbrains/kotlin/psi/KtPsiFactory.kt index 14a38280c3d..fa6674e4315 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/psi/KtPsiFactory.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/psi/KtPsiFactory.kt @@ -69,14 +69,13 @@ class KtPsiFactory @JvmOverloads constructor(private val project: Project, val m return (createExpression("a?.b") as KtSafeQualifiedExpression).operationTokenNode } - private fun doCreateExpression(text: String): KtExpression { - //TODO: '\n' below if important - some strange code indenting problems appear without it - val expression = createProperty("val x =\n$text").initializer ?: error("Failed to create expression from text: '$text'") - return expression + private fun doCreateExpression(text: String): KtExpression? { + //NOTE: '\n' below is important - some strange code indenting problems appear without it + return createProperty("val x =\n$text").initializer } fun createExpression(text: String): KtExpression { - val expression = doCreateExpression(text) + val expression = doCreateExpression(text) ?: error("Failed to create expression from text: '$text'") assert(expression.text == text) { "Failed to create expression from text: '$text', resulting expression's text was: '${expression.text}'" } @@ -84,7 +83,7 @@ class KtPsiFactory @JvmOverloads constructor(private val project: Project, val m } fun createExpressionIfPossible(text: String): KtExpression? { - val expression = doCreateExpression(text) + val expression = doCreateExpression(text) ?: return null return if (expression.text == text) expression else null } diff --git a/idea/src/org/jetbrains/kotlin/idea/refactoring/introduce/introduceParameter/KotlinIntroduceParameterDialog.kt b/idea/src/org/jetbrains/kotlin/idea/refactoring/introduce/introduceParameter/KotlinIntroduceParameterDialog.kt index 5228039eba3..5855f0e8ead 100644 --- a/idea/src/org/jetbrains/kotlin/idea/refactoring/introduce/introduceParameter/KotlinIntroduceParameterDialog.kt +++ b/idea/src/org/jetbrains/kotlin/idea/refactoring/introduce/introduceParameter/KotlinIntroduceParameterDialog.kt @@ -231,8 +231,8 @@ class KotlinIntroduceParameterDialog private constructor( override fun canRun() { val psiFactory = KtPsiFactory(myProject) - psiFactory.createSimpleName(nameField.enteredName.quoteIfNeeded()).validateElement("Invalid parameter name") - psiFactory.createType(typeField.enteredName).validateElement("Invalid parameter type") + psiFactory.createExpressionIfPossible(nameField.enteredName.quoteIfNeeded()).validateElement("Invalid parameter name") + psiFactory.createTypeIfPossible(typeField.enteredName).validateElement("Invalid parameter type") } override fun doAction() {