Skip to content

Add JavaDoc comment style setting #774 #922

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Sep 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ object UtSettings : AbstractSettings(
/**
* Generate summaries using plugin's custom JavaDoc tags.
*/
var useCustomJavaDocTags by getBooleanProperty(false)
var useCustomJavaDocTags by getBooleanProperty(true)

/**
* Enable the machine learning module to generate summaries for methods under test.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1167,6 +1167,27 @@ enum class TreatOverflowAsError(
}
}

enum class JavaDocCommentStyle(
override val displayName: String,
override val description: String
) : CodeGenerationSettingItem {
CUSTOM_JAVADOC_TAGS(
displayName = "Structured via custom Javadoc tags",
description = "Uses custom Javadoc tags to describe test's execution path."
),
FULL_SENTENCE_WRITTEN(
displayName = "Plain text",
description = "Uses plain text to describe test's execution path."
);

override fun toString(): String = displayName

companion object : CodeGenerationSettingBox {
override val defaultItem = if (UtSettings.useCustomJavaDocTags) CUSTOM_JAVADOC_TAGS else FULL_SENTENCE_WRITTEN
override val allItems = JavaDocCommentStyle.values().toList()
}
}

enum class MockFramework(
override val displayName: String,
override val description: String = "Use $displayName as mock framework",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ abstract class UtValueTestCaseChecker(
UtSettings.useAssembleModelGenerator = true
UtSettings.saveRemainingStatesForConcreteExecution = false
UtSettings.useFuzzing = false
UtSettings.useCustomJavaDocTags = false
}

// checks paramsBefore and result
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ import java.util.concurrent.TimeUnit
import org.utbot.engine.util.mockListeners.ForceStaticMockListener
import org.utbot.framework.PathSelectorType
import org.utbot.framework.plugin.api.ExecutableId
import org.utbot.framework.plugin.api.JavaDocCommentStyle
import org.utbot.framework.plugin.api.util.executableId
import org.utbot.framework.plugin.services.WorkingDirService
import org.utbot.intellij.plugin.models.packageName
Expand Down Expand Up @@ -197,6 +198,8 @@ object UtTestsDialogProcessor {
// set timeout for concrete execution and for generated tests
UtSettings.concreteExecutionTimeoutInChildProcess = model.hangingTestsTimeout.timeoutMs

UtSettings.useCustomJavaDocTags = model.commentStyle == JavaDocCommentStyle.CUSTOM_JAVADOC_TAGS

val searchDirectory = ReadAction
.nonBlocking<Path> {
project.basePath?.let { Paths.get(it) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import com.intellij.openapi.vfs.newvfs.impl.FakeVirtualFile
import com.intellij.psi.PsiClass
import com.intellij.refactoring.util.classMembers.MemberInfo
import org.jetbrains.kotlin.idea.core.getPackage
import org.utbot.framework.plugin.api.JavaDocCommentStyle
import org.utbot.framework.util.ConflictTriggers
import org.utbot.intellij.plugin.ui.utils.jdkVersion

Expand Down Expand Up @@ -65,6 +66,7 @@ data class GenerateTestsModel(
lateinit var hangingTestsTimeout: HangingTestsTimeout
lateinit var forceStaticMocking: ForceStaticMocking
lateinit var chosenClassesToMockAlways: Set<ClassId>
lateinit var commentStyle: JavaDocCommentStyle

val conflictTriggers: ConflictTriggers = ConflictTriggers()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import org.utbot.framework.codegen.TestNg
import org.utbot.framework.plugin.api.ClassId
import org.utbot.framework.plugin.api.CodeGenerationSettingItem
import org.utbot.framework.plugin.api.CodegenLanguage
import org.utbot.framework.plugin.api.JavaDocCommentStyle
import org.utbot.framework.plugin.api.MockFramework
import org.utbot.framework.plugin.api.MockStrategyApi
import org.utbot.framework.plugin.api.TreatOverflowAsError
Expand Down Expand Up @@ -53,7 +54,8 @@ class Settings(val project: Project) : PersistentStateComponent<Settings.State>
var parametrizedTestSource: ParametrizedTestSource = ParametrizedTestSource.defaultItem,
var classesToMockAlways: Array<String> = Mocker.defaultSuperClassesToMockAlwaysNames.toTypedArray(),
var fuzzingValue: Double = 0.05,
var runGeneratedTestsWithCoverage : Boolean = false,
var runGeneratedTestsWithCoverage: Boolean = false,
var commentStyle: JavaDocCommentStyle = JavaDocCommentStyle.defaultItem
) {
constructor(model: GenerateTestsModel) : this(
codegenLanguage = model.codegenLanguage,
Expand All @@ -67,7 +69,8 @@ class Settings(val project: Project) : PersistentStateComponent<Settings.State>
parametrizedTestSource = model.parametrizedTestSource,
classesToMockAlways = model.chosenClassesToMockAlways.mapTo(mutableSetOf()) { it.name }.toTypedArray(),
fuzzingValue = model.fuzzingValue,
runGeneratedTestsWithCoverage = model.runGeneratedTestsWithCoverage
runGeneratedTestsWithCoverage = model.runGeneratedTestsWithCoverage,
commentStyle = model.commentStyle
)

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

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

val javaDocCommentStyle: JavaDocCommentStyle get() = state.commentStyle

var fuzzingValue: Double
get() = state.fuzzingValue
set(value) {
Expand Down Expand Up @@ -182,6 +187,7 @@ class Settings(val project: Project) : PersistentStateComponent<Settings.State>
state.treatOverflowAsError = provider as TreatOverflowAsError
UtSettings.treatOverflowAsError = provider == TreatOverflowAsError.AS_ERROR
}
JavaDocCommentStyle::class -> state.commentStyle = provider as JavaDocCommentStyle
// TODO: add error processing
else -> error("Unknown class [$loader] to map value [$provider]")
}
Expand All @@ -196,6 +202,7 @@ class Settings(val project: Project) : PersistentStateComponent<Settings.State>
RuntimeExceptionTestsBehaviour::class -> runtimeExceptionTestsBehaviour
ForceStaticMocking::class -> forceStaticMocking
TreatOverflowAsError::class -> treatOverflowAsError
JavaDocCommentStyle::class -> javaDocCommentStyle
// TODO: add error processing
else -> error("Unknown service loader: $loader")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import org.utbot.framework.codegen.HangingTestsTimeout
import org.utbot.framework.codegen.RuntimeExceptionTestsBehaviour
import org.utbot.framework.plugin.api.CodeGenerationSettingItem
import org.utbot.framework.plugin.api.CodegenLanguage
import org.utbot.framework.plugin.api.JavaDocCommentStyle
import org.utbot.framework.plugin.api.TreatOverflowAsError

class SettingsWindow(val project: Project) {
Expand All @@ -38,6 +39,7 @@ class SettingsWindow(val project: Project) {
CodegenLanguage::class to "Generated test language:",
RuntimeExceptionTestsBehaviour::class to "Test 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."
Expand Down Expand Up @@ -80,15 +82,15 @@ class SettingsWindow(val project: Project) {
}
}
}

mapOf(
RuntimeExceptionTestsBehaviour::class to RuntimeExceptionTestsBehaviour.values(),
TreatOverflowAsError::class to TreatOverflowAsError.values()
TreatOverflowAsError::class to TreatOverflowAsError.values(),
JavaDocCommentStyle::class to JavaDocCommentStyle.values()
).forEach { (loader, values) ->
valuesComboBox(loader, values)
}



row {
cell {
forceMockCheckBox = checkBox("Force mocking static methods")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,7 @@ class GenerateTestsDialogWindow(val model: GenerateTestsModel) : DialogWrapper(m
model.forceStaticMocking = forceStaticMocking
model.chosenClassesToMockAlways = chosenClassesToMockAlways()
model.fuzzingValue = fuzzingValue
model.commentStyle = javaDocCommentStyle
UtSettings.treatOverflowAsError = treatOverflowAsError == TreatOverflowAsError.AS_ERROR
}

Expand Down