mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[kotlin] Move Declarations performance test: command is moved to Kotlin-specific module.
GitOrigin-RevId: 12a584727122ee3fa26684ed88ed31ee438fb00c
This commit is contained in:
committed by
intellij-monorepo-bot
parent
c3ee09dca2
commit
fb32615b2b
@@ -32,5 +32,6 @@
|
||||
<orderEntry type="module" module-name="kotlin.base.compiler-configuration" />
|
||||
<orderEntry type="module" module-name="intellij.performanceTesting.vcs" />
|
||||
<orderEntry type="module" module-name="kotlin.idea" />
|
||||
<orderEntry type="library" name="kotlinc.kotlin-compiler-common" level="project" />
|
||||
</component>
|
||||
</module>
|
||||
+3
-2
@@ -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),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
+68
@@ -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<Throwable> {
|
||||
MoveHandler.doMove(project, declarations, toFile, null, null)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun getName(): String {
|
||||
return NAME
|
||||
}
|
||||
}
|
||||
@@ -62,6 +62,5 @@
|
||||
<orderEntry type="module" module-name="intellij.platform.serviceContainer" />
|
||||
<orderEntry type="module" module-name="intellij.driver.client" />
|
||||
<orderEntry type="module" module-name="intellij.tools.ide.starter.bus" />
|
||||
<orderEntry type="library" name="kotlinc.kotlin-compiler-common" level="project" />
|
||||
</component>
|
||||
</module>
|
||||
-1
@@ -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),
|
||||
|
||||
-69
@@ -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<Throwable> {
|
||||
MoveHandler.doMove(project, declarations, toFile, null, null)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun getName(): String {
|
||||
return NAME
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user