DeprecatedSymbolUsageFix: initial implementation

This commit is contained in:
Valentin Kipyatkov
2015-05-15 15:21:13 +03:00
parent 0a886320ca
commit df850d7035
73 changed files with 1314 additions and 40 deletions
@@ -0,0 +1,8 @@
// "Replace with 's.newFun()'" "true"
import dependency.newFun
import dependency.oldFun
fun foo() {
"a".<caret>newFun()
}
@@ -0,0 +1,6 @@
package dependency
@deprecated("", ReplaceWith("s.newFun()"))
fun oldFun(s: String) {}
fun String.newFun() {}
@@ -0,0 +1,7 @@
// "Replace with 's.newFun()'" "true"
import dependency.oldFun
fun foo() {
<caret>oldFun("a")
}
@@ -0,0 +1,9 @@
// "Replace with 's.extension().newFun()'" "true"
import dependency.newFun
import dependency.oldFun
import dependency2.extension
fun foo() {
"a".extension().<caret>newFun()
}
@@ -0,0 +1,6 @@
package dependency
@deprecated("", ReplaceWith("s.extension().newFun()", "dependency2.extension"))
fun oldFun(s: String) {}
fun String.newFun() {}
@@ -0,0 +1,3 @@
package dependency2
fun String.extension(): String = this
@@ -0,0 +1,7 @@
// "Replace with 's.extension().newFun()'" "true"
import dependency.oldFun
fun foo() {
<caret>oldFun("a")
}
@@ -0,0 +1,8 @@
// "Replace with 'newFun()'" "true"
import dependency.newFun
import dependency.oldFun
fun foo() {
<caret>newFun()
}
@@ -0,0 +1,6 @@
package dependency
@deprecated("", ReplaceWith("newFun()"))
fun oldFun() {}
fun newFun() {}
@@ -0,0 +1,7 @@
// "Replace with 'newFun()'" "true"
import dependency.oldFun
fun foo() {
<caret>oldFun()
}
@@ -0,0 +1,12 @@
// "Replace with 'newFun(n + java.math.BigInteger(s))'" "true"
import java.math.BigInteger
@deprecated("", ReplaceWith("newFun(n + java.math.BigInteger(s))", "kotlin.math.plus"))
fun oldFun(n: BigInteger, s: String) {}
fun newFun(n: BigInteger) {}
fun foo() {
<caret>oldFun(BigInteger("2"), "1")
}
@@ -0,0 +1,13 @@
// "Replace with 'newFun(n + java.math.BigInteger(s))'" "true"
import java.math.BigInteger
import kotlin.math.plus
@deprecated("", ReplaceWith("newFun(n + java.math.BigInteger(s))", "kotlin.math.plus"))
fun oldFun(n: BigInteger, s: String) {}
fun newFun(n: BigInteger) {}
fun foo() {
<caret>newFun(BigInteger("2") + BigInteger("1"))
}
@@ -0,0 +1,9 @@
// "Replace with 's.extension1().extension2'" "true"
import dependency.oldFun
import dependency2.extension1
import dependency2.extension2
fun foo() {
"a".extension1().<caret>extension2
}
@@ -0,0 +1,4 @@
package dependency
@deprecated("", ReplaceWith("s.extension1().extension2", "dependency2.extension1", "dependency2.extension2"))
fun oldFun(s: String) {}
@@ -0,0 +1,4 @@
package dependency2
fun String.extension1(): String = this
val String.extension2: String get() = this
@@ -0,0 +1,7 @@
// "Replace with 's.extension1().extension2'" "true"
import dependency.oldFun
fun foo() {
<caret>oldFun("a")
}
@@ -0,0 +1,12 @@
// "class org.jetbrains.kotlin.idea.quickfix.DeprecatedSymbolUsageFix" "false"
// ERROR: Too many arguments for kotlin.deprecated internal fun oldFun(): kotlin.Unit defined in root package
@deprecated("", ReplaceWith("newFun()"))
fun oldFun() {
}
fun newFun(){}
fun foo() {
<caret>oldFun(123)
}
@@ -0,0 +1,12 @@
// "Replace with 's.newFun(this)'" "true"
class X {
@deprecated("", ReplaceWith("s.newFun(this)"))
fun oldFun(s: String){}
}
fun String.newFun(x: X){}
fun foo(x: X) {
x.<caret>oldFun("a")
}
@@ -0,0 +1,12 @@
// "Replace with 's.newFun(this)'" "true"
class X {
@deprecated("", ReplaceWith("s.newFun(this)"))
fun oldFun(s: String){}
}
fun String.newFun(x: X){}
fun foo(x: X) {
"a".newFun(x)
}
@@ -0,0 +1,12 @@
// "Replace with 's.newFun(this)'" "true"
class X {
@deprecated("", ReplaceWith("s.newFun(this)"))
fun oldFun(s: String){}
}
fun String.newFun(x: X){}
fun X.foo() {
<caret>oldFun("a")
}
@@ -0,0 +1,12 @@
// "Replace with 's.newFun(this)'" "true"
class X {
@deprecated("", ReplaceWith("s.newFun(this)"))
fun oldFun(s: String){}
}
fun String.newFun(x: X){}
fun X.foo() {
"a".<caret>newFun(this)
}
@@ -0,0 +1,12 @@
// "Replace with 's.newFun(this)'" "true"
class X {
@deprecated("", ReplaceWith("s.newFun(this)"))
fun oldFun(s: String): String = s.newFun(this)
}
fun String.newFun(x: X): String = this
fun foo(x: X?) {
x?.<caret>oldFun("a")
}
@@ -0,0 +1,14 @@
// "Replace with 's.newFun(this)'" "true"
class X {
@deprecated("", ReplaceWith("s.newFun(this)"))
fun oldFun(s: String): String = s.newFun(this)
}
fun String.newFun(x: X): String = this
fun foo(x: X?) {
<caret>if (x != null) {
"a".newFun(x)
}
}
@@ -0,0 +1,15 @@
// "Replace with 's.newFun(this)'" "true"
class X {
@deprecated("", ReplaceWith("s.newFun(this)"))
fun oldFun(s: String): String = s.newFun(this)
}
fun String.newFun(x: X): String = this
fun foo(x: X?, p: Boolean) {
val v = if (p)
x?.<caret>oldFun("a")
else
null
}
@@ -0,0 +1,15 @@
// "Replace with 's.newFun(this)'" "true"
class X {
@deprecated("", ReplaceWith("s.newFun(this)"))
fun oldFun(s: String): String = s.newFun(this)
}
fun String.newFun(x: X): String = this
fun foo(x: X?, p: Boolean) {
val v = if (p)
x?.<caret>let { "a".newFun(it) }
else
null
}
@@ -0,0 +1,18 @@
// "Replace with 's.newFun(this)'" "true"
open class Base {
@deprecated("", ReplaceWith("s.newFun(this)"))
fun oldFun(s: String){}
open inner class Inner
}
class Derived : Base() {
inner class InnerDerived : Base.Inner() {
fun foo() {
<caret>oldFun("a")
}
}
}
fun String.newFun(x: Base){}
@@ -0,0 +1,18 @@
// "Replace with 's.newFun(this)'" "true"
open class Base {
@deprecated("", ReplaceWith("s.newFun(this)"))
fun oldFun(s: String){}
open inner class Inner
}
class Derived : Base() {
inner class InnerDerived : Base.Inner() {
fun foo() {
<caret>"a".newFun(this@Derived)
}
}
}
fun String.newFun(x: Base){}
@@ -0,0 +1,10 @@
// "Replace with 'newFun(c)'" "true"
@deprecated("", ReplaceWith("newFun(c)"))
fun oldFun(c: Char){}
fun newFun(c: Char){}
fun foo() {
<caret>oldFun(java.io.File.separatorChar)
}
@@ -0,0 +1,10 @@
// "Replace with 'newFun(c)'" "true"
@deprecated("", ReplaceWith("newFun(c)"))
fun oldFun(c: Char){}
fun newFun(c: Char){}
fun foo() {
<caret>newFun(java.io.File.separatorChar)
}
@@ -0,0 +1,14 @@
// "Replace with 'newFun(p)'" "true"
class X {
@deprecated("", ReplaceWith("newFun(p)"))
fun oldFun(p: Any) {
newFun(p)
}
fun newFun(p: Any){}
}
fun X.foo() {
this.<caret>oldFun(this.toString())
}
@@ -0,0 +1,14 @@
// "Replace with 'newFun(p)'" "true"
class X {
@deprecated("", ReplaceWith("newFun(p)"))
fun oldFun(p: Any) {
newFun(p)
}
fun newFun(p: Any){}
}
fun X.foo() {
this.<caret>newFun(this.toString())
}
@@ -0,0 +1,12 @@
// "Replace with 'newFun()'" "true"
class X {
@deprecated("", ReplaceWith("newFun()"))
fun oldFun(){}
}
fun newFun(){}
fun foo(x: X) {
x.<caret>oldFun()
}
@@ -0,0 +1,12 @@
// "Replace with 'newFun()'" "true"
class X {
@deprecated("", ReplaceWith("newFun()"))
fun oldFun(){}
}
fun newFun(){}
fun foo(x: X) {
newFun()
}
@@ -0,0 +1,12 @@
// "Replace with 'newFun()'" "true"
class X {
@deprecated("", ReplaceWith("newFun()"))
fun oldFun(){}
}
fun newFun(){}
fun foo(x: X) {
x?.<caret>oldFun()
}
@@ -0,0 +1,14 @@
// "Replace with 'newFun()'" "true"
class X {
@deprecated("", ReplaceWith("newFun()"))
fun oldFun(){}
}
fun newFun(){}
fun foo(x: X) {
<caret>if (x != null) {
newFun()
}
}
@@ -0,0 +1,12 @@
// "Replace with 'newFun(t)'" "true"
class C<T>
@deprecated("", ReplaceWith("newFun(t)"))
fun <T> C<T>.oldFun(t: T){}
fun <T> C<T>.newFun(t: T){}
fun foo(x: C<String>) {
x.<caret>oldFun("a")
}
@@ -0,0 +1,12 @@
// "Replace with 'newFun(t)'" "true"
class C<T>
@deprecated("", ReplaceWith("newFun(t)"))
fun <T> C<T>.oldFun(t: T){}
fun <T> C<T>.newFun(t: T){}
fun foo(x: C<String>) {
x.<caret>newFun("a")
}
@@ -0,0 +1,9 @@
// "class org.jetbrains.kotlin.idea.quickfix.DeprecatedSymbolUsageFix" "false"
@deprecated("", ReplaceWith("="))
fun oldFun() {
}
fun foo() {
<caret>oldFun()
}
@@ -0,0 +1,14 @@
// "Replace with 'newFun()'" "true"
class X {
@deprecated("", ReplaceWith("newFun()"))
fun oldFun() {
newFun()
}
fun newFun(){}
}
fun foo(x: X) {
x.<caret>oldFun()
}
@@ -0,0 +1,14 @@
// "Replace with 'newFun()'" "true"
class X {
@deprecated("", ReplaceWith("newFun()"))
fun oldFun() {
newFun()
}
fun newFun(){}
}
fun foo(x: X) {
x.newFun()
}
@@ -0,0 +1,14 @@
// "Replace with 'newFun()'" "true"
class X {
@deprecated("", ReplaceWith("newFun()"))
fun oldFun() {
newFun()
}
fun newFun(){}
}
fun X.foo() {
<caret>oldFun()
}
@@ -0,0 +1,14 @@
// "Replace with 'newFun()'" "true"
class X {
@deprecated("", ReplaceWith("newFun()"))
fun oldFun() {
newFun()
}
fun newFun(){}
}
fun X.foo() {
<caret>newFun()
}
@@ -0,0 +1,12 @@
// "Replace with 'newFun(t)'" "true"
interface X<T> {
@deprecated("", ReplaceWith("newFun(t)"))
fun oldFun(t: T)
fun newFun(t: T)
}
fun foo(x: X<String>) {
x.<caret>oldFun("a")
}
@@ -0,0 +1,12 @@
// "Replace with 'newFun(t)'" "true"
interface X<T> {
@deprecated("", ReplaceWith("newFun(t)"))
fun oldFun(t: T)
fun newFun(t: T)
}
fun foo(x: X<String>) {
x.<caret>newFun("a")
}
@@ -0,0 +1,12 @@
// "Replace with 'x'" "true"
trait X {
@deprecated("", ReplaceWith("x"))
fun getX(): String
val x: String
}
fun foo(x: X): String {
return x.<caret>getX()
}
@@ -0,0 +1,12 @@
// "Replace with 'x'" "true"
trait X {
@deprecated("", ReplaceWith("x"))
fun getX(): String
val x: String
}
fun foo(x: X): String {
return x.<caret>x
}
@@ -0,0 +1,9 @@
// "class org.jetbrains.kotlin.idea.quickfix.DeprecatedSymbolUsageFix" "false"
@deprecated("")
fun oldFun() {
}
fun foo() {
<caret>oldFun()
}
@@ -0,0 +1,11 @@
// "Replace with 'newFun(b, a, null)'" "true"
@deprecated("", ReplaceWith("newFun(b, a, null)"))
fun oldFun(a: Int, b: String) {
}
fun newFun(b: String, a: Int, x: Any?){}
fun foo() {
<caret>oldFun(1, "x")
}
@@ -0,0 +1,11 @@
// "Replace with 'newFun(b, a, null)'" "true"
@deprecated("", ReplaceWith("newFun(b, a, null)"))
fun oldFun(a: Int, b: String) {
}
fun newFun(b: String, a: Int, x: Any?){}
fun foo() {
<caret>newFun("x", 1, null)
}
@@ -0,0 +1,12 @@
// "Replace with 'getX()'" "true"
trait X {
@deprecated("", ReplaceWith("getX()"))
val x: String
fun getX(): String
}
fun foo(x: X): String {
return x.<caret>x
}
@@ -0,0 +1,12 @@
// "Replace with 'getX()'" "true"
trait X {
@deprecated("", ReplaceWith("getX()"))
val x: String
fun getX(): String
}
fun foo(x: X): String {
return x.<caret>getX()
}
@@ -0,0 +1,12 @@
// "Replace with 'newFun()'" "true"
class X {
@deprecated("", ReplaceWith("newFun()"))
fun oldFun(){}
fun newFun(){}
}
fun foo(x: X?) {
x?.<caret>oldFun()
}
@@ -0,0 +1,12 @@
// "Replace with 'newFun()'" "true"
class X {
@deprecated("", ReplaceWith("newFun()"))
fun oldFun(){}
fun newFun(){}
}
fun foo(x: X?) {
x?.<caret>newFun()
}
@@ -0,0 +1,10 @@
// "Replace with 'newFun(java.io.File.separatorChar)'" "true"
@deprecated("", ReplaceWith("newFun(java.io.File.separatorChar)"))
fun oldFun() { }
fun newFun(separator: Char){}
fun foo() {
<caret>oldFun()
}
@@ -0,0 +1,12 @@
// "Replace with 'newFun(java.io.File.separatorChar)'" "true"
import java.io.File
@deprecated("", ReplaceWith("newFun(java.io.File.separatorChar)"))
fun oldFun() { }
fun newFun(separator: Char){}
fun foo() {
<caret>newFun(File.separatorChar)
}
@@ -0,0 +1,12 @@
// "Replace with 'newFun()'" "true"
@deprecated("", ReplaceWith("newFun()"))
fun oldFun() {
newFun()
}
fun newFun(){}
fun foo() {
<caret>oldFun()
}
@@ -0,0 +1,12 @@
// "Replace with 'newFun()'" "true"
@deprecated("", ReplaceWith("newFun()"))
fun oldFun() {
newFun()
}
fun newFun(){}
fun foo() {
<caret>newFun()
}
@@ -0,0 +1,7 @@
// "Replace with 'newFun(this)'" "true"
import dependency.C
fun foo(c: dependency.C) {
C.<caret>newFun(c)
}
@@ -0,0 +1,11 @@
package dependency
class C {
@deprecated("", ReplaceWith("newFun(this)"))
fun oldFun() {}
companion object {
fun newFun(c: C) {}
}
}
@@ -0,0 +1,5 @@
// "Replace with 'newFun(this)'" "true"
fun foo(c: dependency.C) {
c.<caret>oldFun()
}
@@ -0,0 +1,15 @@
// "Replace with 'newFun(this)'" "true"
// ERROR: Unresolved reference: newFun
class Outer {
inner class Inner {
@deprecated("", ReplaceWith("newFun(this)"))
fun oldFun() {}
}
fun newFun(inner: Inner) {}
}
fun foo(inner: Outer.Inner) {
inner.<caret>oldFun()
}
@@ -0,0 +1,15 @@
// "Replace with 'newFun(this)'" "true"
// ERROR: Unresolved reference: newFun
class Outer {
inner class Inner {
@deprecated("", ReplaceWith("newFun(this)"))
fun oldFun() {}
}
fun newFun(inner: Inner) {}
}
fun foo(inner: Outer.Inner) {
<caret>newFun(inner)
}
@@ -0,0 +1,10 @@
// "Replace with 'newFun(p1 + p2)'" "true"
@deprecated("", ReplaceWith("newFun(p1 + p2)"))
fun oldFun(p1: Int, p2: Int) {}
fun newFun(n: Int) {}
fun foo() {
<caret>oldFun(1, 2)
}
@@ -0,0 +1,10 @@
// "Replace with 'newFun(p1 + p2)'" "true"
@deprecated("", ReplaceWith("newFun(p1 + p2)"))
fun oldFun(p1: Int, p2: Int) {}
fun newFun(n: Int) {}
fun foo() {
<caret>newFun(1 + 2)
}