diff --git a/plugins/kotlin/kotlin.performanceExtendedPlugin/kotlin.performanceExtendedPlugin.iml b/plugins/kotlin/kotlin.performanceExtendedPlugin/kotlin.performanceExtendedPlugin.iml
index bfd10ee11fa5..1a27b33da6e5 100644
--- a/plugins/kotlin/kotlin.performanceExtendedPlugin/kotlin.performanceExtendedPlugin.iml
+++ b/plugins/kotlin/kotlin.performanceExtendedPlugin/kotlin.performanceExtendedPlugin.iml
@@ -32,5 +32,6 @@
+
\ No newline at end of file
diff --git a/plugins/kotlin/kotlin.performanceExtendedPlugin/src/com/intellij/performance/performancePlugin/KotlinPluginCommandProvider.kt b/plugins/kotlin/kotlin.performanceExtendedPlugin/src/com/intellij/performance/performancePlugin/KotlinPluginCommandProvider.kt
index 1bd55725069a..4b55cad17219 100644
--- a/plugins/kotlin/kotlin.performanceExtendedPlugin/src/com/intellij/performance/performancePlugin/KotlinPluginCommandProvider.kt
+++ b/plugins/kotlin/kotlin.performanceExtendedPlugin/src/com/intellij/performance/performancePlugin/KotlinPluginCommandProvider.kt
@@ -16,6 +16,7 @@ internal class KotlinPluginCommandProvider : CommandProvider {
TypingWithCompletionCommand.PREFIX to CreateCommand(::TypingWithCompletionCommand),
EnableKotlinDaemonLogCommand.PREFIX to CreateCommand(::EnableKotlinDaemonLogCommand),
AddKotlinCompilerOptionsCommand.PREFIX to CreateCommand(::AddKotlinCompilerOptionsCommand),
- ConvertJavaToKotlinCommand.PREFIX to CreateCommand(::ConvertJavaToKotlinCommand)
+ ConvertJavaToKotlinCommand.PREFIX to CreateCommand(::ConvertJavaToKotlinCommand),
+ MoveKotlinDeclarationsCommand.PREFIX to CreateCommand(::MoveKotlinDeclarationsCommand),
)
-}
\ No newline at end of file
+}
diff --git a/plugins/kotlin/kotlin.performanceExtendedPlugin/src/com/intellij/performance/performancePlugin/commands/MoveKotlinDeclarationsCommand.kt b/plugins/kotlin/kotlin.performanceExtendedPlugin/src/com/intellij/performance/performancePlugin/commands/MoveKotlinDeclarationsCommand.kt
new file mode 100644
index 000000000000..caecfc3974df
--- /dev/null
+++ b/plugins/kotlin/kotlin.performanceExtendedPlugin/src/com/intellij/performance/performancePlugin/commands/MoveKotlinDeclarationsCommand.kt
@@ -0,0 +1,68 @@
+// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
+package com.intellij.performance.performancePlugin.commands
+
+import com.jetbrains.performancePlugin.commands.OpenFileCommand
+import com.jetbrains.performancePlugin.commands.PerformanceCommandCoroutineAdapter
+
+import com.intellij.openapi.application.EDT
+import com.intellij.openapi.application.writeIntentReadAction
+import com.intellij.openapi.diagnostic.Logger
+import com.intellij.openapi.project.Project
+import com.intellij.openapi.ui.playback.PlaybackContext
+import com.intellij.openapi.vfs.VirtualFile
+import com.intellij.platform.diagnostic.telemetry.Scope
+import com.intellij.platform.diagnostic.telemetry.TelemetryManager
+import com.intellij.platform.diagnostic.telemetry.helpers.use
+import com.intellij.psi.PsiManager
+import com.intellij.refactoring.BaseRefactoringProcessor.ConflictsInTestsException.withIgnoredConflicts
+import com.intellij.refactoring.move.MoveHandler
+import com.jetbrains.performancePlugin.commands.dto.MoveDeclarationsData
+import kotlinx.coroutines.Dispatchers
+import kotlinx.coroutines.withContext
+import org.jetbrains.kotlin.psi.KtClass
+import org.jetbrains.kotlin.psi.KtNamedDeclaration
+
+/**
+ * The command moves declarations from one specified source file to another.
+ * Argument is serialized [MoveDeclarationsData] as json.
+ * NB: Different MoveHandlerDelegates are used to move declarations!
+ */
+class MoveKotlinDeclarationsCommand(text: String, line: Int) : PerformanceCommandCoroutineAdapter(text, line) {
+ companion object {
+ const val NAME = "moveDeclarations"
+ const val PREFIX = "$CMD_PREFIX$NAME"
+ val LOG = Logger.getInstance(MoveKotlinDeclarationsCommand::class.java)
+ }
+
+ private fun findFile(project: Project, path: String): VirtualFile {
+ return OpenFileCommand.findFile(path, project) ?: throw IllegalArgumentException("File not found: $path")
+ }
+
+ override suspend fun doExecute(context: PlaybackContext) {
+ val project = context.project
+ val psiManager = PsiManager.getInstance(project)
+ val moveDeclarationData = deserializeOptionsFromJson(extractCommandArgument(PREFIX), MoveDeclarationsData::class.java)
+ val tag = if (moveDeclarationData.spanTag.isNotEmpty()) "_${moveDeclarationData.spanTag}" else ""
+ withContext(Dispatchers.EDT) {
+ // Currently Refactor / Move with K2 supports only top-level declarations.
+ // We just select all top-level declarations whose names match any provided name.
+ writeIntentReadAction {
+ val file = findFile(project, moveDeclarationData.fromFile)
+ val declarations = psiManager.findFile(file)!!.children.filter {
+ it is KtNamedDeclaration && moveDeclarationData.declarations.contains(it.name)
+ }.toTypedArray()
+ LOG.info("${declarations.joinToString()}.")
+ val toFile = psiManager.findFile(findFile(project, moveDeclarationData.toFile))
+ TelemetryManager.getTracer(Scope("MoveDeclarations")).spanBuilder("$NAME$tag").use {
+ withIgnoredConflicts {
+ MoveHandler.doMove(project, declarations, toFile, null, null)
+ }
+ }
+ }
+ }
+ }
+
+ override fun getName(): String {
+ return NAME
+ }
+}
diff --git a/plugins/performanceTesting/core/intellij.performanceTesting.iml b/plugins/performanceTesting/core/intellij.performanceTesting.iml
index da70233f6996..dabb9462aaed 100644
--- a/plugins/performanceTesting/core/intellij.performanceTesting.iml
+++ b/plugins/performanceTesting/core/intellij.performanceTesting.iml
@@ -62,6 +62,5 @@
-
\ No newline at end of file
diff --git a/plugins/performanceTesting/core/src/com/jetbrains/performancePlugin/BaseCommandProvider.java b/plugins/performanceTesting/core/src/com/jetbrains/performancePlugin/BaseCommandProvider.java
index 571acd478cd6..84e1138e98ac 100644
--- a/plugins/performanceTesting/core/src/com/jetbrains/performancePlugin/BaseCommandProvider.java
+++ b/plugins/performanceTesting/core/src/com/jetbrains/performancePlugin/BaseCommandProvider.java
@@ -121,7 +121,6 @@ public final class BaseCommandProvider implements CommandProvider {
Map.entry(ExpandProjectViewCommand.PREFIX, ExpandProjectViewCommand::new),
Map.entry(DebugToggleBreakpointCommand.PREFIX, DebugToggleBreakpointCommand::new),
Map.entry(MoveFilesCommand.PREFIX, MoveFilesCommand::new),
- Map.entry(MoveKotlinDeclarationsCommand.PREFIX, MoveKotlinDeclarationsCommand::new),
Map.entry(GCCommand.PREFIX, GCCommand::new),
Map.entry(SetupInlineCompletionListenerCommand.PREFIX, SetupInlineCompletionListenerCommand::new),
Map.entry(CallInlineCompletionCommand.PREFIX, CallInlineCompletionCommand::new),
diff --git a/plugins/performanceTesting/core/src/com/jetbrains/performancePlugin/commands/MoveKotlinDeclarationsCommand.kt b/plugins/performanceTesting/core/src/com/jetbrains/performancePlugin/commands/MoveKotlinDeclarationsCommand.kt
deleted file mode 100644
index 6dd4e34a7045..000000000000
--- a/plugins/performanceTesting/core/src/com/jetbrains/performancePlugin/commands/MoveKotlinDeclarationsCommand.kt
+++ /dev/null
@@ -1,69 +0,0 @@
-package com.jetbrains.performancePlugin.commands
-
-import com.intellij.openapi.application.EDT
-import com.intellij.openapi.application.writeIntentReadAction
-import com.intellij.openapi.diagnostic.Logger
-import com.intellij.openapi.project.Project
-import com.intellij.openapi.ui.playback.PlaybackContext
-import com.intellij.openapi.vfs.VirtualFile
-import com.intellij.platform.diagnostic.telemetry.Scope
-import com.intellij.platform.diagnostic.telemetry.TelemetryManager
-import com.intellij.platform.diagnostic.telemetry.helpers.use
-import com.intellij.psi.PsiManager
-import com.intellij.refactoring.BaseRefactoringProcessor.ConflictsInTestsException.withIgnoredConflicts
-import com.intellij.refactoring.move.MoveHandler
-import com.jetbrains.performancePlugin.commands.dto.MoveDeclarationsData
-import kotlinx.coroutines.Dispatchers
-import kotlinx.coroutines.withContext
-
-// Since we move Kotlin declarations, we have to add kotlin-compiler-common library to the module classpath.
-
-/**
- * The command moves declarations from one specified source file to another.
- * Argument is serialized [MoveDeclarationsData] as json.
- * NB: Different MoveHandlerDelegates are used to move declarations!
- */
-class MoveKotlinDeclarationsCommand(text: String, line: Int) : PerformanceCommandCoroutineAdapter(text, line) {
- companion object {
- const val NAME = "moveDeclarations"
- const val PREFIX = "$CMD_PREFIX$NAME"
- val LOG = Logger.getInstance(MoveKotlinDeclarationsCommand::class.java)
- }
-
- private fun findFile(project: Project, path: String): VirtualFile {
- return OpenFileCommand.findFile(path, project) ?: throw IllegalArgumentException("File not found: $path")
- }
-
- override suspend fun doExecute(context: PlaybackContext) {
- val project = context.project
- val psiManager = PsiManager.getInstance(project)
- val moveDeclarationData = deserializeOptionsFromJson(extractCommandArgument(PREFIX), MoveDeclarationsData::class.java)
- val tag = if (moveDeclarationData.spanTag.isNotEmpty()) "_${moveDeclarationData.spanTag}" else ""
- withContext(Dispatchers.EDT) {
- // Currently Refactor / Move with K2 supports only top-level declarations.
- // We just select all top-level declarations whose names match any provided name.
- writeIntentReadAction {
- val file = findFile(project, moveDeclarationData.fromFile)
- val declarations = psiManager.findFile(file)!!.children.filter {
- // For some reason `it is KtClass` and alike returns FALSE! I suspect some effects of class loaders or so.
- if (it.javaClass.simpleName != "KtClass" && it.javaClass.simpleName != "KtNamedFunction" && it.javaClass.simpleName != "KtProperty") false
- else {
- val name = it.javaClass.methods.find { it.name == "getName" }?.invoke(it)
- moveDeclarationData.declarations.contains(name)
- }
- }.toTypedArray()
- LOG.info("${declarations.joinToString()}.")
- val toFile = psiManager.findFile(findFile(project, moveDeclarationData.toFile))
- TelemetryManager.getTracer(Scope("MoveDeclarations")).spanBuilder("$NAME$tag").use {
- withIgnoredConflicts {
- MoveHandler.doMove(project, declarations, toFile, null, null)
- }
- }
- }
- }
- }
-
- override fun getName(): String {
- return NAME
- }
-}