Skip to content

Commit 58609af

Browse files
authored
Added an initial solution with comments for Fuzzing in old good plain mode (#1202)
* Added an initial solution * Added an initial solution * Renaming and refactoring * Fix imports and constants
1 parent 6ce8761 commit 58609af

15 files changed

+99
-57
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ import com.github.javaparser.ast.stmt.SwitchStmt
1111
import com.github.javaparser.ast.stmt.WhileStmt
1212
import org.utbot.framework.plugin.api.Step
1313
import org.utbot.summary.ast.JimpleToASTMap
14-
import org.utbot.summary.comment.IterationDescription
15-
import org.utbot.summary.comment.SimpleSentenceBlock
16-
import org.utbot.summary.comment.StmtDescription
17-
import org.utbot.summary.comment.StmtType
14+
import org.utbot.summary.comment.classic.symbolic.IterationDescription
15+
import org.utbot.summary.comment.classic.symbolic.SimpleSentenceBlock
16+
import org.utbot.summary.comment.classic.symbolic.StmtDescription
17+
import org.utbot.summary.comment.classic.symbolic.StmtType
1818
import org.utbot.summary.comment.getTextIterationDescription
1919
import org.utbot.summary.comment.getTextTypeIterationDescription
2020
import org.utbot.summary.comment.numberWithSuffix

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import org.utbot.summary.analysis.ExecutionStructureAnalysis
1717
import org.utbot.summary.ast.JimpleToASTMap
1818
import org.utbot.summary.ast.SourceCodeParser
1919
import org.utbot.summary.comment.cluster.SymbolicExecutionClusterCommentBuilder
20-
import org.utbot.summary.comment.SimpleCommentBuilder
20+
import org.utbot.summary.comment.classic.symbolic.SimpleCommentBuilder
2121
import org.utbot.summary.name.SimpleNameBuilder
2222
import java.io.File
2323
import java.nio.file.Path

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,7 @@ object SummarySentenceConstants {
6464
const val AT_CODE = "@code"
6565
const val OPEN_BRACKET = "{"
6666
const val CLOSE_BRACKET = "}"
67+
68+
const val JAVA_CLASS_DELIMITER = "$"
69+
const val JAVA_DOC_CLASS_DELIMITER = "."
6770
}

utbot-summary/src/main/kotlin/org/utbot/summary/comment/SentenceUtil.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ import org.utbot.summary.SummarySentenceConstants.COMMA_SYMBOL
1414
import org.utbot.summary.SummarySentenceConstants.DOT_SYMBOL
1515
import org.utbot.summary.SummarySentenceConstants.NEW_LINE
1616
import org.utbot.summary.SummarySentenceConstants.TAB
17+
import org.utbot.summary.comment.classic.symbolic.SquashedStmtTexts
18+
import org.utbot.summary.comment.classic.symbolic.StmtType
1719

1820
fun numberWithSuffix(number: Int) = when (number % 10) {
1921
1 -> "${number}st"
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,45 @@
11
package org.utbot.summary.comment.classic.fuzzer
22

33
import org.utbot.framework.plugin.api.DocPreTagStatement
4+
import org.utbot.framework.plugin.api.DocRegularStmt
45
import org.utbot.framework.plugin.api.DocStatement
56
import org.utbot.framework.plugin.api.UtExecutionResult
67
import org.utbot.fuzzer.FuzzedMethodDescription
78
import org.utbot.fuzzer.FuzzedValue
9+
import org.utbot.summary.SummarySentenceConstants.NEW_LINE
10+
import org.utbot.summary.comment.customtags.getClassReference
11+
import org.utbot.summary.comment.customtags.getMethodReferenceForFuzzingTest
812

9-
// TODO: https://github.com/UnitTestBot/UTBotJava/issues/1127
1013
class SimpleCommentForTestProducedByFuzzerBuilder(
11-
description: FuzzedMethodDescription,
12-
values: List<FuzzedValue>,
13-
result: UtExecutionResult?
14+
val methodDescription: FuzzedMethodDescription,
15+
val values: List<FuzzedValue>,
16+
val result: UtExecutionResult?
1417
) {
1518
fun buildDocStatements(): List<DocStatement> {
16-
return listOf<DocStatement>(DocPreTagStatement(emptyList()))
19+
val packageName = methodDescription.packageName
20+
val className = methodDescription.className
21+
val methodName = methodDescription.compilableName
22+
23+
val result = if (packageName != null && className != null && methodName != null) {
24+
val fullClassName = "$packageName.$className"
25+
26+
val methodReference = getMethodReferenceForFuzzingTest(
27+
fullClassName,
28+
methodName,
29+
methodDescription.parameters,
30+
false
31+
)
32+
33+
val classReference = getClassReference(fullClassName)
34+
35+
val docStatements = mutableListOf<DocStatement>()
36+
docStatements.add(DocRegularStmt("Class under test: $classReference$NEW_LINE"))
37+
docStatements.add(DocRegularStmt("Method under test: $methodReference$NEW_LINE"))
38+
docStatements
39+
} else {
40+
emptyList()
41+
}
42+
43+
return listOf<DocStatement>(DocPreTagStatement(result))
1744
}
1845
}

utbot-summary/src/main/kotlin/org/utbot/summary/comment/classic/symbolic/SimpleCommentBuilder.kt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package org.utbot.summary.comment
1+
package org.utbot.summary.comment.classic.symbolic
22

33
import com.github.javaparser.ast.body.MethodDeclaration
44
import com.github.javaparser.ast.stmt.CatchClause
@@ -16,7 +16,8 @@ import org.utbot.framework.plugin.api.exceptionOrNull
1616
import org.utbot.summary.AbstractTextBuilder
1717
import org.utbot.summary.SummarySentenceConstants.CARRIAGE_RETURN
1818
import org.utbot.summary.ast.JimpleToASTMap
19-
import org.utbot.summary.comment.customtags.getMethodReference
19+
import org.utbot.summary.comment.*
20+
import org.utbot.summary.comment.customtags.getMethodReferenceForSymbolicTest
2021
import org.utbot.summary.tag.BasicTypeTag
2122
import org.utbot.summary.tag.CallOrderTag
2223
import org.utbot.summary.tag.StatementTag
@@ -196,7 +197,7 @@ open class SimpleCommentBuilder(
196197
if (!sentenceInvoke.isEmpty()) {
197198
sentenceBlock.invokeSentenceBlock =
198199
Pair(
199-
getMethodReference(className, methodName, methodParameterTypes, invokeSootMethod.isPrivate),
200+
getMethodReferenceForSymbolicTest(className, methodName, methodParameterTypes, invokeSootMethod.isPrivate),
200201
sentenceInvoke
201202
)
202203
createNextBlock = true
@@ -333,7 +334,7 @@ open class SimpleCommentBuilder(
333334
sentenceBlock.stmtTexts.add(
334335
StmtDescription(
335336
StmtType.Invoke,
336-
getMethodReference(className, methodName, methodParameterTypes, isPrivate),
337+
getMethodReferenceForSymbolicTest(className, methodName, methodParameterTypes, isPrivate),
337338
frequency
338339
)
339340
)

utbot-summary/src/main/kotlin/org/utbot/summary/comment/classic/symbolic/SimpleSentenceBlock.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package org.utbot.summary.comment
1+
package org.utbot.summary.comment.classic.symbolic
22

33
import org.utbot.framework.plugin.api.DocCodeStmt
44
import org.utbot.framework.plugin.api.DocRegularStmt
@@ -12,6 +12,7 @@ import org.utbot.summary.SummarySentenceConstants.NEW_LINE
1212
import org.utbot.summary.SummarySentenceConstants.OPEN_BRACKET
1313
import org.utbot.summary.SummarySentenceConstants.SENTENCE_SEPARATION
1414
import org.utbot.summary.SummarySentenceConstants.TAB
15+
import org.utbot.summary.comment.*
1516

1617
class SimpleSentenceBlock(val stringTemplates: StringsTemplatesInterface) {
1718
val iterationSentenceBlocks = mutableListOf<Pair<String, List<SimpleSentenceBlock>>>()

utbot-summary/src/main/kotlin/org/utbot/summary/comment/cluster/SymbolicExecutionClusterCommentBuilder.kt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ import org.utbot.framework.plugin.api.DocStatement
77
import org.utbot.summary.SummarySentenceConstants.CARRIAGE_RETURN
88
import org.utbot.summary.ast.JimpleToASTMap
99
import org.utbot.summary.comment.*
10-
import org.utbot.summary.comment.customtags.getMethodReference
10+
import org.utbot.summary.comment.classic.symbolic.*
11+
import org.utbot.summary.comment.customtags.getMethodReferenceForSymbolicTest
1112
import org.utbot.summary.tag.BasicTypeTag
1213
import org.utbot.summary.tag.CallOrderTag
1314
import org.utbot.summary.tag.StatementTag
@@ -42,7 +43,7 @@ class SymbolicExecutionClusterCommentBuilder(
4243
sentence = splitLongSentence(sentence)
4344
sentence = lastCommaToDot(sentence)
4445

45-
return "<pre>\n$sentence</pre>".replace(CARRIAGE_RETURN, "")
46+
return "<pre>\n$sentence</pre>".replace(CARRIAGE_RETURN, EMPTY_STRING)
4647
}
4748

4849
override fun buildDocStmts(currentMethod: SootMethod): List<DocStatement> {
@@ -98,7 +99,7 @@ class SymbolicExecutionClusterCommentBuilder(
9899
if (!sentenceInvoke.isEmpty()) {
99100
sentenceBlock.invokeSentenceBlock =
100101
Pair(
101-
getMethodReference(className, methodName, methodParameterTypes, isPrivate),
102+
getMethodReferenceForSymbolicTest(className, methodName, methodParameterTypes, isPrivate),
102103
sentenceInvoke
103104
)
104105
createNextBlock = true
Lines changed: 30 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
package org.utbot.summary.comment.customtags
22

33
import org.utbot.framework.plugin.api.ClassId
4+
import org.utbot.summary.SummarySentenceConstants.CARRIAGE_RETURN
5+
import org.utbot.summary.SummarySentenceConstants.JAVA_CLASS_DELIMITER
6+
import org.utbot.summary.SummarySentenceConstants.JAVA_DOC_CLASS_DELIMITER
7+
import org.utbot.summary.comment.classic.symbolic.EMPTY_STRING
48
import soot.Type
59

610
/**
@@ -12,34 +16,15 @@ import soot.Type
1216
* In case when an enclosing class in nested, we need to replace '$' with '.'
1317
* to render the reference.
1418
*/
15-
fun getMethodReference(
19+
fun getMethodReferenceForSymbolicTest(
1620
className: String,
1721
methodName: String,
1822
methodParameterTypes: List<Type>,
1923
isPrivate: Boolean
2024
): String {
21-
val prettyClassName: String = className.replace("$", ".")
25+
val methodParametersAsString = if (methodParameterTypes.isNotEmpty()) methodParameterTypes.joinToString(",") else EMPTY_STRING
2226

23-
val text = if (methodParameterTypes.isEmpty()) {
24-
"$prettyClassName#$methodName()"
25-
} else {
26-
val methodParametersAsString = methodParameterTypes.joinToString(",")
27-
"$prettyClassName#$methodName($methodParametersAsString)"
28-
}
29-
30-
return if (isPrivate) {
31-
text
32-
} else {
33-
"{@link $text}"
34-
}
35-
}
36-
37-
/**
38-
* Returns a reference to the class.
39-
* Replaces '$' with '.' in case a class is nested.
40-
*/
41-
fun getClassReference(fullClassName: String): String {
42-
return "{@link ${fullClassName.replace("$", ".")}}"
27+
return formMethodReferenceForJavaDoc(className, methodName, methodParametersAsString, isPrivate)
4328
}
4429

4530
/**
@@ -51,12 +36,24 @@ fun getClassReference(fullClassName: String): String {
5136
* to render the reference.
5237
*/
5338
fun getMethodReferenceForFuzzingTest(className: String, methodName: String, methodParameterTypes: List<ClassId>, isPrivate: Boolean): String {
54-
val prettyClassName: String = className.replace("$", ".")
39+
val methodParametersAsString = if (methodParameterTypes.isNotEmpty()) methodParameterTypes.joinToString(",") { it.canonicalName } else EMPTY_STRING
40+
41+
return formMethodReferenceForJavaDoc(className, methodName, methodParametersAsString, isPrivate).replace(
42+
CARRIAGE_RETURN, EMPTY_STRING
43+
)
44+
}
45+
46+
private fun formMethodReferenceForJavaDoc(
47+
className: String,
48+
methodName: String,
49+
methodParametersAsString: String,
50+
isPrivate: Boolean
51+
): String {
52+
val prettyClassName: String = className.replace(JAVA_CLASS_DELIMITER, JAVA_DOC_CLASS_DELIMITER)
5553

56-
val text = if (methodParameterTypes.isEmpty()) {
54+
val text = if (methodParametersAsString == EMPTY_STRING) {
5755
"$prettyClassName#$methodName()"
5856
} else {
59-
val methodParametersAsString = methodParameterTypes.joinToString(",") { it.canonicalName }
6057
"$prettyClassName#$methodName($methodParametersAsString)"
6158
}
6259

@@ -65,4 +62,12 @@ fun getMethodReferenceForFuzzingTest(className: String, methodName: String, meth
6562
} else {
6663
"{@link $text}"
6764
}
65+
}
66+
67+
/**
68+
* Returns a reference to the class.
69+
* Replaces '$' with '.' in case a class is nested.
70+
*/
71+
fun getClassReference(fullClassName: String): String {
72+
return "{@link ${fullClassName.replace(JAVA_CLASS_DELIMITER, JAVA_DOC_CLASS_DELIMITER)}}".replace(CARRIAGE_RETURN, EMPTY_STRING)
6873
}

utbot-summary/src/main/kotlin/org/utbot/summary/comment/customtags/fuzzer/CommentWithCustomTagForTestProducedByFuzzer.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package org.utbot.summary.comment.customtags.fuzzer
22

3-
import org.utbot.summary.comment.EMPTY_STRING
3+
import org.utbot.summary.comment.classic.symbolic.EMPTY_STRING
44

55
/**
66
* Represents a set of plugin's custom JavaDoc tags.

0 commit comments

Comments
 (0)