From ee0b7426c439214c3df68f3a588b00a377973ebb Mon Sep 17 00:00:00 2001 From: Dmitry Gridin Date: Wed, 29 Apr 2020 14:06:19 +0700 Subject: [PATCH] KotlinFunctionCallUsage: fix psi tree #KT-38632 --- .../changeSignature/usages/KotlinFunctionCallUsage.kt | 10 +++++++--- .../primaryParameter/valOnUserType.kt.after | 2 +- .../primaryParameter/varOnUserType.kt.after | 2 +- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/idea/src/org/jetbrains/kotlin/idea/refactoring/changeSignature/usages/KotlinFunctionCallUsage.kt b/idea/src/org/jetbrains/kotlin/idea/refactoring/changeSignature/usages/KotlinFunctionCallUsage.kt index 9c452039f7c..204e2c0a8a4 100644 --- a/idea/src/org/jetbrains/kotlin/idea/refactoring/changeSignature/usages/KotlinFunctionCallUsage.kt +++ b/idea/src/org/jetbrains/kotlin/idea/refactoring/changeSignature/usages/KotlinFunctionCallUsage.kt @@ -305,11 +305,13 @@ class KotlinFunctionCallUsage( defaultValueForCall != null -> substituteReferences(defaultValueForCall, parameter.defaultValueParameterReferences, psiFactory) else -> null } + val argName = (if (isInsideOfCallerBody) null else name)?.let { Name.identifier(it) } return psiFactory.createArgument(argValue ?: psiFactory.createExpression("0"), argName).apply { - generatedArgumentValue = true if (argValue == null) { - getArgumentExpression()!!.delete() + getArgumentExpression()?.delete() + } else { + generatedArgumentValue = true } } } @@ -437,7 +439,9 @@ class KotlinFunctionCallUsage( } val oldArgumentList = element.valueArgumentList.sure { "Argument list is expected: " + element.text } - replaceListPsiAndKeepDelimiters(oldArgumentList, newArgumentList) { arguments } + for (argument in replaceListPsiAndKeepDelimiters(oldArgumentList, newArgumentList) { arguments }.arguments) { + if (argument.getArgumentExpression() == null) argument.delete() + } element.accept( object : KtTreeVisitorVoid() { diff --git a/idea/testData/quickfix/createFromUsage/createVariable/primaryParameter/valOnUserType.kt.after b/idea/testData/quickfix/createFromUsage/createVariable/primaryParameter/valOnUserType.kt.after index dcd78066462..e9d29f9fde5 100644 --- a/idea/testData/quickfix/createFromUsage/createVariable/primaryParameter/valOnUserType.kt.after +++ b/idea/testData/quickfix/createFromUsage/createVariable/primaryParameter/valOnUserType.kt.after @@ -4,5 +4,5 @@ class A(val n: T, val foo: A) fun test() { - val a: A = A(1, ).foo + val a: A = A(1,).foo } diff --git a/idea/testData/quickfix/createFromUsage/createVariable/primaryParameter/varOnUserType.kt.after b/idea/testData/quickfix/createFromUsage/createVariable/primaryParameter/varOnUserType.kt.after index b60e43e86b8..5812b484513 100644 --- a/idea/testData/quickfix/createFromUsage/createVariable/primaryParameter/varOnUserType.kt.after +++ b/idea/testData/quickfix/createFromUsage/createVariable/primaryParameter/varOnUserType.kt.after @@ -4,5 +4,5 @@ class A(val n: T, var foo: String) fun test() { - A(1, ).foo = "1" + A(1,).foo = "1" }