Introduce Parameter: Do not remove unused parameters if new parameter is extracted with default value
This commit is contained in:
+11
-7
@@ -94,14 +94,18 @@ public data class IntroduceParameterDescriptor(
|
||||
}
|
||||
else JetValVar.None
|
||||
|
||||
val occurrenceRanges = occurrencesToReplace.map { it.getTextRange() }
|
||||
parametersToRemove = parametersUsages.entrySet()
|
||||
.filter {
|
||||
it.value.all { paramRef ->
|
||||
occurrenceRanges.any { occurrenceRange -> occurrenceRange.contains(paramRef.getElement().getTextRange()) }
|
||||
}
|
||||
parametersToRemove =
|
||||
if (withDefaultValue) Collections.emptyList()
|
||||
else {
|
||||
val occurrenceRanges = occurrencesToReplace.map { it.getTextRange() }
|
||||
parametersUsages.entrySet()
|
||||
.filter {
|
||||
it.value.all { paramRef ->
|
||||
occurrenceRanges.any { occurrenceRange -> occurrenceRange.contains(paramRef.getElement().getTextRange()) }
|
||||
}
|
||||
}
|
||||
.map { it.key }
|
||||
}
|
||||
.map { it.key }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -1,7 +1,7 @@
|
||||
fun foo(s: String, i: Int = a + b): Int {
|
||||
fun foo(a: Int, s: String, b: Int, i: Int = a + b): Int {
|
||||
return i * 2
|
||||
}
|
||||
|
||||
fun test() {
|
||||
foo("2")
|
||||
foo(1, "2", 3)
|
||||
}
|
||||
@@ -1,8 +1,8 @@
|
||||
fun foo(s: String, i: Int = a + 1): Int {
|
||||
fun foo(a: Int, s: String, i: Int = a + 1): Int {
|
||||
val t = i * 2
|
||||
return i - t
|
||||
}
|
||||
|
||||
fun test() {
|
||||
foo("2")
|
||||
foo(1, "2")
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
fun foo(s: String, i: Int = a + 1): Int {
|
||||
fun foo(a: Int, s: String, i: Int = a + 1): Int {
|
||||
return i * 2
|
||||
}
|
||||
|
||||
fun test() {
|
||||
foo("2")
|
||||
foo(1, "2")
|
||||
}
|
||||
Reference in New Issue
Block a user