Introduce Parameter: Do not remove unused parameters if new parameter is extracted with default value

This commit is contained in:
Alexey Sedunov
2015-04-16 14:16:38 +03:00
parent 6e2076d602
commit bf13f7e637
4 changed files with 17 additions and 13 deletions
@@ -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 }
}
}
@@ -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")
}