Copy: Fix import insertion on declaration copying
#KT-19909 Fixed
This commit is contained in:
+2
-1
@@ -265,6 +265,7 @@ class CopyKotlinDeclarationsHandler : CopyHandlerDelegateBase() {
|
|||||||
runWriteAction {
|
runWriteAction {
|
||||||
val newElements = elementsToCopy.map { targetFile.add(it.copy()) as KtNamedDeclaration }
|
val newElements = elementsToCopy.map { targetFile.add(it.copy()) as KtNamedDeclaration }
|
||||||
elementsToCopy.zip(newElements).toMap(oldToNewElementsMapping)
|
elementsToCopy.zip(newElements).toMap(oldToNewElementsMapping)
|
||||||
|
oldToNewElementsMapping[originalFile] = targetFile
|
||||||
|
|
||||||
for (newElement in oldToNewElementsMapping.values) {
|
for (newElement in oldToNewElementsMapping.values) {
|
||||||
restoredInternalUsages += restoreInternalUsages(newElement as KtElement, oldToNewElementsMapping, true)
|
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
|
if (newName == newDeclaration.name) return@let
|
||||||
val selfReferences = ReferencesSearch.search(newDeclaration, LocalSearchScope(newDeclaration)).findAll()
|
val selfReferences = ReferencesSearch.search(newDeclaration, LocalSearchScope(newDeclaration)).findAll()
|
||||||
runWriteAction {
|
runWriteAction {
|
||||||
|
|||||||
@@ -0,0 +1,3 @@
|
|||||||
|
package bar
|
||||||
|
|
||||||
|
fun Any.bar() {}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
package foo
|
||||||
|
|
||||||
|
import bar.bar
|
||||||
|
|
||||||
|
class Foo {
|
||||||
|
init {
|
||||||
|
42.bar()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class Baz {
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
package foo
|
||||||
|
|
||||||
|
import bar.bar
|
||||||
|
|
||||||
|
class Foo2 {
|
||||||
|
init {
|
||||||
|
42.bar()
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
package bar
|
||||||
|
|
||||||
|
fun Any.bar() {}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
package foo
|
||||||
|
|
||||||
|
import bar.bar
|
||||||
|
|
||||||
|
class <caret>Foo {
|
||||||
|
init {
|
||||||
|
42.bar()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class Baz {
|
||||||
|
}
|
||||||
+5
@@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"mainFile": "foo/Foo.kt",
|
||||||
|
"targetPackage": "foo",
|
||||||
|
"newName": "Foo2"
|
||||||
|
}
|
||||||
@@ -198,6 +198,12 @@ public class CopyTestGenerated extends AbstractCopyTest {
|
|||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("copyWithImportInsertion/copyWithImportInsertion.test")
|
||||||
|
public void testCopyWithImportInsertion_CopyWithImportInsertion() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/copy/copyWithImportInsertion/copyWithImportInsertion.test");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("kt18149/kt18149.test")
|
@TestMetadata("kt18149/kt18149.test")
|
||||||
public void testKt18149_Kt18149() throws Exception {
|
public void testKt18149_Kt18149() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/copy/kt18149/kt18149.test");
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/copy/kt18149/kt18149.test");
|
||||||
|
|||||||
Reference in New Issue
Block a user