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:
+8
-1
@@ -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> {
|
||||
|
||||
+4
-3
@@ -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
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
+1
-2
@@ -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 {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user