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 2a420b0a8c..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,6 +176,9 @@ class Settings(val project: Project) : PersistentStateComponent override fun loadState(state: State) { this.state = state + if (!state.codegenLanguage.isSummarizationCompatible()) { + 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..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 @@ -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.selectedValueMatches import com.intellij.ui.layout.slider import com.intellij.ui.layout.withValueBinding import com.intellij.util.castSafelyTo @@ -29,27 +31,42 @@ 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() // 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.item.isSummarizationCompatible()) { + 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 +76,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 +143,7 @@ class SettingsWindow(val project: Project) { .onIsModified { enableSummarizationGenerationCheckBox.isSelected xor settings.state.enableSummariesGeneration } + .enableIf(codegenLanguageCombo.selectedValueMatches(CodegenLanguage?::isSummarizationCompatible)) .component } }