KT-64205 [AA] Adjust defaultCallableShortenStrategy to import only top-level callables

^KT-64205 Fixed
This commit is contained in:
Roman Golyshev
2023-12-13 16:58:10 +02:00
committed by teamcity
parent d5896f20f0
commit deb7999bfb
5 changed files with 25 additions and 11 deletions
@@ -87,12 +87,28 @@ public enum class ShortenStrategy {
} }
public val defaultCallableShortenStrategy: (KtCallableSymbol) -> ShortenStrategy = { symbol -> public val defaultCallableShortenStrategy: (KtCallableSymbol) -> ShortenStrategy = { symbol ->
if (symbol is KtEnumEntrySymbol) { when (symbol) {
DO_NOT_SHORTEN is KtEnumEntrySymbol -> DO_NOT_SHORTEN
} else if (symbol is KtConstructorSymbol && symbol.containingClassIdIfNonLocal?.isNestedClass == true) {
SHORTEN_IF_ALREADY_IMPORTED is KtConstructorSymbol -> {
} else { val isNestedClassConstructor = symbol.containingClassIdIfNonLocal?.isNestedClass == true
SHORTEN_AND_IMPORT
if (isNestedClassConstructor) {
SHORTEN_IF_ALREADY_IMPORTED
} else {
SHORTEN_AND_IMPORT
}
}
else -> {
val isNotTopLevel = symbol.callableIdIfNonLocal?.classId != null
if (isNotTopLevel) {
SHORTEN_IF_ALREADY_IMPORTED
} else {
SHORTEN_AND_IMPORT
}
}
} }
} }
} }
@@ -1,6 +1,6 @@
Before shortening: a.b.c.MyClass.Companion.foo() Before shortening: a.b.c.MyClass.Companion.foo()
with default settings: with default settings:
[qualifier] a.b.c.MyClass.Companion.foo() [qualifier] a.b.c.MyClass
with DO_NOT_SHORTEN: with DO_NOT_SHORTEN:
with SHORTEN_IF_ALREADY_IMPORTED: with SHORTEN_IF_ALREADY_IMPORTED:
[qualifier] a.b.c.MyClass [qualifier] a.b.c.MyClass
@@ -1,6 +1,5 @@
Before shortening: C.K Before shortening: C.K
with default settings: with default settings:
[qualifier] C.K
with DO_NOT_SHORTEN: with DO_NOT_SHORTEN:
with SHORTEN_IF_ALREADY_IMPORTED: with SHORTEN_IF_ALREADY_IMPORTED:
with SHORTEN_AND_IMPORT: with SHORTEN_AND_IMPORT:
@@ -1,6 +1,5 @@
Before shortening: C.foo() Before shortening: C.foo()
with default settings: with default settings:
[qualifier] C.foo()
with DO_NOT_SHORTEN: with DO_NOT_SHORTEN:
with SHORTEN_IF_ALREADY_IMPORTED: with SHORTEN_IF_ALREADY_IMPORTED:
with SHORTEN_AND_IMPORT: with SHORTEN_AND_IMPORT:
@@ -1,7 +1,7 @@
Before shortening: x.y.z.Outer.Inner.VALUE0 > x.y.z.Outer.Inner.VALUE1 Before shortening: x.y.z.Outer.Inner.VALUE0 > x.y.z.Outer.Inner.VALUE1
with default settings: with default settings:
[qualifier] x.y.z.Outer.Inner.VALUE0 [qualifier] x.y.z.Outer
[qualifier] x.y.z.Outer.Inner.VALUE1 [qualifier] x.y.z.Outer
with DO_NOT_SHORTEN: with DO_NOT_SHORTEN:
with SHORTEN_IF_ALREADY_IMPORTED: with SHORTEN_IF_ALREADY_IMPORTED:
with SHORTEN_AND_IMPORT: with SHORTEN_AND_IMPORT: