Copy: Fix import insertion on declaration copying

#KT-19909 Fixed
This commit is contained in:
Alexey Sedunov
2017-09-19 16:37:09 +03:00
parent 0beadddb7f
commit c8c0ab1647
8 changed files with 52 additions and 1 deletions
@@ -265,6 +265,7 @@ class CopyKotlinDeclarationsHandler : CopyHandlerDelegateBase() {
runWriteAction {
val newElements = elementsToCopy.map { targetFile.add(it.copy()) as KtNamedDeclaration }
elementsToCopy.zip(newElements).toMap(oldToNewElementsMapping)
oldToNewElementsMapping[originalFile] = targetFile
for (newElement in oldToNewElementsMapping.values) {
restoredInternalUsages += restoreInternalUsages(newElement as KtElement, oldToNewElementsMapping, true)
@@ -275,7 +276,7 @@ class CopyKotlinDeclarationsHandler : CopyHandlerDelegateBase() {
}
}
(oldToNewElementsMapping.values.singleOrNull() as? KtNamedDeclaration)?.let { newDeclaration ->
(oldToNewElementsMapping.values.filterIsInstance<KtNamedDeclaration>().singleOrNull())?.let { newDeclaration ->
if (newName == newDeclaration.name) return@let
val selfReferences = ReferencesSearch.search(newDeclaration, LocalSearchScope(newDeclaration)).findAll()
runWriteAction {