KTIJ-27841 [AA] Refactor ElementsToShortenCollector.processCallableQualifiedAccess

Rename it, and return `ElementToShorten` from it
This commit is contained in:
Roman Golyshev
2024-01-10 18:26:47 +01:00
committed by teamcity
parent d0d29bea57
commit 702be98927
@@ -1131,12 +1131,12 @@ private class ElementsToShortenCollector(
} }
if (option == ShortenStrategy.SHORTEN_IF_ALREADY_IMPORTED) return if (option == ShortenStrategy.SHORTEN_IF_ALREADY_IMPORTED) return
processCallableQualifiedAccess( findCallableQualifiedAccessToShorten(
propertySymbol, propertySymbol,
option, option,
qualifiedProperty, qualifiedProperty,
availableCallables, availableCallables,
) )?.let(::addElementToShorten)
} }
private val FirPropertyAccessExpression.correspondingNameReference: KtNameReferenceExpression? private val FirPropertyAccessExpression.correspondingNameReference: KtNameReferenceExpression?
@@ -1182,34 +1182,34 @@ private class ElementsToShortenCollector(
} }
if (option == ShortenStrategy.SHORTEN_IF_ALREADY_IMPORTED) return if (option == ShortenStrategy.SHORTEN_IF_ALREADY_IMPORTED) return
processCallableQualifiedAccess( findCallableQualifiedAccessToShorten(
calledSymbol, calledSymbol,
option, option,
qualifiedCallExpression, qualifiedCallExpression,
availableCallables, availableCallables,
) )?.let(::addElementToShorten)
} }
private fun processCallableQualifiedAccess( private fun findCallableQualifiedAccessToShorten(
calledSymbol: FirCallableSymbol<*>, calledSymbol: FirCallableSymbol<*>,
option: ShortenStrategy, option: ShortenStrategy,
qualifiedCallExpression: KtDotQualifiedExpression, qualifiedCallExpression: KtDotQualifiedExpression,
availableCallables: List<AvailableSymbol<FirCallableSymbol<*>>>, availableCallables: List<AvailableSymbol<FirCallableSymbol<*>>>,
) { ): ElementToShorten? {
if (option == ShortenStrategy.DO_NOT_SHORTEN) return if (option == ShortenStrategy.DO_NOT_SHORTEN) return null
val nameToImport = shorteningContext.convertToImportableName(calledSymbol) val nameToImport = shorteningContext.convertToImportableName(calledSymbol)
val (matchedCallables, otherCallables) = availableCallables.partition { it.symbol.callableId == calledSymbol.callableId } val (matchedCallables, otherCallables) = availableCallables.partition { it.symbol.callableId == calledSymbol.callableId }
val importKindFromOption = ImportKind.fromShortenOption(option) val importKindFromOption = ImportKind.fromShortenOption(option)
val importKind = matchedCallables.minOfOrNull { it.importKind } ?: importKindFromOption ?: return val importKind = matchedCallables.minOfOrNull { it.importKind } ?: importKindFromOption ?: return null
val callToShorten = when { val callToShorten = when {
otherCallables.all { importKind.hasHigherPriorityThan(it.importKind) } -> { otherCallables.all { importKind.hasHigherPriorityThan(it.importKind) } -> {
when { when {
matchedCallables.isEmpty() -> { matchedCallables.isEmpty() -> {
if (nameToImport == null || option == ShortenStrategy.SHORTEN_IF_ALREADY_IMPORTED) return if (nameToImport == null || option == ShortenStrategy.SHORTEN_IF_ALREADY_IMPORTED) return null
createElementToShorten( createElementToShorten(
qualifiedCallExpression, qualifiedCallExpression,
nameToImport, nameToImport,
@@ -1225,7 +1225,7 @@ private class ElementsToShortenCollector(
else -> findFakePackageToShorten(qualifiedCallExpression) else -> findFakePackageToShorten(qualifiedCallExpression)
} }
callToShorten?.let(::addElementToShorten) return callToShorten
} }
private fun canBePossibleToDropReceiver(qualifiedAccess: FirQualifiedAccessExpression): Boolean { private fun canBePossibleToDropReceiver(qualifiedAccess: FirQualifiedAccessExpression): Boolean {