Move File/Change Package: Change package directive prior to processing of internal usages (otherwise some necessary imports are not added)
This commit is contained in:
+1
-1
@@ -61,8 +61,8 @@ public class KotlinChangePackageRefactoring(val file: JetFile) {
|
|||||||
val internalUsages = file.getInternalReferencesToUpdateOnPackageNameChange(PackageNameInfo(currentFqName, newFqName))
|
val internalUsages = file.getInternalReferencesToUpdateOnPackageNameChange(PackageNameInfo(currentFqName, newFqName))
|
||||||
|
|
||||||
project.executeWriteCommand("Change file's package to '${newFqName.asString()}'") {
|
project.executeWriteCommand("Change file's package to '${newFqName.asString()}'") {
|
||||||
postProcessMoveUsages(internalUsages)
|
|
||||||
packageDirective.setFqName(newFqName)
|
packageDirective.setFqName(newFqName)
|
||||||
|
postProcessMoveUsages(internalUsages)
|
||||||
project.runWithElementsToShortenIsEmptyIgnored { declarationProcessor.execute(declarationUsages) }
|
project.runWithElementsToShortenIsEmptyIgnored { declarationProcessor.execute(declarationUsages) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-1
@@ -94,8 +94,9 @@ public class MoveKotlinFileHandler : MoveFileHandler() {
|
|||||||
if (file !is JetFile) return
|
if (file !is JetFile) return
|
||||||
val packageNameInfo = packageNameInfo ?: return
|
val packageNameInfo = packageNameInfo ?: return
|
||||||
|
|
||||||
postProcessMoveUsages(file.getInternalReferencesToUpdateOnPackageNameChange(packageNameInfo))
|
val internalUsages = file.getInternalReferencesToUpdateOnPackageNameChange(packageNameInfo)
|
||||||
file.getPackageDirective()?.setFqName(packageNameInfo.newPackageName)
|
file.getPackageDirective()?.setFqName(packageNameInfo.newPackageName)
|
||||||
|
postProcessMoveUsages(internalUsages)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun retargetUsages(usageInfos: List<UsageInfo>?, oldToNewMap: Map<PsiElement, PsiElement>?) {
|
override fun retargetUsages(usageInfos: List<UsageInfo>?, oldToNewMap: Map<PsiElement, PsiElement>?) {
|
||||||
|
|||||||
+5
@@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"mainFile": "source/foo.kt",
|
||||||
|
"type": "CHANGE_PACKAGE_DIRECTIVE",
|
||||||
|
"newPackageName": "source"
|
||||||
|
}
|
||||||
+7
@@ -0,0 +1,7 @@
|
|||||||
|
package target
|
||||||
|
|
||||||
|
import source.C
|
||||||
|
|
||||||
|
fun C.foo() {
|
||||||
|
|
||||||
|
}
|
||||||
+9
@@ -0,0 +1,9 @@
|
|||||||
|
package source
|
||||||
|
|
||||||
|
import target.foo
|
||||||
|
|
||||||
|
class C
|
||||||
|
|
||||||
|
fun test(c: C) {
|
||||||
|
c.foo()
|
||||||
|
}
|
||||||
+5
@@ -0,0 +1,5 @@
|
|||||||
|
package target
|
||||||
|
|
||||||
|
fun C.foo() {
|
||||||
|
|
||||||
|
}
|
||||||
+7
@@ -0,0 +1,7 @@
|
|||||||
|
package target
|
||||||
|
|
||||||
|
class C
|
||||||
|
|
||||||
|
fun test(c: C) {
|
||||||
|
c.foo()
|
||||||
|
}
|
||||||
+5
@@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"mainFile": "source/foo.kt",
|
||||||
|
"type": "MOVE_FILES",
|
||||||
|
"targetPackage": "target"
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
package source
|
||||||
|
|
||||||
|
import target.C
|
||||||
|
|
||||||
|
fun C.foo() {
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
package target
|
||||||
|
|
||||||
|
import source.foo
|
||||||
|
|
||||||
|
class C
|
||||||
|
|
||||||
|
fun test(c: C) {
|
||||||
|
c.foo()
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
package source
|
||||||
|
|
||||||
|
fun C.foo() {
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
package source
|
||||||
|
|
||||||
|
class C
|
||||||
|
|
||||||
|
fun test(c: C) {
|
||||||
|
c.foo()
|
||||||
|
}
|
||||||
@@ -209,6 +209,12 @@ public class JetMoveTestGenerated extends AbstractJetMoveTest {
|
|||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("kotlin/changePackage/addExtensionImport/addExtensionImport.test")
|
||||||
|
public void testKotlin_changePackage_addExtensionImport_AddExtensionImport() throws Exception {
|
||||||
|
String fileName = JetTestUtils.navigationMetadata("idea/testData/refactoring/move/kotlin/changePackage/addExtensionImport/addExtensionImport.test");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("kotlin/changePackage/changeToDefaultPackage/changeToDefaultPackage.test")
|
@TestMetadata("kotlin/changePackage/changeToDefaultPackage/changeToDefaultPackage.test")
|
||||||
public void testKotlin_changePackage_changeToDefaultPackage_ChangeToDefaultPackage() throws Exception {
|
public void testKotlin_changePackage_changeToDefaultPackage_ChangeToDefaultPackage() throws Exception {
|
||||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/refactoring/move/kotlin/changePackage/changeToDefaultPackage/changeToDefaultPackage.test");
|
String fileName = JetTestUtils.navigationMetadata("idea/testData/refactoring/move/kotlin/changePackage/changeToDefaultPackage/changeToDefaultPackage.test");
|
||||||
@@ -221,6 +227,12 @@ public class JetMoveTestGenerated extends AbstractJetMoveTest {
|
|||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("kotlin/moveFile/addExtensionImport/addExtensionImport.test")
|
||||||
|
public void testKotlin_moveFile_addExtensionImport_AddExtensionImport() throws Exception {
|
||||||
|
String fileName = JetTestUtils.navigationMetadata("idea/testData/refactoring/move/kotlin/moveFile/addExtensionImport/addExtensionImport.test");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("kotlin/moveFile/internalReferences/internalReferences.test")
|
@TestMetadata("kotlin/moveFile/internalReferences/internalReferences.test")
|
||||||
public void testKotlin_moveFile_internalReferences_InternalReferences() throws Exception {
|
public void testKotlin_moveFile_internalReferences_InternalReferences() throws Exception {
|
||||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/refactoring/move/kotlin/moveFile/internalReferences/internalReferences.test");
|
String fileName = JetTestUtils.navigationMetadata("idea/testData/refactoring/move/kotlin/moveFile/internalReferences/internalReferences.test");
|
||||||
|
|||||||
Reference in New Issue
Block a user