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 }
|
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> {
|
override fun extractTransferableData(content: Transferable): List<MoveDeclarationsTransferableData> {
|
||||||
|
|||||||
+4
-3
@@ -76,8 +76,9 @@ class MoveDeclarationsProcessor(
|
|||||||
if (sourceContainer == sourcePsiFile && sourcePsiFile.packageFqName == targetPsiFile.packageFqName) return null
|
if (sourceContainer == sourcePsiFile && sourcePsiFile.packageFqName == targetPsiFile.packageFqName) return null
|
||||||
|
|
||||||
// check that declarations were cut (not copied)
|
// check that declarations were cut (not copied)
|
||||||
val filteredDeclarations = sourceContainer.declarations.filter { it in data.declarations }
|
if (sourceContainer.declarations.any { declaration -> declaration.text in data.declarationTexts }) {
|
||||||
if (filteredDeclarations.isNotEmpty()) return null
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
return MoveDeclarationsProcessor(
|
return MoveDeclarationsProcessor(
|
||||||
project,
|
project,
|
||||||
@@ -85,7 +86,7 @@ class MoveDeclarationsProcessor(
|
|||||||
targetPsiFile,
|
targetPsiFile,
|
||||||
declarations,
|
declarations,
|
||||||
data.imports,
|
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 com.intellij.codeInsight.editorActions.TextBlockTransferableData
|
||||||
import org.jetbrains.kotlin.idea.util.IdeDescriptorRenderers
|
import org.jetbrains.kotlin.idea.util.IdeDescriptorRenderers
|
||||||
import org.jetbrains.kotlin.psi.KtNamedDeclaration
|
|
||||||
import java.awt.datatransfer.DataFlavor
|
import java.awt.datatransfer.DataFlavor
|
||||||
|
|
||||||
class MoveDeclarationsTransferableData(
|
class MoveDeclarationsTransferableData(
|
||||||
val sourceFileUrl: String,
|
val sourceFileUrl: String,
|
||||||
val sourceObjectFqName: String?,
|
val sourceObjectFqName: String?,
|
||||||
val declarations: List<KtNamedDeclaration>,
|
val declarationTexts: List<String>,
|
||||||
val imports: List<String>
|
val imports: List<String>
|
||||||
) : TextBlockTransferableData {
|
) : TextBlockTransferableData {
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user