Refactor and fix of the run/apply/let/also intention converter

1) Optimize and refactored code
2) Added support for correct renaming of target identifier to this/it
3) Added support of cases with difficult application targets (like: var x = 1 + 2)
4) Show error hint when refactoring failed for some reason
5) Improved intention applicability checking to eliminate false-positive cases
6) Fixed EA-209577
This commit is contained in:
Igor Yakovlev
2019-08-09 21:27:22 +03:00
parent ef5fcb4e9e
commit 5a511dd635
35 changed files with 615 additions and 140 deletions
@@ -1,14 +1,10 @@
// WITH_RUNTIME
class MyClass {
fun foo1() = Unit
fun foo2() = Unit
fun foo3() = Unit
fun foo4() {
val a = MyClass()
a.foo1()<caret>
a.foo2()
a.foo3()
fun foo(c: Int) {
val a = 23
a.dec()
a.dec()<caret>
a.dec() + a
}
}
@@ -1,16 +1,12 @@
// WITH_RUNTIME
class MyClass {
fun foo1() = Unit
fun foo2() = Unit
fun foo3() = Unit
fun foo4() {
val a = MyClass()
fun foo(c: Int) {
val a = 23
with(a) {
foo1()
foo2()
foo3()
dec()
dec()
dec() + this
}
}
}
@@ -0,0 +1,14 @@
// WITH_RUNTIME
class MyClass {
fun foo1() = Unit
fun foo2() = Unit
fun foo3() = Unit
fun foo4() {
val a = MyClass()
a.foo1()<caret>
a.foo2()
a.foo3()
}
}
@@ -0,0 +1,16 @@
// WITH_RUNTIME
class MyClass {
fun foo1() = Unit
fun foo2() = Unit
fun foo3() = Unit
fun foo4() {
val a = MyClass()
with(a) {
foo1()
foo2()
foo3()
}
}
}
@@ -0,0 +1,9 @@
// WITH_RUNTIME
class MyClass {
fun foo() {
val c = 2
c.div(2)<caret>
c.div(c + 2 + c) + c.div(c)
}
}
@@ -0,0 +1,11 @@
// WITH_RUNTIME
class MyClass {
fun foo() {
val c = 2
with(c) {
div(2)
div(this + 2 + this) + div(this)
}
}
}
@@ -0,0 +1,10 @@
// WITH_RUNTIME
// IS_APPLICABLE: false
class MyClass {
fun foo() {
val c = 2
c.div(2) + 3<caret>
c.div(c + 2 + c) + c.div(c)
}
}
@@ -0,0 +1,10 @@
// WITH_RUNTIME
// IS_APPLICABLE: false
class MyClass {
fun foo() {
val c = 2
(c.div(2) + 3)<caret>
c.div(c + 2 + c) + c.div(c)
}
}