Change Signature: Fix reference substitution when default value is a single simple name reference
#KT-10954 Fixed
This commit is contained in:
+7
-3
@@ -26,6 +26,7 @@ import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.idea.caches.resolve.analyze
|
||||
import org.jetbrains.kotlin.idea.codeInsight.shorten.addToShorteningWaitSet
|
||||
import org.jetbrains.kotlin.idea.core.moveFunctionLiteralOutsideParentheses
|
||||
import org.jetbrains.kotlin.idea.core.replaced
|
||||
import org.jetbrains.kotlin.idea.refactoring.replaceListPsiAndKeepDelimiters
|
||||
import org.jetbrains.kotlin.idea.refactoring.changeSignature.KotlinChangeInfo
|
||||
import org.jetbrains.kotlin.idea.refactoring.changeSignature.KotlinParameterInfo
|
||||
@@ -168,13 +169,13 @@ class KotlinFunctionCallUsage(
|
||||
): KtExpression {
|
||||
if (referenceMap.isEmpty() || resolvedCall == null) return expression
|
||||
|
||||
val newExpression = expression.copy() as KtExpression
|
||||
var newExpression = expression.copy() as KtExpression
|
||||
|
||||
val nameCounterpartMap = createNameCounterpartMap(expression, newExpression)
|
||||
|
||||
val valueArguments = resolvedCall.valueArguments
|
||||
|
||||
val replacements = ArrayList<Pair<KtElement, KtElement>>()
|
||||
val replacements = ArrayList<Pair<KtExpression, KtExpression>>()
|
||||
loop@ for ((ref, descriptor) in referenceMap.entries) {
|
||||
var argumentExpression: KtExpression?
|
||||
val addReceiver: Boolean
|
||||
@@ -235,7 +236,10 @@ class KotlinFunctionCallUsage(
|
||||
// Sort by descending offset so that call arguments are replaced before call itself
|
||||
ContainerUtil.sort(replacements, REVERSED_TEXT_OFFSET_COMPARATOR)
|
||||
for ((expressionToReplace, replacingExpression) in replacements) {
|
||||
expressionToReplace.replace(replacingExpression)
|
||||
val replaced = expressionToReplace.replaced(replacingExpression)
|
||||
if (expressionToReplace == newExpression) {
|
||||
newExpression = replaced
|
||||
}
|
||||
}
|
||||
|
||||
return newExpression
|
||||
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
// WITH_DEFAULT_VALUE: false
|
||||
|
||||
class A {
|
||||
val prop = ""
|
||||
|
||||
fun foo() = bar("")
|
||||
|
||||
private fun bar(x: String): Boolean {
|
||||
<selection>prop</selection>
|
||||
return true
|
||||
}
|
||||
}
|
||||
Vendored
+12
@@ -0,0 +1,12 @@
|
||||
// WITH_DEFAULT_VALUE: false
|
||||
|
||||
class A {
|
||||
val prop = ""
|
||||
|
||||
fun foo() = bar("", prop)
|
||||
|
||||
private fun bar(x: String, s: String): Boolean {
|
||||
s
|
||||
return true
|
||||
}
|
||||
}
|
||||
+6
@@ -3457,6 +3457,12 @@ public class ExtractionTestGenerated extends AbstractExtractionTest {
|
||||
doIntroduceSimpleParameterTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("simpleNameWithDefaultValueSubstitution.kt")
|
||||
public void testSimpleNameWithDefaultValueSubstitution() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/introduceParameter/simpleNameWithDefaultValueSubstitution.kt");
|
||||
doIntroduceSimpleParameterTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("substituteBinaryExpressions.kt")
|
||||
public void testSubstituteBinaryExpressions() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/introduceParameter/substituteBinaryExpressions.kt");
|
||||
|
||||
Reference in New Issue
Block a user