From 8ea8f230789d268e11e6999f1c0b80a708978063 Mon Sep 17 00:00:00 2001 From: "Vassiliy.Kudryashov" Date: Wed, 2 Nov 2022 20:25:21 +0300 Subject: [PATCH 1/2] Summaries should be turned off for Kotlin related generations #1283 --- .../intellij/plugin/settings/Settings.kt | 3 ++ .../plugin/settings/SettingsWindow.kt | 28 ++++++++++++++----- 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/settings/Settings.kt b/utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/settings/Settings.kt index 2a420b0a8c..0689545329 100644 --- a/utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/settings/Settings.kt +++ b/utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/settings/Settings.kt @@ -175,6 +175,9 @@ class Settings(val project: Project) : PersistentStateComponent override fun loadState(state: State) { this.state = state + if (state.codegenLanguage != CodegenLanguage.JAVA) { + this.state.enableSummariesGeneration = false + } } fun loadStateFromModel(model: GenerateTestsModel) { diff --git a/utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/settings/SettingsWindow.kt b/utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/settings/SettingsWindow.kt index 719579e26f..c1c572bb6e 100644 --- a/utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/settings/SettingsWindow.kt +++ b/utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/settings/SettingsWindow.kt @@ -2,6 +2,7 @@ package org.utbot.intellij.plugin.settings import com.intellij.openapi.components.service import com.intellij.openapi.project.Project +import com.intellij.openapi.ui.ComboBox import com.intellij.openapi.ui.DialogPanel import com.intellij.ui.ContextHelpLabel import com.intellij.ui.components.JBLabel @@ -10,6 +11,7 @@ import com.intellij.ui.layout.LayoutBuilder import com.intellij.ui.layout.PropertyBinding import com.intellij.ui.layout.labelTable import com.intellij.ui.layout.panel +import com.intellij.ui.layout.selectedValueIs import com.intellij.ui.layout.slider import com.intellij.ui.layout.withValueBinding import com.intellij.util.castSafelyTo @@ -34,22 +36,36 @@ class SettingsWindow(val project: Project) { private val settings = project.service() // TODO it is better to use something like SearchEverywhere for classes but it is complicated to implement + private lateinit var codegenLanguageCombo: ComboBox private val excludeTable = MockAlwaysClassesTable(project) private lateinit var runInspectionAfterTestGenerationCheckBox: JCheckBox private lateinit var forceMockCheckBox: JCheckBox private lateinit var enableSummarizationGenerationCheckBox: JCheckBox val panel: JPanel = panel { + row("Generated test language:") { + cell { + codegenLanguageCombo = comboBox( + DefaultComboBoxModel(CodegenLanguage.values()), + getter = { settings.providerNameByServiceLoader(CodegenLanguage::class) as CodegenLanguage }, + setter = { settings.setProviderByLoader(CodegenLanguage::class, it as CodeGenerationSettingItem) } + ).apply { + component.renderer = CodeGenerationSettingItemRenderer() + ContextHelpLabel.create("You can generate test methods in Java or Kotlin regardless of your source code language.") + }.component + codegenLanguageCombo.addActionListener { + if (codegenLanguageCombo.selectedItem != CodegenLanguage.JAVA) { + enableSummarizationGenerationCheckBox.isSelected = false + } + } + } + } val valuesComboBox: LayoutBuilder.(KClass<*>, Array<*>) -> Unit = { loader, values -> val serviceLabels = mapOf( - CodegenLanguage::class to "Generated test language:", RuntimeExceptionTestsBehaviour::class to "Tests with exceptions:", TreatOverflowAsError::class to "Overflow detection:", JavaDocCommentStyle::class to "Javadoc comment style:" ) - val tooltipLabels = mapOf( - CodegenLanguage::class to "You can generate test methods in Java or Kotlin regardless of your source code language." - ) row(serviceLabels[loader] ?: error("Unknown service loader: $loader")) { cell { @@ -59,14 +75,11 @@ class SettingsWindow(val project: Project) { setter = { settings.setProviderByLoader(loader, it as CodeGenerationSettingItem) }, ).apply { component.renderer = CodeGenerationSettingItemRenderer() - ContextHelpLabel.create(tooltipLabels[loader] ?: return@apply)() } } } } - valuesComboBox(CodegenLanguage::class, CodegenLanguage.values()) - row("Hanging test timeout:") { cell { spinner( @@ -129,6 +142,7 @@ class SettingsWindow(val project: Project) { .onIsModified { enableSummarizationGenerationCheckBox.isSelected xor settings.state.enableSummariesGeneration } + .enableIf(codegenLanguageCombo.selectedValueIs(CodegenLanguage.JAVA)) .component } } From 670c7ce81481b66a4abca419788a152c83000bab Mon Sep 17 00:00:00 2001 From: "Vassiliy.Kudryashov" Date: Thu, 3 Nov 2022 13:09:16 +0300 Subject: [PATCH 2/2] Summaries should be turned off for Kotlin related generations #1283 Refactoring --- .../src/main/kotlin/org/utbot/framework/plugin/api/Api.kt | 2 ++ .../kotlin/org/utbot/intellij/plugin/settings/Settings.kt | 3 ++- .../org/utbot/intellij/plugin/settings/SettingsWindow.kt | 7 ++++--- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/utbot-framework-api/src/main/kotlin/org/utbot/framework/plugin/api/Api.kt b/utbot-framework-api/src/main/kotlin/org/utbot/framework/plugin/api/Api.kt index 0f2b8e2a11..a4d6b59f8d 100644 --- a/utbot-framework-api/src/main/kotlin/org/utbot/framework/plugin/api/Api.kt +++ b/utbot-framework-api/src/main/kotlin/org/utbot/framework/plugin/api/Api.kt @@ -1296,6 +1296,8 @@ enum class CodegenLanguage( override val allItems: List = values().toList() } } +//TODO #1279 +fun CodegenLanguage?.isSummarizationCompatible() = this == CodegenLanguage.JAVA // https://docs.oracle.com/javase/7/docs/technotes/tools/windows/javac.html#commandlineargfile fun isolateCommandLineArgumentsToArgumentFile(arguments: List): String { diff --git a/utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/settings/Settings.kt b/utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/settings/Settings.kt index 0689545329..f25567356c 100644 --- a/utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/settings/Settings.kt +++ b/utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/settings/Settings.kt @@ -32,6 +32,7 @@ import org.utbot.framework.plugin.api.TreatOverflowAsError import org.utbot.intellij.plugin.models.GenerateTestsModel import java.util.concurrent.CompletableFuture import kotlin.reflect.KClass +import org.utbot.framework.plugin.api.isSummarizationCompatible @State( name = "UtBotSettings", @@ -175,7 +176,7 @@ class Settings(val project: Project) : PersistentStateComponent override fun loadState(state: State) { this.state = state - if (state.codegenLanguage != CodegenLanguage.JAVA) { + if (!state.codegenLanguage.isSummarizationCompatible()) { this.state.enableSummariesGeneration = false } } diff --git a/utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/settings/SettingsWindow.kt b/utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/settings/SettingsWindow.kt index c1c572bb6e..c5f249524a 100644 --- a/utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/settings/SettingsWindow.kt +++ b/utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/settings/SettingsWindow.kt @@ -11,7 +11,7 @@ import com.intellij.ui.layout.LayoutBuilder import com.intellij.ui.layout.PropertyBinding import com.intellij.ui.layout.labelTable import com.intellij.ui.layout.panel -import com.intellij.ui.layout.selectedValueIs +import com.intellij.ui.layout.selectedValueMatches import com.intellij.ui.layout.slider import com.intellij.ui.layout.withValueBinding import com.intellij.util.castSafelyTo @@ -31,6 +31,7 @@ import org.utbot.framework.plugin.api.JavaDocCommentStyle import org.utbot.framework.plugin.api.TreatOverflowAsError import org.utbot.intellij.plugin.ui.components.CodeGenerationSettingItemRenderer import javax.swing.JSlider +import org.utbot.framework.plugin.api.isSummarizationCompatible class SettingsWindow(val project: Project) { private val settings = project.service() @@ -54,7 +55,7 @@ class SettingsWindow(val project: Project) { ContextHelpLabel.create("You can generate test methods in Java or Kotlin regardless of your source code language.") }.component codegenLanguageCombo.addActionListener { - if (codegenLanguageCombo.selectedItem != CodegenLanguage.JAVA) { + if (!codegenLanguageCombo.item.isSummarizationCompatible()) { enableSummarizationGenerationCheckBox.isSelected = false } } @@ -142,7 +143,7 @@ class SettingsWindow(val project: Project) { .onIsModified { enableSummarizationGenerationCheckBox.isSelected xor settings.state.enableSummariesGeneration } - .enableIf(codegenLanguageCombo.selectedValueIs(CodegenLanguage.JAVA)) + .enableIf(codegenLanguageCombo.selectedValueMatches(CodegenLanguage?::isSummarizationCompatible)) .component } }