Skip to content

Commit

Permalink
Summaries should be turned off for Kotlin related generations #1283 (#…
Browse files Browse the repository at this point in the history
…1298)

(cherry picked from commit 8734d59)
  • Loading branch information
Vassiliy-Kudryashov authored and denis-fokin committed Nov 7, 2022
1 parent 9bfae4d commit 23afe65
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1296,6 +1296,8 @@ enum class CodegenLanguage(
override val allItems: List<CodegenLanguage> = 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>): String {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -175,6 +176,9 @@ class Settings(val project: Project) : PersistentStateComponent<Settings.State>

override fun loadState(state: State) {
this.state = state
if (!state.codegenLanguage.isSummarizationCompatible()) {
this.state.enableSummariesGeneration = false
}
}

fun loadStateFromModel(model: GenerateTestsModel) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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<Settings>()

// TODO it is better to use something like SearchEverywhere for classes but it is complicated to implement
private lateinit var codegenLanguageCombo: ComboBox<CodegenLanguage>
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 {
Expand All @@ -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(
Expand Down Expand Up @@ -129,6 +143,7 @@ class SettingsWindow(val project: Project) {
.onIsModified {
enableSummarizationGenerationCheckBox.isSelected xor settings.state.enableSummariesGeneration
}
.enableIf(codegenLanguageCombo.selectedValueMatches(CodegenLanguage?::isSummarizationCompatible))
.component
}
}
Expand Down

0 comments on commit 23afe65

Please sign in to comment.