Don't store hard references to psi elements in transferable data (KT-33802)

This leads to project leaked errors in tests.
This commit is contained in:
Nikolay Krasko
2019-09-23 18:54:18 +03:00
parent f8bd3518dc
commit 7271e65851
3 changed files with 13 additions and 6 deletions
@@ -75,7 +75,14 @@ class MoveDeclarationsCopyPasteProcessor : CopyPastePostProcessor<MoveDeclaratio
val imports = file.importDirectives.map { it.text }
return listOf(MoveDeclarationsTransferableData(file.virtualFile.url, sourceObjectFqName, declarations, imports))
return listOf(
MoveDeclarationsTransferableData(
file.virtualFile.url,
sourceObjectFqName,
declarations.map { it.text },
imports
)
)
}
override fun extractTransferableData(content: Transferable): List<MoveDeclarationsTransferableData> {
@@ -76,8 +76,9 @@ class MoveDeclarationsProcessor(
if (sourceContainer == sourcePsiFile && sourcePsiFile.packageFqName == targetPsiFile.packageFqName) return null
// check that declarations were cut (not copied)
val filteredDeclarations = sourceContainer.declarations.filter { it in data.declarations }
if (filteredDeclarations.isNotEmpty()) return null
if (sourceContainer.declarations.any { declaration -> declaration.text in data.declarationTexts }) {
return null
}
return MoveDeclarationsProcessor(
project,
@@ -85,7 +86,7 @@ class MoveDeclarationsProcessor(
targetPsiFile,
declarations,
data.imports,
data.declarations.map { it.text }
data.declarationTexts
)
}
}
@@ -18,13 +18,12 @@ package org.jetbrains.kotlin.idea.refactoring.cutPaste
import com.intellij.codeInsight.editorActions.TextBlockTransferableData
import org.jetbrains.kotlin.idea.util.IdeDescriptorRenderers
import org.jetbrains.kotlin.psi.KtNamedDeclaration
import java.awt.datatransfer.DataFlavor
class MoveDeclarationsTransferableData(
val sourceFileUrl: String,
val sourceObjectFqName: String?,
val declarations: List<KtNamedDeclaration>,
val declarationTexts: List<String>,
val imports: List<String>
) : TextBlockTransferableData {