DeprecatedSymbolUsageFix: more correct generation of "let" for safe call

This commit is contained in:
Valentin Kipyatkov
2015-05-18 20:41:56 +03:00
parent df850d7035
commit 348d09866a
11 changed files with 203 additions and 8 deletions
@@ -0,0 +1,18 @@
// "Replace with 'c.newFun(this)'" "true"
class X {
@deprecated("", ReplaceWith("c.newFun(this)"))
fun oldFun(c: Char): Char = c.newFun(this)
}
fun Char.newFun(x: X): Char = this
fun foo(x: X?, p: Boolean, s: String) {
val chars = s.filter {
val v = if (p)
x?.<caret>oldFun(it)
else
null
v != 'a'
}
}
@@ -0,0 +1,18 @@
// "Replace with 'c.newFun(this)'" "true"
class X {
@deprecated("", ReplaceWith("c.newFun(this)"))
fun oldFun(c: Char): Char = c.newFun(this)
}
fun Char.newFun(x: X): Char = this
fun foo(x: X?, p: Boolean, s: String) {
val chars = s.filter {
val v = if (p)
x?.let { x -> it.newFun(x) }
else
null
v != 'a'
}
}
@@ -0,0 +1,14 @@
// "Replace with 's.filter { it != c }'" "true"
class X {
@deprecated("", ReplaceWith("s.filter { it != c }"))
fun oldFun(s: String): CharSequence = s.filter { it != c }
val c = 'x'
}
fun foo(x: X?, s: String) {
bar(x?.<caret>oldFun(s))
}
fun bar(s: CharSequence?){}
@@ -0,0 +1,14 @@
// "Replace with 's.filter { it != c }'" "true"
class X {
@deprecated("", ReplaceWith("s.filter { it != c }"))
fun oldFun(s: String): CharSequence = s.filter { it != c }
val c = 'x'
}
fun foo(x: X?, s: String) {
bar(x?.<caret>let { x -> s.filter { it != x.c } })
}
fun bar(s: CharSequence?){}
@@ -0,0 +1,20 @@
// "Replace with 'c1.newFun(this, c2)'" "true"
class X {
@deprecated("", ReplaceWith("c1.newFun(this, c2)"))
fun oldFun(c1: Char, c2: Char): Char = c1.newFun(this, c2)
val c: Char = 'a'
}
fun Char.newFun(x: X, c: Char): Char = this
fun foo(s: String, x: X) {
val chars = s.filter {
O.x?.<caret>oldFun(it, x.c) != 'a'
}
}
object O {
var x: X? = null
}
@@ -0,0 +1,20 @@
// "Replace with 'c1.newFun(this, c2)'" "true"
class X {
@deprecated("", ReplaceWith("c1.newFun(this, c2)"))
fun oldFun(c1: Char, c2: Char): Char = c1.newFun(this, c2)
val c: Char = 'a'
}
fun Char.newFun(x: X, c: Char): Char = this
fun foo(s: String, x: X) {
val chars = s.filter {
O.x?.<caret>let { x1 -> it.newFun(x1, x.c) } != 'a'
}
}
object O {
var x: X? = null
}
@@ -0,0 +1,16 @@
// "Replace with 'c1.newFun(this, c2)'" "true"
class X(val c: Char) {
@deprecated("", ReplaceWith("c1.newFun(this, c2)"))
fun oldFun(c1: Char, c2: Char): Char = c1.newFun(this, c2)
}
fun Char.newFun(x: X, c: Char): Char = this
fun foo(s: String, t: X) {
val chars = s.filter {
(X('a') + X('b'))?.<caret>oldFun(it, t.c) != 'a'
}
}
fun X.plus(x: X): X? = null
@@ -0,0 +1,16 @@
// "Replace with 'c1.newFun(this, c2)'" "true"
class X(val c: Char) {
@deprecated("", ReplaceWith("c1.newFun(this, c2)"))
fun oldFun(c1: Char, c2: Char): Char = c1.newFun(this, c2)
}
fun Char.newFun(x: X, c: Char): Char = this
fun foo(s: String, t: X) {
val chars = s.filter {
(X('a') + X('b'))?.let { t1 -> it.newFun(t1, t.c) } != 'a'
}
}
fun X.plus(x: X): X? = null