[K2] Avoid shortening duplicated PSI elements
The existing K2 reference shortener collects all the PSI elements to
shorten. As a result, it possibly shortens duplicated PSI elements. For
example,
```
// FILE: main.kt
package a.b.c
fun test(n: Int) {
return if (<expr>x.y.z.Outer.Inner.VALUE0 > x.y.z.Outer.Inner.VALUE1</expr>) 1
else n
}
// FILE: values.kt
package x.y.z
class Outer {
object Inner {
val VALUE0 = 13
val VALUE1 = 17
}
}
```
for the above code, the existing K2 reference shortener tried to shorten
- x.y.z.Outer.Inner -> Inner
- x.y.z.Outer.Inner.VALUE0 -> VALUE0
- x.y.z.Outer.Inner -> Inner
- x.y.z.Outer.Inner.VALUE1 -> VALUE1
`x.y.z.Outer.Inner` is included in the list to shorten twice.
When it actually shortens the PSI elements, it shortens only
- x.y.z.Outer.Inner.VALUE0 -> VALUE0
- x.y.z.Outer.Inner.VALUE1 -> VALUE1
but it imports all of
- x.y.z.Outer.Inner
- x.y.z.Outer.Inner.VALUE0
- x.y.z.Outer.Inner.VALUE1
As a result, it has unnecessary additional import directives.
This commit fixes the issue by avoiding duplicated shortening for a
single PSI element.
This commit is contained in:
Vendored
-3
@@ -1,11 +1,8 @@
|
||||
Before shortening: Child.Foo.check()
|
||||
with DO_NOT_SHORTEN:
|
||||
with SHORTEN_IF_ALREADY_IMPORTED:
|
||||
[qualifier] Child.Foo
|
||||
[qualifier] Child.Foo.check()
|
||||
with SHORTEN_AND_IMPORT:
|
||||
[qualifier] Child.Foo
|
||||
[qualifier] Child.Foo.check()
|
||||
with SHORTEN_AND_STAR_IMPORT:
|
||||
[qualifier] Child.Foo
|
||||
[qualifier] Child.Foo.check()
|
||||
|
||||
-3
@@ -1,11 +1,8 @@
|
||||
Before shortening: a.b.c.MyEnum.Companion.foo()
|
||||
with DO_NOT_SHORTEN:
|
||||
with SHORTEN_IF_ALREADY_IMPORTED:
|
||||
[qualifier] a.b.c.MyEnum
|
||||
[qualifier] a.b.c.MyEnum.Companion.foo()
|
||||
with SHORTEN_AND_IMPORT:
|
||||
[qualifier] a.b.c.MyEnum.Companion
|
||||
[qualifier] a.b.c.MyEnum.Companion.foo()
|
||||
with SHORTEN_AND_STAR_IMPORT:
|
||||
[qualifier] a.b.c.MyEnum.Companion
|
||||
[qualifier] a.b.c.MyEnum.Companion.foo()
|
||||
|
||||
Vendored
+16
@@ -0,0 +1,16 @@
|
||||
// FILE: main.kt
|
||||
package a.b.c
|
||||
|
||||
fun test(n: Int) {
|
||||
return if (<expr>x.y.z.Outer.Inner.VALUE0 > x.y.z.Outer.Inner.VALUE1</expr>) 1
|
||||
else n
|
||||
}
|
||||
// FILE: values.kt
|
||||
package x.y.z
|
||||
|
||||
class Outer {
|
||||
object Inner {
|
||||
val VALUE0 = 13
|
||||
val VALUE1 = 17
|
||||
}
|
||||
}
|
||||
Vendored
+9
@@ -0,0 +1,9 @@
|
||||
Before shortening: x.y.z.Outer.Inner.VALUE0 > x.y.z.Outer.Inner.VALUE1
|
||||
with DO_NOT_SHORTEN:
|
||||
with SHORTEN_IF_ALREADY_IMPORTED:
|
||||
with SHORTEN_AND_IMPORT:
|
||||
[qualifier] x.y.z.Outer.Inner.VALUE0
|
||||
[qualifier] x.y.z.Outer.Inner.VALUE1
|
||||
with SHORTEN_AND_STAR_IMPORT:
|
||||
[qualifier] x.y.z.Outer.Inner.VALUE0
|
||||
[qualifier] x.y.z.Outer.Inner.VALUE1
|
||||
-3
@@ -1,11 +1,8 @@
|
||||
Before shortening: Outer.Inner.foo()
|
||||
with DO_NOT_SHORTEN:
|
||||
with SHORTEN_IF_ALREADY_IMPORTED:
|
||||
[qualifier] Outer.Inner
|
||||
[qualifier] Outer.Inner.foo()
|
||||
with SHORTEN_AND_IMPORT:
|
||||
[qualifier] Outer.Inner
|
||||
[qualifier] Outer.Inner.foo()
|
||||
with SHORTEN_AND_STAR_IMPORT:
|
||||
[qualifier] Outer.Inner
|
||||
[qualifier] Outer.Inner.foo()
|
||||
|
||||
Reference in New Issue
Block a user