Skip to content

Commit e4cf410

Browse files
authored
UtSummarySettings are splitted on two parts: UTSettings related and DBSCAN related (#1442)
* Split settings and move out * Fixed the loading from the file
1 parent 31a983b commit e4cf410

File tree

6 files changed

+58
-66
lines changed

6 files changed

+58
-66
lines changed

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

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -131,18 +131,43 @@ object UtSettings : AbstractSettings(logger, defaultKeyForSettingsPath, defaultS
131131
*/
132132
var testDisplayName by getBooleanProperty(true)
133133

134-
/**
135-
* Generate summaries using plugin's custom JavaDoc tags.
136-
*/
137-
var useCustomJavaDocTags by getBooleanProperty(true)
138-
139134
/**
140135
* Enable the Summarization module to generate summaries for methods under test.
141136
*
142137
* Note: if it is false, all the execution for a particular method will be stored at the same nameless region.
143138
*/
144139
var enableSummariesGeneration by getBooleanProperty(true)
145140

141+
/**
142+
* If True test comments will be generated.
143+
*/
144+
var enableJavaDocGeneration by getBooleanProperty(true)
145+
146+
/**
147+
* If True cluster comments will be generated.
148+
*/
149+
var enableClusterCommentsGeneration by getBooleanProperty(true)
150+
151+
/**
152+
* If True names for tests will be generated.
153+
*/
154+
var enableTestNamesGeneration by getBooleanProperty(true)
155+
156+
/**
157+
* If True display names for tests will be generated.
158+
*/
159+
var enableDisplayNameGeneration by getBooleanProperty(true)
160+
161+
/**
162+
* If True display name in from -> to style will be generated.
163+
*/
164+
var useDisplayNameArrowStyle by getBooleanProperty(true)
165+
166+
/**
167+
* Generate summaries using plugin's custom JavaDoc tags.
168+
*/
169+
var useCustomJavaDocTags by getBooleanProperty(true)
170+
146171
/**
147172
* This option regulates which [NullPointerException] check should be performed for nested methods.
148173
*
@@ -173,7 +198,6 @@ object UtSettings : AbstractSettings(logger, defaultKeyForSettingsPath, defaultS
173198
*/
174199
var substituteStaticsWithSymbolicVariable by getBooleanProperty(true)
175200

176-
177201
/**
178202
* Use concrete execution.
179203
*/

utbot-summary/src/main/kotlin/org/utbot/summary/UtSummarySettings.kt renamed to utbot-summary/src/main/kotlin/org/utbot/summary/DBSCANClusteringConstants.kt

Lines changed: 4 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,25 @@
11
package org.utbot.summary
22

3-
object UtSummarySettings {
4-
/**
5-
* If True test comments will be generated.
6-
*/
7-
var GENERATE_COMMENTS = true
8-
9-
/**
10-
* If True cluster comments will be generated.
11-
*/
12-
var GENERATE_CLUSTER_COMMENTS = true
13-
14-
/**
15-
* If True names for tests will be generated.
16-
*/
17-
var GENERATE_NAMES = true
18-
19-
/**
20-
* If True display names for tests will be generated.
21-
*/
22-
var GENERATE_DISPLAY_NAMES = true
23-
24-
/**
25-
* If True display name in from -> to style will be generated.
26-
*/
27-
var GENERATE_DISPLAYNAME_FROM_TO_STYLE = true
28-
29-
/**
30-
* If True mutation descriptions for tests will be generated
31-
* TODO: implement
32-
*/
33-
var GENERATE_MUTATION_DESCRIPTIONS = true
34-
3+
object DBSCANClusteringConstants {
354
/**
365
* Sets minimum number of successful execution
376
* for applying the clustering algorithm.
387
*/
39-
const val MIN_NUMBER_OF_EXECUTIONS_FOR_CLUSTERING: Int = 4
8+
internal const val MIN_NUMBER_OF_EXECUTIONS_FOR_CLUSTERING: Int = 4
409

4110
/**
4211
* DBSCAN hyperparameter.
4312
*
4413
* Sets minimum number of executions to form a cluster.
4514
*/
46-
var MIN_EXEC_DBSCAN: Int = 2
15+
internal const val MIN_EXEC_DBSCAN: Int = 2
4716

4817
/**
4918
* DBSCAN hyperparameter.
5019
*
5120
* Sets radius of search for algorithm.
5221
*/
53-
var RADIUS_DBSCAN: Float = 5.0f
22+
internal const val RADIUS_DBSCAN: Float = 5.0f
5423
}
5524

5625
object SummarySentenceConstants {

utbot-summary/src/main/kotlin/org/utbot/summary/Summarization.kt

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,6 @@ import org.utbot.framework.plugin.api.UtExecutionCluster
88
import org.utbot.framework.plugin.api.UtMethodTestSet
99
import org.utbot.instrumentation.instrumentation.instrumenter.Instrumenter
1010
import org.utbot.summary.SummarySentenceConstants.NEW_LINE
11-
import org.utbot.summary.UtSummarySettings.GENERATE_CLUSTER_COMMENTS
12-
import org.utbot.summary.UtSummarySettings.GENERATE_COMMENTS
13-
import org.utbot.summary.UtSummarySettings.GENERATE_DISPLAYNAME_FROM_TO_STYLE
14-
import org.utbot.summary.UtSummarySettings.GENERATE_DISPLAY_NAMES
15-
import org.utbot.summary.UtSummarySettings.GENERATE_NAMES
1611
import org.utbot.summary.analysis.ExecutionStructureAnalysis
1712
import org.utbot.summary.ast.JimpleToASTMap
1813
import org.utbot.summary.ast.SourceCodeParser
@@ -23,6 +18,12 @@ import java.io.File
2318
import java.nio.file.Path
2419
import java.nio.file.Paths
2520
import mu.KotlinLogging
21+
import org.utbot.framework.UtSettings.enableClusterCommentsGeneration
22+
import org.utbot.framework.UtSettings.enableJavaDocGeneration
23+
import org.utbot.framework.UtSettings.useDisplayNameArrowStyle
24+
import org.utbot.framework.UtSettings.enableDisplayNameGeneration
25+
import org.utbot.framework.UtSettings.enableTestNamesGeneration
26+
import org.utbot.framework.UtSettings.useCustomJavaDocTags
2627
import org.utbot.framework.plugin.api.util.jClass
2728
import org.utbot.fuzzer.FuzzedMethodDescription
2829
import org.utbot.fuzzer.FuzzedValue
@@ -86,7 +87,7 @@ class Summarization(val sourceFile: File?, val invokeDescriptions: List<InvokeDe
8687
executionClusters += generateSummariesForTestsProducedByFuzzer(testSet)
8788
executionClusters += generateSummariesForTestsWithEmptyPathsProducedBySymbolicExecutor(testSet)
8889

89-
return if (GENERATE_CLUSTER_COMMENTS && executionClusters.size > 0)
90+
return if (enableClusterCommentsGeneration && executionClusters.size > 0)
9091
executionClusters
9192
else
9293
listOf(UtExecutionCluster(UtClusterInfo(), testSet.executions))
@@ -110,9 +111,9 @@ class Summarization(val sourceFile: File?, val invokeDescriptions: List<InvokeDe
110111
jimpleBodyAnalysis.traceStructuralAnalysis(jimpleBody, clusteredTags, methodUnderTest, invokeDescriptions)
111112
val numberOfSuccessfulClusters = clusteredTags.filter { it.isSuccessful }.size
112113
for (clusterTraceTags in clusteredTags) {
113-
val clusterHeader = clusterTraceTags.clusterHeader.takeIf { GENERATE_CLUSTER_COMMENTS }
114+
val clusterHeader = clusterTraceTags.clusterHeader.takeIf { enableClusterCommentsGeneration }
114115
val clusterContent = if (
115-
GENERATE_CLUSTER_COMMENTS && clusterTraceTags.isSuccessful // add only for successful executions
116+
enableClusterCommentsGeneration && clusterTraceTags.isSuccessful // add only for successful executions
116117
&& numberOfSuccessfulClusters > 1 // there is more than one successful execution
117118
&& clusterTraceTags.traceTags.size > 1 // add if there is more than 1 execution
118119
) {
@@ -130,8 +131,8 @@ class Summarization(val sourceFile: File?, val invokeDescriptions: List<InvokeDe
130131
}
131132

132133
for (traceTags in clusterTraceTags.traceTags) {
133-
if (GENERATE_COMMENTS) {
134-
if (UtSettings.useCustomJavaDocTags) {
134+
if (enableJavaDocGeneration) {
135+
if (useCustomJavaDocTags) {
135136
traceTags.execution.summary =
136137
CustomJavaDocCommentBuilder(traceTags, sootToAST).buildDocStatements(methodUnderTest)
137138
} else {
@@ -140,22 +141,22 @@ class Summarization(val sourceFile: File?, val invokeDescriptions: List<InvokeDe
140141
}
141142
}
142143

143-
if (GENERATE_DISPLAY_NAMES || GENERATE_NAMES) {
144+
if (enableDisplayNameGeneration || enableTestNamesGeneration) {
144145
val simpleNameBuilder = SimpleNameBuilder(traceTags, sootToAST, methodUnderTest)
145146
val name = simpleNameBuilder.name
146147
val displayName = simpleNameBuilder.displayName
147148
val fromToName = simpleNameBuilder.fromToName
148149
val nameIndex = namesCounter.getOrPut(name) { 0 }
149150
namesCounter[name] = nameIndex + 1
150151
updatedExecutions += traceTags.execution
151-
if (GENERATE_DISPLAY_NAMES) {
152-
if (!GENERATE_DISPLAYNAME_FROM_TO_STYLE) {
152+
if (enableDisplayNameGeneration) {
153+
if (!useDisplayNameArrowStyle) {
153154
traceTags.execution.displayName = displayName
154155
} else {
155156
traceTags.execution.displayName = fromToName
156157
}
157158
}
158-
if (GENERATE_NAMES) {
159+
if (enableTestNamesGeneration) {
159160
traceTags.execution.testMethodName = name
160161
if (nameIndex != 0) traceTags.execution.testMethodName += "_$nameIndex"
161162
}

utbot-summary/src/main/kotlin/org/utbot/summary/TagGenerator.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import org.utbot.framework.plugin.api.UtTimeoutException
1616
import org.utbot.framework.plugin.api.util.humanReadableName
1717
import org.utbot.framework.plugin.api.util.isCheckedException
1818
import org.utbot.fuzzer.UtFuzzedExecution
19-
import org.utbot.summary.UtSummarySettings.MIN_NUMBER_OF_EXECUTIONS_FOR_CLUSTERING
19+
import org.utbot.summary.DBSCANClusteringConstants.MIN_NUMBER_OF_EXECUTIONS_FOR_CLUSTERING
2020
import org.utbot.summary.clustering.MatrixUniqueness
2121
import org.utbot.summary.clustering.SplitSteps
2222
import org.utbot.summary.tag.TraceTag

utbot-summary/src/main/kotlin/org/utbot/summary/clustering/MatrixUniqueness.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package org.utbot.summary.clustering
22

33
import org.utbot.framework.plugin.api.Step
44
import org.utbot.framework.plugin.api.UtSymbolicExecution
5-
import org.utbot.summary.UtSummarySettings
5+
import org.utbot.summary.DBSCANClusteringConstants
66
import org.utbot.summary.clustering.dbscan.DBSCANTrainer
77
import org.utbot.summary.clustering.dbscan.neighbor.LinearRangeQuery
88

@@ -81,8 +81,8 @@ class MatrixUniqueness(executions: List<UtSymbolicExecution>) {
8181
/** Returns map: cluster identifier, List<executions>. */
8282
fun dbscanClusterExecutions(
8383
methodExecutions: List<UtSymbolicExecution>,
84-
minPts: Int = UtSummarySettings.MIN_EXEC_DBSCAN,
85-
radius: Float = UtSummarySettings.RADIUS_DBSCAN
84+
minPts: Int = DBSCANClusteringConstants.MIN_EXEC_DBSCAN,
85+
radius: Float = DBSCANClusteringConstants.RADIUS_DBSCAN
8686
): Map<Int, List<UtSymbolicExecution>> {
8787

8888
val executionPaths = methodExecutions.map { it.path.asIterable() }.toTypedArray()

utbot-summary/src/main/kotlin/org/utbot/summary/fuzzer/names/ModelBasedNameSuggester.kt

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import org.utbot.fuzzer.FuzzedMethodDescription
77
import org.utbot.fuzzer.FuzzedValue
88
import org.utbot.summary.SummarySentenceConstants.FROM_TO_NAMES_COLON
99
import org.utbot.summary.SummarySentenceConstants.FROM_TO_NAMES_TRANSITION
10-
import org.utbot.summary.UtSummarySettings
1110
import org.utbot.summary.comment.classic.fuzzer.SimpleCommentForTestProducedByFuzzerBuilder
1211
import org.utbot.summary.comment.customtags.fuzzer.CommentWithCustomTagForTestProducedByFuzzerBuilder
1312
import java.util.*
@@ -35,9 +34,9 @@ class ModelBasedNameSuggester(
3534

3635
return sequenceOf(
3736
TestSuggestedInfo(
38-
testName = if (UtSummarySettings.GENERATE_NAMES) createTestName(description, values, result) else null,
39-
displayName = if (UtSummarySettings.GENERATE_DISPLAY_NAMES) createDisplayName(description, values, result) else null,
40-
javaDoc = if (UtSummarySettings.GENERATE_COMMENTS) createJavaDoc(description, values, result) else null
37+
testName = if (UtSettings.enableTestNamesGeneration) createTestName(description, values, result) else null,
38+
displayName = if (UtSettings.enableDisplayNameGeneration) createDisplayName(description, values, result) else null,
39+
javaDoc = if (UtSettings.enableJavaDocGeneration) createJavaDoc(description, values, result) else null
4140
)
4241
)
4342
}
@@ -108,14 +107,14 @@ class ModelBasedNameSuggester(
108107
* 2. **Name without appropriate information**: `arg_0 = 0 and others -> return 0`
109108
*
110109
* NOTE: The ```:``` symbol is used as a separator instead
111-
* of ```->``` if the [UtSummarySettings.GENERATE_DISPLAYNAME_FROM_TO_STYLE] is false.
110+
* of ```->``` if the [UtSettings.GENERATE_DISPLAYNAME_FROM_TO_STYLE] is false.
112111
*/
113112
private fun createDisplayName(
114113
description: FuzzedMethodDescription,
115114
values: List<FuzzedValue>,
116115
result: UtExecutionResult?
117116
): String {
118-
val displayNameSeparator = if (UtSummarySettings.GENERATE_DISPLAYNAME_FROM_TO_STYLE) FROM_TO_NAMES_TRANSITION else FROM_TO_NAMES_COLON
117+
val displayNameSeparator = if (UtSettings.useDisplayNameArrowStyle) FROM_TO_NAMES_TRANSITION else FROM_TO_NAMES_COLON
119118

120119
val summaries = values.asSequence()
121120
.mapIndexed { index, value ->
@@ -183,5 +182,4 @@ class ModelBasedNameSuggester(
183182
.filter { it.isUpperCase() }
184183
.joinToString(separator = "")
185184
}
186-
187185
}

0 commit comments

Comments
 (0)