Introduce Parameter: Fix NPE on invalid parameter name or type
EA-95189 Fixed
This commit is contained in:
@@ -69,14 +69,13 @@ class KtPsiFactory @JvmOverloads constructor(private val project: Project, val m
|
|||||||
return (createExpression("a?.b") as KtSafeQualifiedExpression).operationTokenNode
|
return (createExpression("a?.b") as KtSafeQualifiedExpression).operationTokenNode
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun doCreateExpression(text: String): KtExpression {
|
private fun doCreateExpression(text: String): KtExpression? {
|
||||||
//TODO: '\n' below if important - some strange code indenting problems appear without it
|
//NOTE: '\n' below is 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 createProperty("val x =\n$text").initializer
|
||||||
return expression
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun createExpression(text: String): KtExpression {
|
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) {
|
assert(expression.text == text) {
|
||||||
"Failed to create expression from text: '$text', resulting expression's text was: '${expression.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? {
|
fun createExpressionIfPossible(text: String): KtExpression? {
|
||||||
val expression = doCreateExpression(text)
|
val expression = doCreateExpression(text) ?: return null
|
||||||
return if (expression.text == text) expression else null
|
return if (expression.text == text) expression else null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+2
-2
@@ -231,8 +231,8 @@ class KotlinIntroduceParameterDialog private constructor(
|
|||||||
|
|
||||||
override fun canRun() {
|
override fun canRun() {
|
||||||
val psiFactory = KtPsiFactory(myProject)
|
val psiFactory = KtPsiFactory(myProject)
|
||||||
psiFactory.createSimpleName(nameField.enteredName.quoteIfNeeded()).validateElement("Invalid parameter name")
|
psiFactory.createExpressionIfPossible(nameField.enteredName.quoteIfNeeded()).validateElement("Invalid parameter name")
|
||||||
psiFactory.createType(typeField.enteredName).validateElement("Invalid parameter type")
|
psiFactory.createTypeIfPossible(typeField.enteredName).validateElement("Invalid parameter type")
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun doAction() {
|
override fun doAction() {
|
||||||
|
|||||||
Reference in New Issue
Block a user