KT-62675 [AA] Get rid of second override of ElementsToShortenCollector.addElementToShorten
Those two overrides were odd - one of them was deconstructing `ElementToShorten` into its fields, and the other one was re-constructing it back
This commit is contained in:
+16
-29
@@ -380,19 +380,20 @@ private class FirShorteningContext(val analysisSession: KtFirAnalysisSession) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private sealed class ElementToShorten {
|
private sealed class ElementToShorten {
|
||||||
|
abstract val element: KtElement
|
||||||
abstract val nameToImport: FqName?
|
abstract val nameToImport: FqName?
|
||||||
abstract val importAllInParent: Boolean
|
abstract val importAllInParent: Boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
private class ShortenType(
|
private class ShortenType(
|
||||||
val element: KtUserType,
|
override val element: KtUserType,
|
||||||
val shortenedRef: String? = null,
|
val shortenedRef: String? = null,
|
||||||
override val nameToImport: FqName? = null,
|
override val nameToImport: FqName? = null,
|
||||||
override val importAllInParent: Boolean = false,
|
override val importAllInParent: Boolean = false,
|
||||||
) : ElementToShorten()
|
) : ElementToShorten()
|
||||||
|
|
||||||
private class ShortenQualifier(
|
private class ShortenQualifier(
|
||||||
val element: KtDotQualifiedExpression,
|
override val element: KtDotQualifiedExpression,
|
||||||
val shortenedRef: String? = null,
|
val shortenedRef: String? = null,
|
||||||
override val nameToImport: FqName? = null,
|
override val nameToImport: FqName? = null,
|
||||||
override val importAllInParent: Boolean = false
|
override val importAllInParent: Boolean = false
|
||||||
@@ -845,10 +846,16 @@ private class ElementsToShortenCollector(
|
|||||||
|
|
||||||
private fun createElementToShorten(
|
private fun createElementToShorten(
|
||||||
element: KtElement,
|
element: KtElement,
|
||||||
nameToImport: FqName? = null,
|
referencedSymbol: FqName? = null,
|
||||||
importAllInParent: Boolean = false,
|
importAllInParent: Boolean = false,
|
||||||
shortenedRef: String? = null,
|
shortenedRef: String? = null,
|
||||||
): ElementToShorten {
|
): ElementToShorten {
|
||||||
|
var nameToImport = if (importAllInParent) {
|
||||||
|
referencedSymbol?.parentOrNull() ?: error("Provided FqName '$referencedSymbol' cannot be imported with a star")
|
||||||
|
} else {
|
||||||
|
referencedSymbol
|
||||||
|
}
|
||||||
|
|
||||||
return when (element) {
|
return when (element) {
|
||||||
is KtUserType -> ShortenType(element, shortenedRef, nameToImport, importAllInParent)
|
is KtUserType -> ShortenType(element, shortenedRef, nameToImport, importAllInParent)
|
||||||
is KtDotQualifiedExpression -> ShortenQualifier(element, shortenedRef, nameToImport, importAllInParent)
|
is KtDotQualifiedExpression -> ShortenQualifier(element, shortenedRef, nameToImport, importAllInParent)
|
||||||
@@ -1232,37 +1239,17 @@ private class ElementsToShortenCollector(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun addElementToShorten(element: KtElement, shortenedRef: String?, nameToImport: FqName?, isImportWithStar: Boolean) {
|
private fun addElementToShorten(elementInfoToShorten: ElementToShorten) {
|
||||||
val qualifier = element.getQualifier() ?: return
|
val qualifier = elementInfoToShorten.element.getQualifier() ?: return
|
||||||
if (!qualifier.isAlreadyCollected()) {
|
if (!qualifier.isAlreadyCollected()) {
|
||||||
removeRedundantElements(qualifier)
|
removeRedundantElements(qualifier)
|
||||||
when (element) {
|
when (elementInfoToShorten) {
|
||||||
is KtUserType -> typesToShorten.add(ShortenType(element, shortenedRef, nameToImport, isImportWithStar))
|
is ShortenType -> typesToShorten.add(elementInfoToShorten)
|
||||||
is KtDotQualifiedExpression -> qualifiersToShorten.add(
|
is ShortenQualifier -> qualifiersToShorten.add(elementInfoToShorten)
|
||||||
ShortenQualifier(
|
|
||||||
element, shortenedRef, nameToImport, isImportWithStar
|
|
||||||
)
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun addElementToShorten(elementInfoToShorten: ElementToShorten) {
|
|
||||||
val (nameToImport, isImportWithStar) = if (elementInfoToShorten.importAllInParent && elementInfoToShorten.nameToImport?.parentOrNull()?.isRoot == false) {
|
|
||||||
elementInfoToShorten.nameToImport?.parent() to true
|
|
||||||
} else {
|
|
||||||
elementInfoToShorten.nameToImport to false
|
|
||||||
}
|
|
||||||
when (elementInfoToShorten) {
|
|
||||||
is ShortenType -> addElementToShorten(
|
|
||||||
elementInfoToShorten.element, elementInfoToShorten.shortenedRef, nameToImport, isImportWithStar
|
|
||||||
)
|
|
||||||
is ShortenQualifier -> addElementToShorten(
|
|
||||||
elementInfoToShorten.element, elementInfoToShorten.shortenedRef, nameToImport, isImportWithStar
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks whether type reference of [this] type is considered to be in the [selection] text range.
|
* Checks whether type reference of [this] type is considered to be in the [selection] text range.
|
||||||
*
|
*
|
||||||
@@ -1421,5 +1408,5 @@ internal fun KtSimpleNameExpression.getDotQualifiedExpressionForSelector(): KtDo
|
|||||||
private fun KtElement.getQualifier(): KtElement? = when (this) {
|
private fun KtElement.getQualifier(): KtElement? = when (this) {
|
||||||
is KtUserType -> qualifier
|
is KtUserType -> qualifier
|
||||||
is KtDotQualifiedExpression -> receiverExpression
|
is KtDotQualifiedExpression -> receiverExpression
|
||||||
else -> null
|
else -> error("Unexpected ${this::class}")
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user