Move: Fix NPE on moving file to non-source directory
This commit is contained in:
+4
-1
@@ -132,7 +132,10 @@ class MoveKotlinFileHandler : MoveFileHandler() {
|
||||
val moveContext = MoveContext(file, moveProcessor)
|
||||
oldToNewMap[moveContext] = moveContext
|
||||
val packageNameInfo = file.getPackageNameInfo(moveDestination, true) ?: return
|
||||
file.packageDirective?.fqName = packageNameInfo.newContainer.fqName!!.quoteIfNeeded()
|
||||
val newFqName = packageNameInfo.newContainer.fqName
|
||||
if (newFqName != null) {
|
||||
file.packageDirective?.fqName = newFqName.quoteIfNeeded()
|
||||
}
|
||||
}
|
||||
|
||||
override fun updateMovedFile(file: PsiFile) {
|
||||
|
||||
@@ -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 test
|
||||
|
||||
fun foo() {
|
||||
|
||||
}
|
||||
@@ -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 test
|
||||
|
||||
fun foo() {
|
||||
|
||||
}
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"mainFile": "A/src/test/foo.kt",
|
||||
"type": "MOVE_FILES",
|
||||
"targetDirectory": "A/notSrc"
|
||||
}
|
||||
@@ -261,12 +261,19 @@ enum class MoveAction {
|
||||
val project = mainFile.project
|
||||
|
||||
val targetPackage = config.getNullableString("targetPackage")
|
||||
if (targetPackage != null) {
|
||||
ActionRunner.runInsideWriteAction { VfsUtil.createDirectoryIfMissing(rootDir, targetPackage.replace('.', '/')) }
|
||||
val targetDirPath = targetPackage?.replace('.', '/') ?: config.getNullableString("targetDirectory")
|
||||
if (targetDirPath != null) {
|
||||
ActionRunner.runInsideWriteAction { VfsUtil.createDirectoryIfMissing(rootDir, targetDirPath) }
|
||||
val newParent = if (targetPackage != null) {
|
||||
JavaPsiFacade.getInstance(project).findPackage(targetPackage)!!.directories[0]
|
||||
}
|
||||
else {
|
||||
rootDir.findFileByRelativePath(targetDirPath)!!.toPsiDirectory(project)!!
|
||||
}
|
||||
MoveFilesOrDirectoriesProcessor(
|
||||
project,
|
||||
arrayOf(mainFile),
|
||||
JavaPsiFacade.getInstance(project).findPackage(targetPackage)!!.directories[0],
|
||||
newParent,
|
||||
/* searchInComments = */ false,
|
||||
/* searchInNonJavaFiles = */ true,
|
||||
/* moveCallback = */ null,
|
||||
|
||||
+6
@@ -48,6 +48,12 @@ public class MultiModuleMoveTestGenerated extends AbstractMultiModuleMoveTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("moveFileToNonSrc/moveFileToNonSrc.test")
|
||||
public void testMoveFileToNonSrc_MoveFileToNonSrc() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/moveMultiModule/moveFileToNonSrc/moveFileToNonSrc.test");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("moveFileWithDeclarationsToUnrelatedModuleConflict/moveFileWithDeclarationsToUnrelatedModuleConflict.test")
|
||||
public void testMoveFileWithDeclarationsToUnrelatedModuleConflict_MoveFileWithDeclarationsToUnrelatedModuleConflict() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/moveMultiModule/moveFileWithDeclarationsToUnrelatedModuleConflict/moveFileWithDeclarationsToUnrelatedModuleConflict.test");
|
||||
|
||||
Reference in New Issue
Block a user