[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:
+5
-2
@@ -95,7 +95,7 @@ internal class KtFirReferenceShortener(
|
|||||||
firDeclaration.accept(collector)
|
firDeclaration.accept(collector)
|
||||||
|
|
||||||
return ShortenCommandImpl(
|
return ShortenCommandImpl(
|
||||||
file,
|
file.createSmartPointer(),
|
||||||
collector.namesToImport.distinct(),
|
collector.namesToImport.distinct(),
|
||||||
collector.namesToImportWithStar.distinct(),
|
collector.namesToImportWithStar.distinct(),
|
||||||
collector.typesToShorten.distinct().map { it.createSmartPointer() },
|
collector.typesToShorten.distinct().map { it.createSmartPointer() },
|
||||||
@@ -616,7 +616,7 @@ private class ElementsToShortenCollector(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private class ShortenCommandImpl(
|
private class ShortenCommandImpl(
|
||||||
val targetFile: KtFile,
|
val targetFile: SmartPsiElementPointer<KtFile>,
|
||||||
val importsToAdd: List<FqName>,
|
val importsToAdd: List<FqName>,
|
||||||
val starImportsToAdd: List<FqName>,
|
val starImportsToAdd: List<FqName>,
|
||||||
val typesToShorten: List<SmartPsiElementPointer<KtUserType>>,
|
val typesToShorten: List<SmartPsiElementPointer<KtUserType>>,
|
||||||
@@ -624,6 +624,9 @@ private class ShortenCommandImpl(
|
|||||||
) : ShortenCommand {
|
) : ShortenCommand {
|
||||||
|
|
||||||
override fun invokeShortening() {
|
override fun invokeShortening() {
|
||||||
|
// if the file has been invalidated, there's nothing we can shorten
|
||||||
|
val targetFile = targetFile.element ?: return
|
||||||
|
|
||||||
for (nameToImport in importsToAdd) {
|
for (nameToImport in importsToAdd) {
|
||||||
addImportToFile(targetFile.project, targetFile, nameToImport)
|
addImportToFile(targetFile.project, targetFile, nameToImport)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user