Improve "ReplaceWith" for class with generic parameter

#KT-27089 Fixed
This commit is contained in:
Dmitry Gridin
2019-03-28 17:33:26 +07:00
parent 88b0db6dd7
commit 09b58403b9
25 changed files with 238 additions and 25 deletions
@@ -1,4 +1,4 @@
// "Replace with 'NewClass<T>'" "true"
// "Replace with 'NewClass<Int>'" "true"
package ppp
@Deprecated("renamed", ReplaceWith("NewClass<T>"))
@@ -1,4 +1,4 @@
// "Replace with 'NewClass<T>'" "true"
// "Replace with 'NewClass<Int>'" "true"
package ppp
@Deprecated("renamed", ReplaceWith("NewClass<T>"))
@@ -0,0 +1,9 @@
// "Replace with 'Factory<Int>()'" "true"
// WITH_RUNTIME
class Foo<T> @Deprecated("", ReplaceWith("Factory<T>()")) constructor()
fun <T> Factory(): Foo<T> = TODO()
fun baz() {
val foo = <caret>Foo<Int>()
}
@@ -0,0 +1,9 @@
// "Replace with 'Factory<Int>()'" "true"
// WITH_RUNTIME
class Foo<T> @Deprecated("", ReplaceWith("Factory<T>()")) constructor()
fun <T> Factory(): Foo<T> = TODO()
fun baz() {
val foo = <caret>Factory<Int>()
}
@@ -0,0 +1,9 @@
// "Replace with 'Factory<Int>()'" "true"
// WITH_RUNTIME
class Foo<T> @Deprecated("", ReplaceWith("Factory()")) constructor()
fun <T> Factory(): Foo<T> = TODO()
fun baz() {
val foo = <caret>Foo<Int>()
}
@@ -0,0 +1,9 @@
// "Replace with 'Factory<Int>()'" "true"
// WITH_RUNTIME
class Foo<T> @Deprecated("", ReplaceWith("Factory()")) constructor()
fun <T> Factory(): Foo<T> = TODO()
fun baz() {
val foo = <caret>Factory<Int>()
}
@@ -0,0 +1,15 @@
// "Replace with 'test.New'" "true"
// WITH_RUNTIME
package test
abstract class Main<T>
@Deprecated("", ReplaceWith("test.New"))
class Old<T> : Main<T>()
class New<T> : Main<T>()
fun test() {
val main = <caret>Old<Int>()
}
@@ -0,0 +1,15 @@
// "Replace with 'test.New'" "true"
// WITH_RUNTIME
package test
abstract class Main<T>
@Deprecated("", ReplaceWith("test.New"))
class Old<T> : Main<T>()
class New<T> : Main<T>()
fun test() {
val main = <caret>New<Int>()
}
@@ -0,0 +1,14 @@
// "Replace with 'New'" "true"
// WITH_RUNTIME
// ERROR: Type inference failed: Not enough information to infer parameter T in constructor New<T>()<br>Please specify it explicitly.<br>
abstract class Main<T>
@Deprecated("", ReplaceWith("New"))
class Old<T, F> : Main<T>()
class New<T> : Main<T>()
fun test() {
val main = <caret>Old<Int, String>()
}
@@ -0,0 +1,14 @@
// "Replace with 'New'" "true"
// WITH_RUNTIME
// ERROR: Type inference failed: Not enough information to infer parameter T in constructor New<T>()<br>Please specify it explicitly.<br>
abstract class Main<T>
@Deprecated("", ReplaceWith("New"))
class Old<T, F> : Main<T>()
class New<T> : Main<T>()
fun test() {
val main = <caret>New()
}
@@ -0,0 +1,9 @@
// "Replace with 'Factory()'" "true"
// WITH_RUNTIME
class Foo<T> @Deprecated("", ReplaceWith("Factory<T>()")) constructor()
fun <T> Factory(): Foo<T> = TODO()
fun baz() {
val foo: Foo<Int> = <caret>Foo()
}
@@ -0,0 +1,9 @@
// "Replace with 'Factory()'" "true"
// WITH_RUNTIME
class Foo<T> @Deprecated("", ReplaceWith("Factory<T>()")) constructor()
fun <T> Factory(): Foo<T> = TODO()
fun baz() {
val foo: Foo<Int> = <caret>Factory()
}
@@ -1,4 +1,4 @@
// "Replace with 'newFun(*elements)'" "true"
// "Replace with 'newFun<String>(*elements)'" "true"
// WITH_RUNTIME
@Deprecated("", ReplaceWith("newFun(*elements)"))
@@ -1,4 +1,4 @@
// "Replace with 'newFun(*elements)'" "true"
// "Replace with 'newFun<String>(*elements)'" "true"
// WITH_RUNTIME
@Deprecated("", ReplaceWith("newFun(*elements)"))
@@ -1,4 +1,4 @@
// "Replace with 'newFun<T>()'" "true"
// "Replace with 'newFun()'" "true"
@Deprecated("", ReplaceWith("newFun<T>()"))
fun <T : Any> oldFun(): T? {
@@ -1,4 +1,4 @@
// "Replace with 'newFun<T>()'" "true"
// "Replace with 'newFun()'" "true"
@Deprecated("", ReplaceWith("newFun<T>()"))
fun <T : Any> oldFun(): T? {
@@ -1,4 +1,4 @@
// "Replace with 'newFun<T>()'" "true"
// "Replace with 'newFun<String>()'" "true"
@Deprecated("", ReplaceWith("newFun<T>()"))
fun <T> oldFun() {
@@ -1,4 +1,4 @@
// "Replace with 'newFun<T>()'" "true"
// "Replace with 'newFun<String>()'" "true"
@Deprecated("", ReplaceWith("newFun<T>()"))
fun <T> oldFun() {
@@ -1,4 +1,4 @@
// "Replace with 'newFun<T>()'" "true"
// "Replace with 'newFun<kotlin.Int>()'" "true"
@Deprecated("", ReplaceWith("newFun<T>()"))
fun <T> oldFun() {
@@ -1,4 +1,4 @@
// "Replace with 'newFun<T>()'" "true"
// "Replace with 'newFun<kotlin.Int>()'" "true"
@Deprecated("", ReplaceWith("newFun<T>()"))
fun <T> oldFun() {
@@ -8,5 +8,5 @@ fun <T> oldFun() {
fun <T> newFun(){}
fun foo() {
<caret>newFun<kotlin.Int>()
<caret>newFun<Int>()
}