diff --git a/ChangeLog.md b/ChangeLog.md index 94d702ed83e..11ef3ae69fa 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -234,6 +234,7 @@ These artifacts include extensions for the types available in the latter JDKs, s - [`KT-13909`](https://youtrack.jetbrains.com/issue/KT-13909) Move Files/Directories: Fix behavior of "Open moved files in editor" checkbox - [`KT-14004`](https://youtrack.jetbrains.com/issue/KT-14004) Introduce Variable: Fix exception on trying to extract variable of functional type - [`KT-13726`](https://youtrack.jetbrains.com/issue/KT-13726) Move: Fix bogus conflicts due to references resolving to wrong library version +- [`KT-14114`](https://youtrack.jetbrains.com/issue/KT-14114) Move: Fix exception on moving Kotlin file without declarations ##### New features diff --git a/idea/src/org/jetbrains/kotlin/idea/refactoring/move/moveDeclarations/MoveKotlinDeclarationsProcessor.kt b/idea/src/org/jetbrains/kotlin/idea/refactoring/move/moveDeclarations/MoveKotlinDeclarationsProcessor.kt index abb778274f3..70cfb0e46e2 100644 --- a/idea/src/org/jetbrains/kotlin/idea/refactoring/move/moveDeclarations/MoveKotlinDeclarationsProcessor.kt +++ b/idea/src/org/jetbrains/kotlin/idea/refactoring/move/moveDeclarations/MoveKotlinDeclarationsProcessor.kt @@ -130,6 +130,8 @@ class MoveKotlinDeclarationsProcessor( fun getConflictsAsUsages(): List = conflicts.entrySet().map { ConflictUsageInfo(it.key, it.value) } public override fun findUsages(): Array { + if (elementsToMove.isEmpty()) return UsageInfo.EMPTY_ARRAY + val newContainerName = descriptor.moveTarget.targetContainerFqName?.asString() ?: "" fun collectUsages(kotlinToLightElements: Map>, result: MutableList) { diff --git a/idea/testData/refactoring/move/kotlin/moveFile/moveFileWithoutDeclarations/after/p/dummy.txt b/idea/testData/refactoring/move/kotlin/moveFile/moveFileWithoutDeclarations/after/p/dummy.txt new file mode 100644 index 00000000000..e69de29bb2d diff --git a/idea/testData/refactoring/move/kotlin/moveFile/moveFileWithoutDeclarations/after/q/test.kt b/idea/testData/refactoring/move/kotlin/moveFile/moveFileWithoutDeclarations/after/q/test.kt new file mode 100644 index 00000000000..ea083c1193d --- /dev/null +++ b/idea/testData/refactoring/move/kotlin/moveFile/moveFileWithoutDeclarations/after/q/test.kt @@ -0,0 +1 @@ +package q \ No newline at end of file diff --git a/idea/testData/refactoring/move/kotlin/moveFile/moveFileWithoutDeclarations/before/p/dummy.txt b/idea/testData/refactoring/move/kotlin/moveFile/moveFileWithoutDeclarations/before/p/dummy.txt new file mode 100644 index 00000000000..e69de29bb2d diff --git a/idea/testData/refactoring/move/kotlin/moveFile/moveFileWithoutDeclarations/before/p/test.kt b/idea/testData/refactoring/move/kotlin/moveFile/moveFileWithoutDeclarations/before/p/test.kt new file mode 100644 index 00000000000..72381b051f2 --- /dev/null +++ b/idea/testData/refactoring/move/kotlin/moveFile/moveFileWithoutDeclarations/before/p/test.kt @@ -0,0 +1 @@ +package p \ No newline at end of file diff --git a/idea/testData/refactoring/move/kotlin/moveFile/moveFileWithoutDeclarations/moveFileWithoutDeclarations.test b/idea/testData/refactoring/move/kotlin/moveFile/moveFileWithoutDeclarations/moveFileWithoutDeclarations.test new file mode 100644 index 00000000000..5c8065cf2c7 --- /dev/null +++ b/idea/testData/refactoring/move/kotlin/moveFile/moveFileWithoutDeclarations/moveFileWithoutDeclarations.test @@ -0,0 +1,5 @@ +{ + "mainFile": "p/test.kt", + "type": "MOVE_FILES", + "targetPackage": "q" +} diff --git a/idea/tests/org/jetbrains/kotlin/idea/refactoring/move/MoveTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/refactoring/move/MoveTestGenerated.java index 95d17104bb5..927237ca086 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/refactoring/move/MoveTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/refactoring/move/MoveTestGenerated.java @@ -257,6 +257,12 @@ public class MoveTestGenerated extends AbstractMoveTest { doTest(fileName); } + @TestMetadata("kotlin/moveFile/moveFileWithoutDeclarations/moveFileWithoutDeclarations.test") + public void testKotlin_moveFile_moveFileWithoutDeclarations_MoveFileWithoutDeclarations() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/move/kotlin/moveFile/moveFileWithoutDeclarations/moveFileWithoutDeclarations.test"); + doTest(fileName); + } + @TestMetadata("kotlin/moveFile/moveFileWithoutPackageRename/moveFileWithoutPackageRename.test") public void testKotlin_moveFile_moveFileWithoutPackageRename_MoveFileWithoutPackageRename() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/move/kotlin/moveFile/moveFileWithoutPackageRename/moveFileWithoutPackageRename.test");