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 else JetValVar.None
val occurrenceRanges = occurrencesToReplace.map { it.getTextRange() } parametersToRemove =
parametersToRemove = parametersUsages.entrySet() if (withDefaultValue) Collections.emptyList()
.filter { else {
it.value.all { paramRef -> val occurrenceRanges = occurrencesToReplace.map { it.getTextRange() }
occurrenceRanges.any { occurrenceRange -> occurrenceRange.contains(paramRef.getElement().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 return i * 2
} }
fun test() { 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 val t = i * 2
return i - t return i - t
} }
fun test() { 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 return i * 2
} }
fun test() { fun test() {
foo("2") foo(1, "2")
} }