KTIJ-28080 [AA] Refactor ElementsToShortenCollector.findClassifierElementsToShorten

Move unrolling the qualifiers into the function, add some simple KDoc
This commit is contained in:
Roman Golyshev
2024-01-05 13:26:16 +01:00
committed by teamcity
parent 8f79d519b8
commit 3b448b284c
@@ -613,12 +613,10 @@ private class ElementsToShortenCollector(
withImplicitReceivers = false, withImplicitReceivers = false,
) ?: return null ) ?: return null
val allClassIds = wholeClassQualifier.outerClassesWithSelf return findClassifierQualifierToShorten(
val allQualifiers = wholeQualifierElement.qualifiedElementsWithSelf
return findClassifierElementsToShorten(
positionScopes, positionScopes,
allClassIds, wholeClassQualifier,
allQualifiers, wholeQualifierElement,
) )
} }
@@ -828,11 +826,18 @@ private class ElementsToShortenCollector(
return createElementToShorten(referenceExpression, shortenedRef = aliasedName) return createElementToShorten(referenceExpression, shortenedRef = aliasedName)
} }
private fun findClassifierElementsToShorten( /**
* Finds the longest qualifier in [wholeQualifierElement] which can be safely shortened in the [positionScopes].
* [wholeQualifierClassId] is supposed to reflect the class which is referenced by the [wholeQualifierElement].
*/
private fun findClassifierQualifierToShorten(
positionScopes: List<FirScope>, positionScopes: List<FirScope>,
allClassIds: Sequence<ClassId>, wholeQualifierClassId: ClassId,
allQualifiedElements: Sequence<KtElement>, wholeQualifierElement: KtElement,
): ElementToShorten? { ): ElementToShorten? {
val allClassIds = wholeQualifierClassId.outerClassesWithSelf
val allQualifiedElements = wholeQualifierElement.qualifiedElementsWithSelf
for ((classId, element) in allClassIds.zip(allQualifiedElements)) { for ((classId, element) in allClassIds.zip(allQualifiedElements)) {
val classSymbol = shorteningContext.toClassSymbol(classId) ?: return null val classSymbol = shorteningContext.toClassSymbol(classId) ?: return null
val option = classShortenStrategy(classSymbol) val option = classShortenStrategy(classSymbol)