Move: KT-8955
Fix NPE on moving directory where at least one Kotlin file contains package directive unmatched by the containing directory #KT-8955 Fixed
This commit is contained in:
+8
-2
@@ -90,7 +90,11 @@ class KotlinMoveDirectoryWithClassesHelper : MoveDirectoryWithClassesHelper() {
|
|||||||
moveContextMap[file] = MoveContext(moveDestination,
|
moveContextMap[file] = MoveContext(moveDestination,
|
||||||
fileHandler.findInternalUsages(file, moveDestination),
|
fileHandler.findInternalUsages(file, moveDestination),
|
||||||
moveDeclarationsProcessor)
|
moveDeclarationsProcessor)
|
||||||
moveDestination.getPackage()?.let { newPackage -> file.packageDirective?.fqName = FqName(newPackage.qualifiedName).quoteIfNeeded() }
|
if (moveDeclarationsProcessor != null) {
|
||||||
|
moveDestination.getPackage()?.let { newPackage ->
|
||||||
|
file.packageDirective?.fqName = FqName(newPackage.qualifiedName).quoteIfNeeded()
|
||||||
|
}
|
||||||
|
}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -109,10 +113,12 @@ class KotlinMoveDirectoryWithClassesHelper : MoveDirectoryWithClassesHelper() {
|
|||||||
val moveContext = fileToMoveContext[file] ?: return@body
|
val moveContext = fileToMoveContext[file] ?: return@body
|
||||||
|
|
||||||
MoveFilesOrDirectoriesUtil.doMoveFile(file, moveContext.newParent)
|
MoveFilesOrDirectoriesUtil.doMoveFile(file, moveContext.newParent)
|
||||||
|
|
||||||
|
val moveDeclarationsProcessor = moveContext.moveDeclarationsProcessor ?: return@body
|
||||||
val movedFile = moveContext.newParent.findFile(file.name) ?: return@body
|
val movedFile = moveContext.newParent.findFile(file.name) ?: return@body
|
||||||
|
|
||||||
usagesToProcessAfterMove +=
|
usagesToProcessAfterMove +=
|
||||||
FileUsagesWrapper(movedFile, it.usages + moveContext.internalUsages, moveContext.moveDeclarationsProcessor)
|
FileUsagesWrapper(movedFile, it.usages + moveContext.internalUsages, moveDeclarationsProcessor)
|
||||||
}
|
}
|
||||||
usagesToProcessAfterMove.forEach { fileHandler.retargetUsages(it.usages, it.moveDeclarationsProcessor!!) }
|
usagesToProcessAfterMove.forEach { fileHandler.retargetUsages(it.usages, it.moveDeclarationsProcessor!!) }
|
||||||
}
|
}
|
||||||
|
|||||||
Vendored
+12
@@ -0,0 +1,12 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<module type="JAVA_MODULE" version="4">
|
||||||
|
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||||
|
<exclude-output />
|
||||||
|
<content url="file://$MODULE_DIR$">
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||||
|
</content>
|
||||||
|
<orderEntry type="inheritedJdk" />
|
||||||
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
|
<orderEntry type="library" name="KotlinJavaRuntime" level="project" />
|
||||||
|
</component>
|
||||||
|
</module>
|
||||||
+5
@@ -0,0 +1,5 @@
|
|||||||
|
package y
|
||||||
|
|
||||||
|
fun foo() {
|
||||||
|
|
||||||
|
}
|
||||||
idea/testData/refactoring/move/kotlin/moveDirectory/moveDirectoryKeepPackageDirective/before/A/A.iml
Vendored
+12
@@ -0,0 +1,12 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<module type="JAVA_MODULE" version="4">
|
||||||
|
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||||
|
<exclude-output />
|
||||||
|
<content url="file://$MODULE_DIR$">
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||||
|
</content>
|
||||||
|
<orderEntry type="inheritedJdk" />
|
||||||
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
|
<orderEntry type="library" name="KotlinJavaRuntime" level="project" />
|
||||||
|
</component>
|
||||||
|
</module>
|
||||||
+5
@@ -0,0 +1,5 @@
|
|||||||
|
package y
|
||||||
|
|
||||||
|
fun foo() {
|
||||||
|
|
||||||
|
}
|
||||||
+7
@@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"mainFile": "A/src/x/test.kt",
|
||||||
|
"type": "MOVE_DIRECTORY_WITH_CLASSES",
|
||||||
|
"sourceDir": "A/src/x",
|
||||||
|
"targetDir": "A/src/z",
|
||||||
|
"isMultiModule": "true"
|
||||||
|
}
|
||||||
@@ -228,9 +228,15 @@ public class MoveTestGenerated extends AbstractMoveTest {
|
|||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestMetadata("kotlin/moveDirectory/moveDirectory.test")
|
@TestMetadata("kotlin/moveDirectory/moveDirectoryKeepPackageDirective/moveDirectoryKeepPackageDirective.test")
|
||||||
public void testKotlin_moveDirectory_MoveDirectory() throws Exception {
|
public void testKotlin_moveDirectory_moveDirectoryKeepPackageDirective_MoveDirectoryKeepPackageDirective() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/move/kotlin/moveDirectory/moveDirectory.test");
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/move/kotlin/moveDirectory/moveDirectoryKeepPackageDirective/moveDirectoryKeepPackageDirective.test");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("kotlin/moveDirectory/moveDirectoryWithPackageDirectiveChange/moveDirectoryWithPackageDirectiveChange.test")
|
||||||
|
public void testKotlin_moveDirectory_moveDirectoryWithPackageDirectiveChange_MoveDirectoryWithPackageDirectiveChange() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/move/kotlin/moveDirectory/moveDirectoryWithPackageDirectiveChange/moveDirectoryWithPackageDirectiveChange.test");
|
||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user