From 6f5a679a277d96bff083ee16204b109265c9396d Mon Sep 17 00:00:00 2001 From: amandelpie Date: Mon, 12 Dec 2022 19:56:49 +0300 Subject: [PATCH] Added summaries settings to the UI --- .../generator/UtTestsDialogProcessor.kt | 4 + .../plugin/models/GenerateTestsModel.kt | 4 + .../intellij/plugin/settings/Settings.kt | 26 ++++- .../plugin/settings/SettingsWindow.kt | 101 +++++++++++++++--- .../plugin/ui/GenerateTestsDialogWindow.kt | 4 + 5 files changed, 122 insertions(+), 17 deletions(-) diff --git a/utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/generator/UtTestsDialogProcessor.kt b/utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/generator/UtTestsDialogProcessor.kt index b82a895c1f..00fa9e5e6b 100644 --- a/utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/generator/UtTestsDialogProcessor.kt +++ b/utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/generator/UtTestsDialogProcessor.kt @@ -145,6 +145,10 @@ object UtTestsDialogProcessor { UtSettings.concreteExecutionTimeoutInInstrumentedProcess = model.hangingTestsTimeout.timeoutMs UtSettings.useCustomJavaDocTags = model.commentStyle == JavaDocCommentStyle.CUSTOM_JAVADOC_TAGS UtSettings.enableSummariesGeneration = model.enableSummariesGeneration + UtSettings.enableTestNamesGeneration = model.enableTestNamesGeneration + UtSettings.enableDisplayNameGeneration = model.enableDisplayNameGeneration + UtSettings.enableJavaDocGeneration = model.enableJavaDocGeneration + UtSettings.enableClusterCommentsGeneration = model.enableClusterCommentsGeneration fun now() = LocalDateTime.now().format(DateTimeFormatter.ofPattern("HH:mm:ss.SSS")) diff --git a/utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/models/GenerateTestsModel.kt b/utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/models/GenerateTestsModel.kt index 66097c7a90..b833af2346 100644 --- a/utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/models/GenerateTestsModel.kt +++ b/utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/models/GenerateTestsModel.kt @@ -56,6 +56,10 @@ class GenerateTestsModel( var runGeneratedTestsWithCoverage : Boolean = false var enableSummariesGeneration : Boolean = UtSettings.enableSummariesGeneration + var enableTestNamesGeneration : Boolean = UtSettings.enableTestNamesGeneration + var enableDisplayNameGeneration : Boolean = UtSettings.enableDisplayNameGeneration + var enableJavaDocGeneration : Boolean = UtSettings.enableJavaDocGeneration + var enableClusterCommentsGeneration : Boolean = UtSettings.enableClusterCommentsGeneration } val PsiClass.packageName: 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 8c905738ee..f452c3fdfc 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 @@ -62,7 +62,11 @@ class Settings(val project: Project) : PersistentStateComponent var fuzzingValue: Double = 0.05, var runGeneratedTestsWithCoverage: Boolean = false, var commentStyle: JavaDocCommentStyle = JavaDocCommentStyle.defaultItem, - var enableSummariesGeneration: Boolean = UtSettings.enableSummariesGeneration + var enableSummariesGeneration: Boolean = UtSettings.enableSummariesGeneration, + var enableTestNamesGeneration: Boolean = UtSettings.enableTestNamesGeneration, + var enableDisplayNameGeneration: Boolean = UtSettings.enableDisplayNameGeneration, + var enableJavaDocGeneration: Boolean = UtSettings.enableJavaDocGeneration, + var enableClusterCommentsGeneration: Boolean = UtSettings.enableClusterCommentsGeneration ) { constructor(model: GenerateTestsModel) : this( codegenLanguage = model.codegenLanguage, @@ -79,7 +83,11 @@ class Settings(val project: Project) : PersistentStateComponent fuzzingValue = model.fuzzingValue, runGeneratedTestsWithCoverage = model.runGeneratedTestsWithCoverage, commentStyle = model.commentStyle, - enableSummariesGeneration = model.enableSummariesGeneration + enableSummariesGeneration = model.enableSummariesGeneration, + enableTestNamesGeneration = model.enableTestNamesGeneration, + enableDisplayNameGeneration = model.enableDisplayNameGeneration, + enableJavaDocGeneration = model.enableJavaDocGeneration, + enableClusterCommentsGeneration = model.enableClusterCommentsGeneration ) override fun equals(other: Any?): Boolean { @@ -104,6 +112,10 @@ class Settings(val project: Project) : PersistentStateComponent if (runGeneratedTestsWithCoverage != other.runGeneratedTestsWithCoverage) return false if (commentStyle != other.commentStyle) return false if (enableSummariesGeneration != other.enableSummariesGeneration) return false + if (enableTestNamesGeneration != other.enableTestNamesGeneration) return false + if (enableDisplayNameGeneration != other.enableDisplayNameGeneration) return false + if (enableJavaDocGeneration != other.enableJavaDocGeneration) return false + if (enableClusterCommentsGeneration != other.enableClusterCommentsGeneration) return false return true } @@ -123,6 +135,10 @@ class Settings(val project: Project) : PersistentStateComponent result = 31 * result + fuzzingValue.hashCode() result = 31 * result + if (runGeneratedTestsWithCoverage) 1 else 0 result = 31 * result + if (enableSummariesGeneration) 1 else 0 + result = 31 * result + if (enableTestNamesGeneration) 1 else 0 + result = 31 * result + if (enableDisplayNameGeneration) 1 else 0 + result = 31 * result + if (enableJavaDocGeneration) 1 else 0 + result = 31 * result + if (enableClusterCommentsGeneration) 1 else 0 return result } @@ -165,8 +181,6 @@ class Settings(val project: Project) : PersistentStateComponent } var runGeneratedTestsWithCoverage = state.runGeneratedTestsWithCoverage - var enableSummariesGeneration = state.enableSummariesGeneration - fun setClassesToMockAlways(classesToMockAlways: List) { state.classesToMockAlways = classesToMockAlways.distinct().toTypedArray() } @@ -202,6 +216,10 @@ class Settings(val project: Project) : PersistentStateComponent this.state = state if (!state.codegenLanguage.isSummarizationCompatible()) { this.state.enableSummariesGeneration = false + this.state.enableTestNamesGeneration = false + this.state.enableDisplayNameGeneration = false + this.state.enableJavaDocGeneration = false + this.state.enableClusterCommentsGeneration = 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 8ad2cfeba3..13b97844c6 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 @@ -44,6 +44,10 @@ class SettingsWindow(val project: Project) { private lateinit var runInspectionAfterTestGenerationCheckBox: JCheckBox private lateinit var forceMockCheckBox: JCheckBox private lateinit var enableSummarizationGenerationCheckBox: JCheckBox + private lateinit var enableTestNamesGenerationCheckBox: JCheckBox + private lateinit var enableDisplayNameGenerationCheckBox: JCheckBox + private lateinit var enableJavaDocGenerationCheckBox: JCheckBox + private lateinit var enableClusterCommentsGenerationCheckBox: JCheckBox val panel: JPanel = panel { row("Generated test language:") { @@ -59,6 +63,10 @@ class SettingsWindow(val project: Project) { codegenLanguageCombo.addActionListener { if (!codegenLanguageCombo.item.isSummarizationCompatible()) { enableSummarizationGenerationCheckBox.isSelected = false + enableTestNamesGenerationCheckBox.isSelected = false + enableJavaDocGenerationCheckBox.isSelected = false + enableDisplayNameGenerationCheckBox.isSelected = false + enableClusterCommentsGenerationCheckBox.isSelected = false } } } @@ -110,46 +118,115 @@ class SettingsWindow(val project: Project) { mapOf( RuntimeExceptionTestsBehaviour::class to RuntimeExceptionTestsBehaviour.values(), - TreatOverflowAsError::class to TreatOverflowAsError.values(), - JavaDocCommentStyle::class to JavaDocCommentStyle.values() + TreatOverflowAsError::class to TreatOverflowAsError.values() ).forEach { (loader, values) -> valuesComboBox(loader, values) } row { cell { - runInspectionAfterTestGenerationCheckBox = checkBox("Display detected errors on the Problems tool window") + enableSummarizationGenerationCheckBox = checkBox("Enable Summaries Generation") .onApply { - settings.state.runInspectionAfterTestGeneration = runInspectionAfterTestGenerationCheckBox.isSelected + settings.state.enableSummariesGeneration = enableSummarizationGenerationCheckBox.isSelected } .onReset { - runInspectionAfterTestGenerationCheckBox.isSelected = settings.state.runInspectionAfterTestGeneration + enableSummarizationGenerationCheckBox.isSelected = settings.state.enableSummariesGeneration } .onIsModified { - runInspectionAfterTestGenerationCheckBox.isSelected xor settings.state.runInspectionAfterTestGeneration + enableSummarizationGenerationCheckBox.isSelected xor settings.state.enableSummariesGeneration } - // .apply { ContextHelpLabel.create("Automatically run code inspection after test generation")() } + .enableIf(codegenLanguageCombo.selectedValueMatches(CodegenLanguage?::isSummarizationCompatible)) .component } } row { cell { - enableSummarizationGenerationCheckBox = checkBox("Enable Summaries Generation") + enableTestNamesGenerationCheckBox = checkBox("Enable Test Names Generation") .onApply { - settings.state.enableSummariesGeneration = enableSummarizationGenerationCheckBox.isSelected + settings.state.enableTestNamesGeneration = enableTestNamesGenerationCheckBox.isSelected } .onReset { - enableSummarizationGenerationCheckBox.isSelected = settings.state.enableSummariesGeneration + enableTestNamesGenerationCheckBox.isSelected = settings.state.enableTestNamesGeneration } .onIsModified { - enableSummarizationGenerationCheckBox.isSelected xor settings.state.enableSummariesGeneration + enableTestNamesGenerationCheckBox.isSelected xor settings.state.enableTestNamesGeneration } .enableIf(codegenLanguageCombo.selectedValueMatches(CodegenLanguage?::isSummarizationCompatible)) .component } } + row { + cell { + enableDisplayNameGenerationCheckBox = checkBox("Enable Display Names Generation") + .onApply { + settings.state.enableDisplayNameGeneration = enableDisplayNameGenerationCheckBox.isSelected + } + .onReset { + enableDisplayNameGenerationCheckBox.isSelected = settings.state.enableDisplayNameGeneration + } + .onIsModified { + enableDisplayNameGenerationCheckBox.isSelected xor settings.state.enableDisplayNameGeneration + } + .enableIf(codegenLanguageCombo.selectedValueMatches(CodegenLanguage?::isSummarizationCompatible)) + .component + } + } + + row { + cell { + enableJavaDocGenerationCheckBox = checkBox("Enable Javadoc Generation") + .onApply { + settings.state.enableJavaDocGeneration = enableJavaDocGenerationCheckBox.isSelected + } + .onReset { + enableJavaDocGenerationCheckBox.isSelected = settings.state.enableJavaDocGeneration + } + .onIsModified { + enableJavaDocGenerationCheckBox.isSelected xor settings.state.enableJavaDocGeneration + } + .enableIf(codegenLanguageCombo.selectedValueMatches(CodegenLanguage?::isSummarizationCompatible)) + .component + } + } + + row { + cell { + enableClusterCommentsGenerationCheckBox = checkBox("Enable Cluster Comments Generation") + .onApply { + settings.state.enableClusterCommentsGeneration = enableClusterCommentsGenerationCheckBox.isSelected + } + .onReset { + enableClusterCommentsGenerationCheckBox.isSelected = settings.state.enableClusterCommentsGeneration + } + .onIsModified { + enableClusterCommentsGenerationCheckBox.isSelected xor settings.state.enableClusterCommentsGeneration + } + .enableIf(codegenLanguageCombo.selectedValueMatches(CodegenLanguage?::isSummarizationCompatible)) + .component + } + } + + valuesComboBox(JavaDocCommentStyle::class, JavaDocCommentStyle.values()) + + row { + cell { + runInspectionAfterTestGenerationCheckBox = checkBox("Display detected errors on the Problems tool window") + .onApply { + settings.state.runInspectionAfterTestGeneration = runInspectionAfterTestGenerationCheckBox.isSelected + } + .onReset { + runInspectionAfterTestGenerationCheckBox.isSelected = settings.state.runInspectionAfterTestGeneration + } + .onIsModified { + runInspectionAfterTestGenerationCheckBox.isSelected xor settings.state.runInspectionAfterTestGeneration + } + // .apply { ContextHelpLabel.create("Automatically run code inspection after test generation")() } + .component + } + } + row { cell { forceMockCheckBox = checkBox("Force mocking static methods") @@ -178,8 +255,6 @@ class SettingsWindow(val project: Project) { } .onIsModified { excludeTable.isModified() } forceMockCheckBox.addActionListener { updater.run() } - - } val fuzzLabel = JBLabel("Fuzzing") diff --git a/utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/ui/GenerateTestsDialogWindow.kt b/utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/ui/GenerateTestsDialogWindow.kt index cf681a3b42..67860891a0 100644 --- a/utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/ui/GenerateTestsDialogWindow.kt +++ b/utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/ui/GenerateTestsDialogWindow.kt @@ -530,6 +530,10 @@ class GenerateTestsDialogWindow(val model: GenerateTestsModel) : DialogWrapper(m model.fuzzingValue = fuzzingValue model.commentStyle = javaDocCommentStyle model.enableSummariesGeneration = state.enableSummariesGeneration + model.enableTestNamesGeneration = state.enableTestNamesGeneration + model.enableDisplayNameGeneration = state.enableDisplayNameGeneration + model.enableJavaDocGeneration = state.enableJavaDocGeneration + model.enableClusterCommentsGeneration = state.enableClusterCommentsGeneration UtSettings.treatOverflowAsError = treatOverflowAsError == TreatOverflowAsError.AS_ERROR }