Move: Filter out ConflictUsageInfo instances before running the refactoring
#KT-16556 Fixed
This commit is contained in:
+5
-1
@@ -52,12 +52,16 @@ class MoveFilesWithDeclarationsProcessor(
|
|||||||
override fun preprocessUsages(refUsages: Ref<Array<UsageInfo>>): Boolean {
|
override fun preprocessUsages(refUsages: Ref<Array<UsageInfo>>): Boolean {
|
||||||
val usages = refUsages.get()
|
val usages = refUsages.get()
|
||||||
|
|
||||||
val distinctConflictUsages = UsageViewUtil.removeDuplicatedUsages(usages.filterIsInstance<ConflictUsageInfo>().toTypedArray())
|
val (conflictUsages, usagesToProcess) = usages.partition { it is ConflictUsageInfo }
|
||||||
|
|
||||||
|
val distinctConflictUsages = UsageViewUtil.removeDuplicatedUsages(conflictUsages.toTypedArray())
|
||||||
val conflicts = MultiMap<PsiElement, String>()
|
val conflicts = MultiMap<PsiElement, String>()
|
||||||
for (conflictUsage in distinctConflictUsages) {
|
for (conflictUsage in distinctConflictUsages) {
|
||||||
conflicts.putValues(conflictUsage.element, (conflictUsage as ConflictUsageInfo).messages)
|
conflicts.putValues(conflictUsage.element, (conflictUsage as ConflictUsageInfo).messages)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
refUsages.set(usagesToProcess.toTypedArray())
|
||||||
|
|
||||||
return showConflicts(conflicts, usages)
|
return showConflicts(conflicts, usages)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+11
@@ -0,0 +1,11 @@
|
|||||||
|
<?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" />
|
||||||
|
</component>
|
||||||
|
</module>
|
||||||
+11
@@ -0,0 +1,11 @@
|
|||||||
|
<?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" />
|
||||||
|
</component>
|
||||||
|
</module>
|
||||||
+1
@@ -0,0 +1 @@
|
|||||||
|
fdgfg
|
||||||
+7
@@ -0,0 +1,7 @@
|
|||||||
|
package b
|
||||||
|
|
||||||
|
fun foo() = listOf(1, 2, 3)
|
||||||
|
|
||||||
|
fun bar() {
|
||||||
|
|
||||||
|
}
|
||||||
+11
@@ -0,0 +1,11 @@
|
|||||||
|
<?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" />
|
||||||
|
</component>
|
||||||
|
</module>
|
||||||
+7
@@ -0,0 +1,7 @@
|
|||||||
|
package a
|
||||||
|
|
||||||
|
fun <caret>foo() = listOf(1, 2, 3)
|
||||||
|
|
||||||
|
fun bar() {
|
||||||
|
|
||||||
|
}
|
||||||
+11
@@ -0,0 +1,11 @@
|
|||||||
|
<?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" />
|
||||||
|
</component>
|
||||||
|
</module>
|
||||||
+1
@@ -0,0 +1 @@
|
|||||||
|
fdgfg
|
||||||
+1
@@ -0,0 +1 @@
|
|||||||
|
Function kotlin.collections.listOf(vararg T), referenced in function a.foo(), will not be accessible in module B
|
||||||
+8
@@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
"mainFile": "A/src/a/test.kt",
|
||||||
|
"type": "MOVE_FILES_WITH_DECLARATIONS",
|
||||||
|
"targetDirectory": "B/src/b",
|
||||||
|
"isMultiModule": "true",
|
||||||
|
"withRuntime": "true",
|
||||||
|
"modulesWithRuntime": ["A"]
|
||||||
|
}
|
||||||
@@ -21,6 +21,7 @@ import com.google.gson.JsonParser
|
|||||||
import com.intellij.codeInsight.TargetElementUtilBase
|
import com.intellij.codeInsight.TargetElementUtilBase
|
||||||
import com.intellij.openapi.editor.EditorFactory
|
import com.intellij.openapi.editor.EditorFactory
|
||||||
import com.intellij.openapi.fileEditor.FileDocumentManager
|
import com.intellij.openapi.fileEditor.FileDocumentManager
|
||||||
|
import com.intellij.openapi.module.ModuleManager
|
||||||
import com.intellij.openapi.util.io.FileUtil
|
import com.intellij.openapi.util.io.FileUtil
|
||||||
import com.intellij.openapi.vfs.VfsUtil
|
import com.intellij.openapi.vfs.VfsUtil
|
||||||
import com.intellij.openapi.vfs.VirtualFile
|
import com.intellij.openapi.vfs.VirtualFile
|
||||||
@@ -67,13 +68,18 @@ abstract class AbstractMoveTest : KotlinMultiFileTestCase() {
|
|||||||
|
|
||||||
val conflictFile = File(testDir + "/conflicts.txt")
|
val conflictFile = File(testDir + "/conflicts.txt")
|
||||||
|
|
||||||
val withRuntime = config["withRuntime"]?.asBoolean ?: false
|
|
||||||
if (withRuntime) {
|
|
||||||
ConfigLibraryUtil.configureKotlinRuntimeAndSdk(myModule, PluginTestCaseBase.mockJdk())
|
|
||||||
}
|
|
||||||
isMultiModule = config["isMultiModule"]?.asBoolean ?: false
|
isMultiModule = config["isMultiModule"]?.asBoolean ?: false
|
||||||
|
|
||||||
doTest({ rootDir, _ ->
|
doTest({ rootDir, _ ->
|
||||||
|
val withRuntime = config["withRuntime"]?.asBoolean ?: false
|
||||||
|
if (withRuntime) {
|
||||||
|
val moduleManager = ModuleManager.getInstance(project)
|
||||||
|
val modulesToConfigure =
|
||||||
|
(config["modulesWithRuntime"]?.asJsonArray?.map { moduleManager.findModuleByName(it.asString!!)!! }
|
||||||
|
?: moduleManager.modules.toList())
|
||||||
|
modulesToConfigure.forEach { ConfigLibraryUtil.configureKotlinRuntimeAndSdk(it, PluginTestCaseBase.mockJdk()) }
|
||||||
|
}
|
||||||
|
|
||||||
val mainFile = rootDir.findFileByRelativePath(mainFilePath)!!
|
val mainFile = rootDir.findFileByRelativePath(mainFilePath)!!
|
||||||
val mainPsiFile = PsiManager.getInstance(project!!).findFile(mainFile)!!
|
val mainPsiFile = PsiManager.getInstance(project!!).findFile(mainFile)!!
|
||||||
val document = FileDocumentManager.getInstance().getDocument(mainFile)!!
|
val document = FileDocumentManager.getInstance().getDocument(mainFile)!!
|
||||||
|
|||||||
@@ -504,6 +504,12 @@ public class MoveTestGenerated extends AbstractMoveTest {
|
|||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("kotlin/moveTopLevelDeclarations/misc/moveToModuleWithoutLibConflict/moveToModuleWithoutLibConflict.test")
|
||||||
|
public void testKotlin_moveTopLevelDeclarations_misc_moveToModuleWithoutLibConflict_MoveToModuleWithoutLibConflict() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/move/kotlin/moveTopLevelDeclarations/misc/moveToModuleWithoutLibConflict/moveToModuleWithoutLibConflict.test");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("kotlin/moveTopLevelDeclarations/misc/moveToUnrelatedModuleConflict/moveToUnrelatedModuleConflict.test")
|
@TestMetadata("kotlin/moveTopLevelDeclarations/misc/moveToUnrelatedModuleConflict/moveToUnrelatedModuleConflict.test")
|
||||||
public void testKotlin_moveTopLevelDeclarations_misc_moveToUnrelatedModuleConflict_MoveToUnrelatedModuleConflict() throws Exception {
|
public void testKotlin_moveTopLevelDeclarations_misc_moveToUnrelatedModuleConflict_MoveToUnrelatedModuleConflict() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/move/kotlin/moveTopLevelDeclarations/misc/moveToUnrelatedModuleConflict/moveToUnrelatedModuleConflict.test");
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/move/kotlin/moveTopLevelDeclarations/misc/moveToUnrelatedModuleConflict/moveToUnrelatedModuleConflict.test");
|
||||||
|
|||||||
Reference in New Issue
Block a user