[Analysis API] Use smart pointer to hold onto KtFile in ShortenCommand

It's a better approach, considering that we already
keep all the PSI element via smart pointers
This commit is contained in:
Roman Golyshev
2022-10-31 12:08:06 +01:00
committed by teamcity
parent c7363adf10
commit c3031ccff5
@@ -95,7 +95,7 @@ internal class KtFirReferenceShortener(
firDeclaration.accept(collector)
return ShortenCommandImpl(
file,
file.createSmartPointer(),
collector.namesToImport.distinct(),
collector.namesToImportWithStar.distinct(),
collector.typesToShorten.distinct().map { it.createSmartPointer() },
@@ -616,7 +616,7 @@ private class ElementsToShortenCollector(
}
private class ShortenCommandImpl(
val targetFile: KtFile,
val targetFile: SmartPsiElementPointer<KtFile>,
val importsToAdd: List<FqName>,
val starImportsToAdd: List<FqName>,
val typesToShorten: List<SmartPsiElementPointer<KtUserType>>,
@@ -624,6 +624,9 @@ private class ShortenCommandImpl(
) : ShortenCommand {
override fun invokeShortening() {
// if the file has been invalidated, there's nothing we can shorten
val targetFile = targetFile.element ?: return
for (nameToImport in importsToAdd) {
addImportToFile(targetFile.project, targetFile, nameToImport)
}