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 ->
if (symbol is KtEnumEntrySymbol) {
DO_NOT_SHORTEN
} else if (symbol is KtConstructorSymbol && symbol.containingClassIdIfNonLocal?.isNestedClass == true) {
SHORTEN_IF_ALREADY_IMPORTED
} else {
SHORTEN_AND_IMPORT
when (symbol) {
is KtEnumEntrySymbol -> DO_NOT_SHORTEN
is KtConstructorSymbol -> {
val isNestedClassConstructor = symbol.containingClassIdIfNonLocal?.isNestedClass == true
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()
with default settings:
[qualifier] a.b.c.MyClass.Companion.foo()
[qualifier] a.b.c.MyClass
with DO_NOT_SHORTEN:
with SHORTEN_IF_ALREADY_IMPORTED:
[qualifier] a.b.c.MyClass
@@ -1,6 +1,5 @@
Before shortening: C.K
with default settings:
[qualifier] C.K
with DO_NOT_SHORTEN:
with SHORTEN_IF_ALREADY_IMPORTED:
with SHORTEN_AND_IMPORT:
@@ -1,6 +1,5 @@
Before shortening: C.foo()
with default settings:
[qualifier] C.foo()
with DO_NOT_SHORTEN:
with SHORTEN_IF_ALREADY_IMPORTED:
with SHORTEN_AND_IMPORT:
@@ -1,7 +1,7 @@
Before shortening: x.y.z.Outer.Inner.VALUE0 > x.y.z.Outer.Inner.VALUE1
with default settings:
[qualifier] x.y.z.Outer.Inner.VALUE0
[qualifier] x.y.z.Outer.Inner.VALUE1
[qualifier] x.y.z.Outer
[qualifier] x.y.z.Outer
with DO_NOT_SHORTEN:
with SHORTEN_IF_ALREADY_IMPORTED:
with SHORTEN_AND_IMPORT: