Skip to content

Commit 82f6a19

Browse files
authored
Add JavaDoc comment style setting #774 (#922)
* Fix after rebasing * Fix naming and make useCustomJavadocTags true * Fix broken tests
1 parent 9c6b1c9 commit 82f6a19

File tree

8 files changed

+43
-6
lines changed

8 files changed

+43
-6
lines changed

utbot-framework-api/src/main/kotlin/org/utbot/framework/UtSettings.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ object UtSettings : AbstractSettings(
155155
/**
156156
* Generate summaries using plugin's custom JavaDoc tags.
157157
*/
158-
var useCustomJavaDocTags by getBooleanProperty(false)
158+
var useCustomJavaDocTags by getBooleanProperty(true)
159159

160160
/**
161161
* Enable the machine learning module to generate summaries for methods under test.

utbot-framework-api/src/main/kotlin/org/utbot/framework/plugin/api/Api.kt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1167,6 +1167,27 @@ enum class TreatOverflowAsError(
11671167
}
11681168
}
11691169

1170+
enum class JavaDocCommentStyle(
1171+
override val displayName: String,
1172+
override val description: String
1173+
) : CodeGenerationSettingItem {
1174+
CUSTOM_JAVADOC_TAGS(
1175+
displayName = "Structured via custom Javadoc tags",
1176+
description = "Uses custom Javadoc tags to describe test's execution path."
1177+
),
1178+
FULL_SENTENCE_WRITTEN(
1179+
displayName = "Plain text",
1180+
description = "Uses plain text to describe test's execution path."
1181+
);
1182+
1183+
override fun toString(): String = displayName
1184+
1185+
companion object : CodeGenerationSettingBox {
1186+
override val defaultItem = if (UtSettings.useCustomJavaDocTags) CUSTOM_JAVADOC_TAGS else FULL_SENTENCE_WRITTEN
1187+
override val allItems = JavaDocCommentStyle.values().toList()
1188+
}
1189+
}
1190+
11701191
enum class MockFramework(
11711192
override val displayName: String,
11721193
override val description: String = "Use $displayName as mock framework",

utbot-framework/src/main/kotlin/org/utbot/tests/infrastructure/UtValueTestCaseChecker.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ abstract class UtValueTestCaseChecker(
8787
UtSettings.useAssembleModelGenerator = true
8888
UtSettings.saveRemainingStatesForConcreteExecution = false
8989
UtSettings.useFuzzing = false
90+
UtSettings.useCustomJavaDocTags = false
9091
}
9192

9293
// checks paramsBefore and result

utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/generator/UtTestsDialogProcessor.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ import java.util.concurrent.TimeUnit
5454
import org.utbot.engine.util.mockListeners.ForceStaticMockListener
5555
import org.utbot.framework.PathSelectorType
5656
import org.utbot.framework.plugin.api.ExecutableId
57+
import org.utbot.framework.plugin.api.JavaDocCommentStyle
5758
import org.utbot.framework.plugin.api.util.executableId
5859
import org.utbot.framework.plugin.services.WorkingDirService
5960
import org.utbot.intellij.plugin.models.packageName
@@ -197,6 +198,8 @@ object UtTestsDialogProcessor {
197198
// set timeout for concrete execution and for generated tests
198199
UtSettings.concreteExecutionTimeoutInChildProcess = model.hangingTestsTimeout.timeoutMs
199200

201+
UtSettings.useCustomJavaDocTags = model.commentStyle == JavaDocCommentStyle.CUSTOM_JAVADOC_TAGS
202+
200203
val searchDirectory = ReadAction
201204
.nonBlocking<Path> {
202205
project.basePath?.let { Paths.get(it) }

utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/models/GenerateTestsModel.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import com.intellij.openapi.vfs.newvfs.impl.FakeVirtualFile
1919
import com.intellij.psi.PsiClass
2020
import com.intellij.refactoring.util.classMembers.MemberInfo
2121
import org.jetbrains.kotlin.idea.core.getPackage
22+
import org.utbot.framework.plugin.api.JavaDocCommentStyle
2223
import org.utbot.framework.util.ConflictTriggers
2324
import org.utbot.intellij.plugin.ui.utils.jdkVersion
2425

@@ -65,6 +66,7 @@ data class GenerateTestsModel(
6566
lateinit var hangingTestsTimeout: HangingTestsTimeout
6667
lateinit var forceStaticMocking: ForceStaticMocking
6768
lateinit var chosenClassesToMockAlways: Set<ClassId>
69+
lateinit var commentStyle: JavaDocCommentStyle
6870

6971
val conflictTriggers: ConflictTriggers = ConflictTriggers()
7072

utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/settings/Settings.kt

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import org.utbot.framework.codegen.TestNg
2525
import org.utbot.framework.plugin.api.ClassId
2626
import org.utbot.framework.plugin.api.CodeGenerationSettingItem
2727
import org.utbot.framework.plugin.api.CodegenLanguage
28+
import org.utbot.framework.plugin.api.JavaDocCommentStyle
2829
import org.utbot.framework.plugin.api.MockFramework
2930
import org.utbot.framework.plugin.api.MockStrategyApi
3031
import org.utbot.framework.plugin.api.TreatOverflowAsError
@@ -53,7 +54,8 @@ class Settings(val project: Project) : PersistentStateComponent<Settings.State>
5354
var parametrizedTestSource: ParametrizedTestSource = ParametrizedTestSource.defaultItem,
5455
var classesToMockAlways: Array<String> = Mocker.defaultSuperClassesToMockAlwaysNames.toTypedArray(),
5556
var fuzzingValue: Double = 0.05,
56-
var runGeneratedTestsWithCoverage : Boolean = false,
57+
var runGeneratedTestsWithCoverage: Boolean = false,
58+
var commentStyle: JavaDocCommentStyle = JavaDocCommentStyle.defaultItem
5759
) {
5860
constructor(model: GenerateTestsModel) : this(
5961
codegenLanguage = model.codegenLanguage,
@@ -67,7 +69,8 @@ class Settings(val project: Project) : PersistentStateComponent<Settings.State>
6769
parametrizedTestSource = model.parametrizedTestSource,
6870
classesToMockAlways = model.chosenClassesToMockAlways.mapTo(mutableSetOf()) { it.name }.toTypedArray(),
6971
fuzzingValue = model.fuzzingValue,
70-
runGeneratedTestsWithCoverage = model.runGeneratedTestsWithCoverage
72+
runGeneratedTestsWithCoverage = model.runGeneratedTestsWithCoverage,
73+
commentStyle = model.commentStyle
7174
)
7275

7376
override fun equals(other: Any?): Boolean {
@@ -137,6 +140,8 @@ class Settings(val project: Project) : PersistentStateComponent<Settings.State>
137140

138141
val classesToMockAlways: Set<String> get() = state.classesToMockAlways.toSet()
139142

143+
val javaDocCommentStyle: JavaDocCommentStyle get() = state.commentStyle
144+
140145
var fuzzingValue: Double
141146
get() = state.fuzzingValue
142147
set(value) {
@@ -182,6 +187,7 @@ class Settings(val project: Project) : PersistentStateComponent<Settings.State>
182187
state.treatOverflowAsError = provider as TreatOverflowAsError
183188
UtSettings.treatOverflowAsError = provider == TreatOverflowAsError.AS_ERROR
184189
}
190+
JavaDocCommentStyle::class -> state.commentStyle = provider as JavaDocCommentStyle
185191
// TODO: add error processing
186192
else -> error("Unknown class [$loader] to map value [$provider]")
187193
}
@@ -196,6 +202,7 @@ class Settings(val project: Project) : PersistentStateComponent<Settings.State>
196202
RuntimeExceptionTestsBehaviour::class -> runtimeExceptionTestsBehaviour
197203
ForceStaticMocking::class -> forceStaticMocking
198204
TreatOverflowAsError::class -> treatOverflowAsError
205+
JavaDocCommentStyle::class -> javaDocCommentStyle
199206
// TODO: add error processing
200207
else -> error("Unknown service loader: $loader")
201208
}

utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/settings/SettingsWindow.kt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import org.utbot.framework.codegen.HangingTestsTimeout
2323
import org.utbot.framework.codegen.RuntimeExceptionTestsBehaviour
2424
import org.utbot.framework.plugin.api.CodeGenerationSettingItem
2525
import org.utbot.framework.plugin.api.CodegenLanguage
26+
import org.utbot.framework.plugin.api.JavaDocCommentStyle
2627
import org.utbot.framework.plugin.api.TreatOverflowAsError
2728

2829
class SettingsWindow(val project: Project) {
@@ -38,6 +39,7 @@ class SettingsWindow(val project: Project) {
3839
CodegenLanguage::class to "Generated test language:",
3940
RuntimeExceptionTestsBehaviour::class to "Test with exceptions:",
4041
TreatOverflowAsError::class to "Overflow detection:",
42+
JavaDocCommentStyle::class to "Javadoc comment style:"
4143
)
4244
val tooltipLabels = mapOf(
4345
CodegenLanguage::class to "You can generate test methods in Java or Kotlin regardless of your source code language."
@@ -80,15 +82,15 @@ class SettingsWindow(val project: Project) {
8082
}
8183
}
8284
}
85+
8386
mapOf(
8487
RuntimeExceptionTestsBehaviour::class to RuntimeExceptionTestsBehaviour.values(),
85-
TreatOverflowAsError::class to TreatOverflowAsError.values()
88+
TreatOverflowAsError::class to TreatOverflowAsError.values(),
89+
JavaDocCommentStyle::class to JavaDocCommentStyle.values()
8690
).forEach { (loader, values) ->
8791
valuesComboBox(loader, values)
8892
}
8993

90-
91-
9294
row {
9395
cell {
9496
forceMockCheckBox = checkBox("Force mocking static methods")

utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/ui/GenerateTestsDialogWindow.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -499,6 +499,7 @@ class GenerateTestsDialogWindow(val model: GenerateTestsModel) : DialogWrapper(m
499499
model.forceStaticMocking = forceStaticMocking
500500
model.chosenClassesToMockAlways = chosenClassesToMockAlways()
501501
model.fuzzingValue = fuzzingValue
502+
model.commentStyle = javaDocCommentStyle
502503
UtSettings.treatOverflowAsError = treatOverflowAsError == TreatOverflowAsError.AS_ERROR
503504
}
504505

0 commit comments

Comments
 (0)