KTIJ-27139 [AA] Shorten qualified expressions only when the callee/type reference is in selection

If you want to shorten call like `foo.bar()` into `bar()`, then you
need your range to intersect with `bar` callee reference. Having only
`foo` in the range is not enough

Same goes for the type references - to shorten `foo.Bar` into `Bar`, you
need at least some intersection of your range with `Bar` reference

^KTIJ-27139 Fixed
^KTIJ-27015 Fixed
This commit is contained in:
Roman Golyshev
2023-09-22 18:54:25 +02:00
committed by teamcity
parent ecbf69504a
commit d2fcd71d23
19 changed files with 244 additions and 6 deletions
@@ -0,0 +1,11 @@
// FILE: main.kt
package test
fun usage() {
<expr>dependency</expr>.foo()
}
// FILE: dependency.kt
package dependency
fun foo() {}
@@ -0,0 +1,5 @@
Before shortening: dependency
with DO_NOT_SHORTEN:
with SHORTEN_IF_ALREADY_IMPORTED:
with SHORTEN_AND_IMPORT:
with SHORTEN_AND_STAR_IMPORT:
@@ -0,0 +1,11 @@
// FILE: main.kt
package test
fun usage() {
dependency.<expr>foo()</expr>
}
// FILE: dependency.kt
package dependency
fun foo() {}
@@ -0,0 +1,7 @@
Before shortening: foo()
with DO_NOT_SHORTEN:
with SHORTEN_IF_ALREADY_IMPORTED:
with SHORTEN_AND_IMPORT:
[qualifier] dependency.foo()
with SHORTEN_AND_STAR_IMPORT:
[qualifier] dependency.foo()
@@ -0,0 +1,11 @@
// FILE: main.kt
package test
fun usage() {
<expr>dependency</expr>.foo()
}
// FILE: dependency.kt
package dependency
val foo: Int = 10
@@ -0,0 +1,5 @@
Before shortening: dependency
with DO_NOT_SHORTEN:
with SHORTEN_IF_ALREADY_IMPORTED:
with SHORTEN_AND_IMPORT:
with SHORTEN_AND_STAR_IMPORT:
@@ -0,0 +1,11 @@
// FILE: main.kt
package test
fun usage() {
dependency.<expr>foo</expr>
}
// FILE: dependency.kt
package dependency
val foo: Int = 10
@@ -0,0 +1,7 @@
Before shortening: foo
with DO_NOT_SHORTEN:
with SHORTEN_IF_ALREADY_IMPORTED:
with SHORTEN_AND_IMPORT:
[qualifier] dependency.foo
with SHORTEN_AND_STAR_IMPORT:
[qualifier] dependency.foo
@@ -0,0 +1,9 @@
// FILE: main.kt
package test
fun usage(foo: <expr>dependency</expr>.Foo) {}
// FILE: dependency.kt
package dependency
class Foo
@@ -0,0 +1,5 @@
Before shortening: dependency
with DO_NOT_SHORTEN:
with SHORTEN_IF_ALREADY_IMPORTED:
with SHORTEN_AND_IMPORT:
with SHORTEN_AND_STAR_IMPORT:
@@ -0,0 +1,9 @@
// FILE: main.kt
package test
fun usage(foo: dependency.<expr>Foo</expr>) {}
// FILE: dependency.kt
package dependency
class Foo
@@ -0,0 +1,7 @@
Before shortening: Foo
with DO_NOT_SHORTEN:
with SHORTEN_IF_ALREADY_IMPORTED:
with SHORTEN_AND_IMPORT:
[type] dependency.Foo
with SHORTEN_AND_STAR_IMPORT:
[type] dependency.Foo
@@ -0,0 +1,13 @@
// FILE: main.kt
package test
fun usage() {
<expr>dependency</expr>.Foo.bar()
}
// FILE: dependency.kt
package dependency
object Foo {
fun bar() {}
}
@@ -0,0 +1,5 @@
Before shortening: dependency
with DO_NOT_SHORTEN:
with SHORTEN_IF_ALREADY_IMPORTED:
with SHORTEN_AND_IMPORT:
with SHORTEN_AND_STAR_IMPORT:
@@ -0,0 +1,13 @@
// FILE: main.kt
package test
fun usage() {
dependency.<expr>Foo</expr>.bar()
}
// FILE: dependency.kt
package dependency
object Foo {
fun bar() {}
}
@@ -0,0 +1,7 @@
Before shortening: Foo
with DO_NOT_SHORTEN:
with SHORTEN_IF_ALREADY_IMPORTED:
with SHORTEN_AND_IMPORT:
[qualifier] dependency.Foo
with SHORTEN_AND_STAR_IMPORT:
[qualifier] dependency.Foo