Skip to content

Commit 051317d

Browse files
committed
Fill value of utbot.iterates tag #565
1 parent 26cb72b commit 051317d

File tree

5 files changed

+36
-20
lines changed

5 files changed

+36
-20
lines changed

utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/javadoc/UtCustomJavaDocTagProvider.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class UtCustomJavaDocTagProvider : CustomJavadocTagProvider {
4343
object MethodUnderTest : UtCustomTag("utbot.methodUnderTest", "Method under test")
4444
object ExpectedResult : UtCustomTag("utbot.expectedResult", "Expected result")
4545
object ActualResult : UtCustomTag("utbot.actualResult", "Actual result")
46-
object Executes : UtCustomTag("utbot.executes", "Executes")
46+
object Executes : UtCustomTag("utbot.executesCondition", "Executes condition")
4747
object Invokes : UtCustomTag("utbot.invokes", "Invokes")
4848
object Iterates : UtCustomTag("utbot.iterates", "Iterates")
4949
object ReturnsFrom : UtCustomTag("utbot.returnsFrom", "Returns from")

utbot-intellij/src/main/kotlin/org/utbot/intellij/plugin/javadoc/UtJavaDocInfoGenerator.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ class UtJavaDocInfoGenerator {
3232
generateUtTagSection(builder, comment, UtCustomJavaDocTagProvider.UtCustomTag.MethodUnderTest)
3333
generateUtTagSection(builder, comment, UtCustomJavaDocTagProvider.UtCustomTag.Invokes)
3434
generateUtTagSection(builder, comment, UtCustomJavaDocTagProvider.UtCustomTag.Executes)
35+
generateUtTagSection(builder, comment, UtCustomJavaDocTagProvider.UtCustomTag.Iterates)
3536
generateUtTagSection(builder, comment, UtCustomJavaDocTagProvider.UtCustomTag.ExpectedResult)
3637
generateUtTagSection(builder, comment, UtCustomJavaDocTagProvider.UtCustomTag.ActualResult)
3738
generateUtTagSection(builder, comment, UtCustomJavaDocTagProvider.UtCustomTag.ReturnsFrom)

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ data class CustomJavaDocComment(
88
val methodUnderTest: String,
99
val expectedResult: String?,
1010
val actualResult: String?,
11-
var executes: String?,
11+
var executesCondition: String?,
1212
var invokes: String?,
1313
var iterates: String?,
1414
var returnsFrom: String?,
15-
val throwsException: String?
15+
var throwsException: String?
1616
)

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

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ class CustomJavaDocCommentBuilder(
2727
docStatementList += DocRegularStmt("@utbot.expectedResult ${comment.expectedResult}\n")
2828
if (comment.actualResult != null)
2929
docStatementList += DocRegularStmt("@utbot.actualResult ${comment.actualResult}\n")
30-
if (comment.executes != null)
31-
docStatementList += DocRegularStmt("@utbot.executes ${comment.executes}\n")
30+
if (comment.executesCondition != null)
31+
docStatementList += DocRegularStmt("@utbot.executesCondition ${comment.executesCondition}\n")
3232
if (comment.invokes != null)
3333
docStatementList += DocRegularStmt("@utbot.invokes ${comment.invokes}\n")
3434
if (comment.iterates != null)
@@ -46,33 +46,47 @@ class CustomJavaDocCommentBuilder(
4646
getMethodReference(currentMethod.declaringClass.name, currentMethod.name, currentMethod.parameterTypes)
4747
val classReference = getClassReference(currentMethod.declaringClass.javaStyleName)
4848

49-
val thrownException = traceTag.result.exceptionOrNull()
50-
val exceptionThrow: String? = if (thrownException == null) {
51-
traceTag.result.exceptionOrNull()?.let { it::class.qualifiedName }
52-
} else {
53-
val exceptionName = thrownException.javaClass.simpleName
54-
val reason = findExceptionReason(currentMethod, thrownException)
55-
"{@link $exceptionName} $reason"
56-
}
57-
5849
val customJavaDocComment = CustomJavaDocComment(
5950
classUnderTest = classReference,
6051
methodUnderTest = methodReference,
6152
expectedResult = null,
6253
actualResult = null,
63-
executes = null,
54+
executesCondition = null,
6455
invokes = null,
6556
iterates = null,
6657
returnsFrom = null,
67-
throwsException = exceptionThrow
58+
throwsException = null
6859
)
6960

70-
val rootSentenceBlock = SimpleSentenceBlock(stringTemplates = stringTemplates)
61+
// build throws exception section
62+
val thrownException = traceTag.result.exceptionOrNull()
63+
val exceptionThrow: String? = if (thrownException == null) {
64+
traceTag.result.exceptionOrNull()?.let { it::class.qualifiedName }
65+
} else {
66+
val exceptionName = thrownException.javaClass.simpleName
67+
val reason = findExceptionReason(currentMethod, thrownException)
68+
"{@link $exceptionName} $reason"
69+
}
70+
customJavaDocComment.throwsException = exceptionThrow
7171

72+
val rootSentenceBlock = SimpleSentenceBlock(stringTemplates = stringTemplates)
73+
skippedIterations()
7274
buildSentenceBlock(traceTag.rootStatementTag, rootSentenceBlock, currentMethod)
7375

76+
// builds iterates section
77+
rootSentenceBlock.iterationSentenceBlocks.forEach { (loopDesc, sentenceBlocks) ->
78+
customJavaDocComment.iterates = stringTemplates.iterationSentence.format(
79+
stringTemplates.codeSentence.format(loopDesc),
80+
numberOccurrencesToText(
81+
sentenceBlocks.size
82+
)
83+
)
84+
}
85+
86+
// build invokes, executes, and returns from sections
7487
for (stmtDescription: StmtDescription in rootSentenceBlock.stmtTexts) {
7588
when (stmtDescription.stmtType.name) {
89+
//TODO: support multiple invokes (calls)
7690
"Invoke" -> {
7791
val info = stmtDescription.description
7892
customJavaDocComment.invokes = "{@code $info}"
@@ -81,9 +95,10 @@ class CustomJavaDocCommentBuilder(
8195
val info = stmtDescription.description
8296
customJavaDocComment.returnsFrom = "{@code $info}"
8397
}
98+
//TODO: support multiple conditions
8499
"Condition" -> {
85100
val info = stmtDescription.description
86-
customJavaDocComment.executes = "{@code $info}"
101+
customJavaDocComment.executesCondition = "{@code $info}"
87102
}
88103
}
89104
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,8 @@ open class SimpleCommentBuilder(
154154
if (exceptionNode == null) return ""
155155

156156
reason += when {
157-
exceptionNode is IfStmt -> exceptionNode.condition.toString()
158-
isLoopStatement(exceptionNode) -> getTextIterationDescription(exceptionNode)
157+
exceptionNode is IfStmt -> "{@code ${exceptionNode.condition}}"
158+
isLoopStatement(exceptionNode) -> "{@code ${getTextIterationDescription(exceptionNode)}"
159159
exceptionNode is SwitchStmt -> textSwitchCase(step, jimpleToASTMap)
160160
else -> exceptionNode.toString()
161161
}

0 commit comments

Comments
 (0)