Move: Fix internal reference processing on moving multiple files
#KT-17211 Fixed
This commit is contained in:
+9
-6
@@ -40,12 +40,14 @@ import java.util.*
|
|||||||
class MoveKotlinFileHandler : MoveFileHandler() {
|
class MoveKotlinFileHandler : MoveFileHandler() {
|
||||||
internal class InternalUsagesWrapper(file: KtFile, val usages: List<UsageInfo>) : UsageInfo(file)
|
internal class InternalUsagesWrapper(file: KtFile, val usages: List<UsageInfo>) : UsageInfo(file)
|
||||||
|
|
||||||
|
internal class FileInfo(file: KtFile) : UsageInfo(file)
|
||||||
|
|
||||||
// This is special 'PsiElement' whose purpose is to wrap MoveKotlinTopLevelDeclarationsProcessor
|
// This is special 'PsiElement' whose purpose is to wrap MoveKotlinTopLevelDeclarationsProcessor
|
||||||
// so that it can be kept in the transition map
|
// so that it can be kept in the usage info list
|
||||||
private class MoveContext(
|
private class MoveContext(
|
||||||
psiManager: PsiManager,
|
val file: PsiFile,
|
||||||
val declarationMoveProcessor: MoveKotlinDeclarationsProcessor
|
val declarationMoveProcessor: MoveKotlinDeclarationsProcessor
|
||||||
): LightElement(psiManager, KotlinLanguage.INSTANCE) {
|
): LightElement(file.manager, KotlinLanguage.INSTANCE) {
|
||||||
override fun toString() = ""
|
override fun toString() = ""
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -117,7 +119,7 @@ class MoveKotlinFileHandler : MoveFileHandler() {
|
|||||||
): List<UsageInfo> {
|
): List<UsageInfo> {
|
||||||
if (psiFile !is KtFile) return emptyList()
|
if (psiFile !is KtFile) return emptyList()
|
||||||
|
|
||||||
val usages = ArrayList<UsageInfo>()
|
val usages = arrayListOf<UsageInfo>(FileInfo(psiFile))
|
||||||
initMoveProcessor(psiFile, newParent)?.let {
|
initMoveProcessor(psiFile, newParent)?.let {
|
||||||
usages += it.findUsages()
|
usages += it.findUsages()
|
||||||
usages += it.getConflictsAsUsages()
|
usages += it.getConflictsAsUsages()
|
||||||
@@ -127,7 +129,7 @@ class MoveKotlinFileHandler : MoveFileHandler() {
|
|||||||
|
|
||||||
override fun prepareMovedFile(file: PsiFile, moveDestination: PsiDirectory, oldToNewMap: MutableMap<PsiElement, PsiElement>) {
|
override fun prepareMovedFile(file: PsiFile, moveDestination: PsiDirectory, oldToNewMap: MutableMap<PsiElement, PsiElement>) {
|
||||||
val moveProcessor = initMoveProcessor(file, moveDestination) ?: return
|
val moveProcessor = initMoveProcessor(file, moveDestination) ?: return
|
||||||
val moveContext = MoveContext(file.manager, moveProcessor)
|
val moveContext = MoveContext(file, moveProcessor)
|
||||||
oldToNewMap[moveContext] = moveContext
|
oldToNewMap[moveContext] = moveContext
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -139,7 +141,8 @@ class MoveKotlinFileHandler : MoveFileHandler() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun retargetUsages(usageInfos: List<UsageInfo>?, oldToNewMap: Map<PsiElement, PsiElement>) {
|
override fun retargetUsages(usageInfos: List<UsageInfo>?, oldToNewMap: Map<PsiElement, PsiElement>) {
|
||||||
val moveContext = oldToNewMap.keys.firstIsInstanceOrNull<MoveContext>() ?: return
|
val currentFile = (usageInfos?.firstOrNull() as? FileInfo)?.element
|
||||||
|
val moveContext = oldToNewMap.keys.firstOrNull { it is MoveContext && it.file == currentFile} as? MoveContext ?: return
|
||||||
retargetUsages(usageInfos, moveContext.declarationMoveProcessor)
|
retargetUsages(usageInfos, moveContext.declarationMoveProcessor)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+5
@@ -0,0 +1,5 @@
|
|||||||
|
package target
|
||||||
|
|
||||||
|
interface NamedFaceO
|
||||||
|
|
||||||
|
class NamedClassO : NamedFaceO
|
||||||
+5
@@ -0,0 +1,5 @@
|
|||||||
|
package target
|
||||||
|
|
||||||
|
interface NamedFaceN
|
||||||
|
|
||||||
|
class NamedClassN : NamedFaceN
|
||||||
+5
@@ -0,0 +1,5 @@
|
|||||||
|
package source
|
||||||
|
|
||||||
|
interface NamedFaceO
|
||||||
|
|
||||||
|
class NamedClassO : NamedFaceO
|
||||||
+5
@@ -0,0 +1,5 @@
|
|||||||
|
package source
|
||||||
|
|
||||||
|
interface NamedFaceN
|
||||||
|
|
||||||
|
class NamedClassN : NamedFaceN
|
||||||
+5
@@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"filesToMove": ["source/foo.kt", "source/bar.kt"],
|
||||||
|
"type": "MOVE_FILES_WITH_DECLARATIONS",
|
||||||
|
"targetDirectory": "target"
|
||||||
|
}
|
||||||
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"mainFile": "A/src/a1/internalTarget.kt",
|
"filesToMove": ["A/src/a1/internalTarget.kt"],
|
||||||
"type": "MOVE_FILES_WITH_DECLARATIONS",
|
"type": "MOVE_FILES_WITH_DECLARATIONS",
|
||||||
"targetDirectory": "B/src/b",
|
"targetDirectory": "B/src/b",
|
||||||
"withRuntime": "true"
|
"withRuntime": "true"
|
||||||
|
|||||||
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"mainFile": "A/src/a/test.kt",
|
"filesToMove": ["A/src/a/test.kt"],
|
||||||
"type": "MOVE_FILES_WITH_DECLARATIONS",
|
"type": "MOVE_FILES_WITH_DECLARATIONS",
|
||||||
"targetDirectory": "B/src/b",
|
"targetDirectory": "B/src/b",
|
||||||
"withRuntime": "true",
|
"withRuntime": "true",
|
||||||
|
|||||||
idea/testData/refactoring/moveMultiModule/visibilityConflictInImport/visibilityConflictInImport.test
Vendored
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"mainFile": "A/src/a1/internalTarget.kt",
|
"filesToMove": ["A/src/a1/internalTarget.kt"],
|
||||||
"type": "MOVE_FILES_WITH_DECLARATIONS",
|
"type": "MOVE_FILES_WITH_DECLARATIONS",
|
||||||
"targetDirectory": "B/src/b",
|
"targetDirectory": "B/src/b",
|
||||||
"withRuntime": "true"
|
"withRuntime": "true"
|
||||||
|
|||||||
@@ -47,6 +47,7 @@ import org.jetbrains.kotlin.idea.refactoring.move.changePackage.KotlinChangePack
|
|||||||
import org.jetbrains.kotlin.idea.refactoring.move.moveDeclarations.*
|
import org.jetbrains.kotlin.idea.refactoring.move.moveDeclarations.*
|
||||||
import org.jetbrains.kotlin.idea.refactoring.rename.loadTestConfiguration
|
import org.jetbrains.kotlin.idea.refactoring.rename.loadTestConfiguration
|
||||||
import org.jetbrains.kotlin.idea.refactoring.toPsiDirectory
|
import org.jetbrains.kotlin.idea.refactoring.toPsiDirectory
|
||||||
|
import org.jetbrains.kotlin.idea.refactoring.toPsiFile
|
||||||
import org.jetbrains.kotlin.idea.search.allScope
|
import org.jetbrains.kotlin.idea.search.allScope
|
||||||
import org.jetbrains.kotlin.idea.search.projectScope
|
import org.jetbrains.kotlin.idea.search.projectScope
|
||||||
import org.jetbrains.kotlin.idea.stubindex.KotlinFullClassNameIndex
|
import org.jetbrains.kotlin.idea.stubindex.KotlinFullClassNameIndex
|
||||||
@@ -111,7 +112,7 @@ fun runMoveRefactoring(path: String, config: JsonObject, rootDir: VirtualFile, p
|
|||||||
val action = MoveAction.valueOf(config.getString("type"))
|
val action = MoveAction.valueOf(config.getString("type"))
|
||||||
|
|
||||||
val testDir = path.substring(0, path.lastIndexOf("/"))
|
val testDir = path.substring(0, path.lastIndexOf("/"))
|
||||||
val mainFilePath = config.getNullableString("mainFile")!!
|
val mainFilePath = config.getNullableString("mainFile") ?: config.getAsJsonArray("filesToMove").first().asString
|
||||||
|
|
||||||
val conflictFile = File(testDir + "/conflicts.txt")
|
val conflictFile = File(testDir + "/conflicts.txt")
|
||||||
|
|
||||||
@@ -271,14 +272,16 @@ enum class MoveAction {
|
|||||||
MOVE_FILES_WITH_DECLARATIONS {
|
MOVE_FILES_WITH_DECLARATIONS {
|
||||||
override fun runRefactoring(rootDir: VirtualFile, mainFile: PsiFile, elementAtCaret: PsiElement?, config: JsonObject) {
|
override fun runRefactoring(rootDir: VirtualFile, mainFile: PsiFile, elementAtCaret: PsiElement?, config: JsonObject) {
|
||||||
val project = mainFile.project
|
val project = mainFile.project
|
||||||
|
val psiFilesToMove = config.getAsJsonArray("filesToMove").map {
|
||||||
|
rootDir.findFileByRelativePath(it.asString)!!.toPsiFile(project) as KtFile
|
||||||
|
}
|
||||||
val targetDirPath = config.getString("targetDirectory")
|
val targetDirPath = config.getString("targetDirectory")
|
||||||
val targetDir = rootDir.findFileByRelativePath(targetDirPath)!!.toPsiDirectory(project)!!
|
val targetDir = rootDir.findFileByRelativePath(targetDirPath)!!.toPsiDirectory(project)!!
|
||||||
MoveFilesWithDeclarationsProcessor(
|
MoveFilesWithDeclarationsProcessor(
|
||||||
project,
|
project,
|
||||||
listOf(mainFile as KtFile),
|
psiFilesToMove,
|
||||||
targetDir,
|
targetDir,
|
||||||
mainFile.name,
|
psiFilesToMove.singleOrNull()?.name,
|
||||||
searchInComments = true,
|
searchInComments = true,
|
||||||
searchInNonJavaFiles = true,
|
searchInNonJavaFiles = true,
|
||||||
moveCallback = null
|
moveCallback = null
|
||||||
|
|||||||
@@ -288,6 +288,12 @@ public class MoveTestGenerated extends AbstractMoveTest {
|
|||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("kotlin/moveFile/moveMultipleFIles/moveMultipleFiles.test")
|
||||||
|
public void testKotlin_moveFile_moveMultipleFIles_MoveMultipleFiles() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/move/kotlin/moveFile/moveMultipleFIles/moveMultipleFiles.test");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("kotlin/moveFile/packageWithQuotation/moveFileToPackageWithQuotation.test")
|
@TestMetadata("kotlin/moveFile/packageWithQuotation/moveFileToPackageWithQuotation.test")
|
||||||
public void testKotlin_moveFile_packageWithQuotation_MoveFileToPackageWithQuotation() throws Exception {
|
public void testKotlin_moveFile_packageWithQuotation_MoveFileToPackageWithQuotation() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/move/kotlin/moveFile/packageWithQuotation/moveFileToPackageWithQuotation.test");
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/move/kotlin/moveFile/packageWithQuotation/moveFileToPackageWithQuotation.test");
|
||||||
|
|||||||
Reference in New Issue
Block a user