@@ -23,42 +23,51 @@ class CustomJavaDocCommentBuilder(
23
23
24
24
docStatementList + = DocRegularStmt (" @utbot.classUnderTest ${comment.classUnderTest} \n " )
25
25
docStatementList + = DocRegularStmt (" @utbot.methodUnderTest ${comment.methodUnderTest} \n " )
26
- if (comment.expectedResult != null )
26
+
27
+ if (comment.expectedResult.isNotEmpty())
27
28
docStatementList + = DocRegularStmt (" @utbot.expectedResult ${comment.expectedResult} \n " )
28
- if (comment.actualResult != null )
29
+ if (comment.actualResult.isNotEmpty() )
29
30
docStatementList + = DocRegularStmt (" @utbot.actualResult ${comment.actualResult} \n " )
30
- if (comment.executesCondition != null )
31
- docStatementList + = DocRegularStmt (" @utbot.executesCondition ${comment.executesCondition} \n " )
32
- if (comment.invokes != null )
33
- docStatementList + = DocRegularStmt (" @utbot.invokes ${comment.invokes} \n " )
34
- if (comment.iterates != null )
35
- docStatementList + = DocRegularStmt (" @utbot.iterates ${comment.iterates} \n " )
36
- if (comment.returnsFrom != null )
31
+ if (comment.executesCondition.isNotEmpty()) {
32
+ val statement =
33
+ " @utbot.executesCondition ${comment.executesCondition.joinToString(separator = " ,\n " )} \n "
34
+ docStatementList + = DocRegularStmt (statement)
35
+ }
36
+ if (comment.invokes.isNotEmpty()) {
37
+ val statement = " @utbot.invokes ${comment.invokes.joinToString(separator = " ,\n " )} \n "
38
+ docStatementList + = DocRegularStmt (statement)
39
+ }
40
+ if (comment.iterates.isNotEmpty()) {
41
+ val statement = " @utbot.iterates ${comment.iterates.joinToString(separator = " ,\n " )} \n "
42
+ docStatementList + = DocRegularStmt (statement)
43
+ }
44
+ if (comment.returnsFrom.isNotEmpty())
37
45
docStatementList + = DocRegularStmt (" @utbot.returnsFrom ${comment.returnsFrom} \n " )
38
- if (comment.throwsException != null )
46
+ if (comment.throwsException.isNotEmpty() )
39
47
docStatementList + = DocRegularStmt (" @utbot.throwsException ${comment.throwsException} " )
40
48
41
49
return listOf<DocStatement >(DocPreTagStatement (docStatementList))
42
50
}
43
51
44
52
private fun buildCustomJavaDocComment (currentMethod : SootMethod ): CustomJavaDocComment {
45
- val methodReference =
46
- getMethodReference(currentMethod.declaringClass.name, currentMethod.name, currentMethod.parameterTypes)
53
+ val methodReference = getMethodReference(
54
+ currentMethod.declaringClass.name,
55
+ currentMethod.name,
56
+ currentMethod.parameterTypes
57
+ )
47
58
val classReference = getClassReference(currentMethod.declaringClass.javaStyleName)
48
59
49
60
val customJavaDocComment = CustomJavaDocComment (
50
61
classUnderTest = classReference,
51
62
methodUnderTest = methodReference,
52
- expectedResult = null ,
53
- actualResult = null ,
54
- executesCondition = null ,
55
- invokes = null ,
56
- iterates = null ,
57
- returnsFrom = null ,
58
- throwsException = null
59
63
)
60
64
61
- // build throws exception section
65
+ val rootSentenceBlock = SimpleSentenceBlock (stringTemplates = stringTemplates)
66
+ skippedIterations()
67
+ buildSentenceBlock(traceTag.rootStatementTag, rootSentenceBlock, currentMethod)
68
+ rootSentenceBlock.squashStmtText()
69
+
70
+ // builds Throws exception section
62
71
val thrownException = traceTag.result.exceptionOrNull()
63
72
val exceptionThrow: String? = if (thrownException == null ) {
64
73
traceTag.result.exceptionOrNull()?.let { it::class .qualifiedName }
@@ -67,40 +76,43 @@ class CustomJavaDocCommentBuilder(
67
76
val reason = findExceptionReason(currentMethod, thrownException)
68
77
" {@link $exceptionName } $reason "
69
78
}
70
- customJavaDocComment.throwsException = exceptionThrow
71
-
72
- val rootSentenceBlock = SimpleSentenceBlock (stringTemplates = stringTemplates)
73
- skippedIterations()
74
- buildSentenceBlock(traceTag.rootStatementTag, rootSentenceBlock, currentMethod)
79
+ if (exceptionThrow != null ) {
80
+ customJavaDocComment.throwsException = exceptionThrow
81
+ }
75
82
76
- // builds iterates section
83
+ // builds Iterates section
77
84
rootSentenceBlock.iterationSentenceBlocks.forEach { (loopDesc, sentenceBlocks) ->
78
- customJavaDocComment.iterates = stringTemplates.iterationSentence.format(
85
+ customJavaDocComment.iterates + = stringTemplates.iterationSentence.format(
79
86
stringTemplates.codeSentence.format(loopDesc),
80
87
numberOccurrencesToText(
81
88
sentenceBlocks.size
82
89
)
83
90
)
84
91
}
85
92
86
- // build invokes, executes, and returns from sections
87
- for (stmtDescription: StmtDescription in rootSentenceBlock.stmtTexts) {
88
- when (stmtDescription.stmtType.name) {
89
- // TODO: support multiple invokes (calls)
90
- " Invoke" -> {
91
- val info = stmtDescription.description
92
- customJavaDocComment.invokes = " {@code $info }"
93
- }
94
- " Return" -> {
95
- val info = stmtDescription.description
96
- customJavaDocComment.returnsFrom = " {@code $info }"
97
- }
98
- // TODO: support multiple conditions
99
- " Condition" -> {
100
- val info = stmtDescription.description
101
- customJavaDocComment.executesCondition = " {@code $info }"
93
+ // builds Invoke, Execute, Return sections
94
+ var currentBlock: SimpleSentenceBlock ? = rootSentenceBlock
95
+ while (currentBlock != null ) {
96
+ for (statement in currentBlock.stmtTexts) {
97
+ when (statement.stmtType) {
98
+ StmtType .Invoke -> {
99
+ val info = statement.description
100
+ customJavaDocComment.invokes + = " {@code $info }"
101
+ }
102
+ StmtType .Condition -> {
103
+ val info = statement.description
104
+ customJavaDocComment.executesCondition + = " {@code $info }"
105
+ }
106
+ StmtType .Return -> {
107
+ val info = statement.description
108
+ customJavaDocComment.returnsFrom = " {@code $info }"
109
+ }
110
+ else -> {
111
+ // TODO
112
+ }
102
113
}
103
114
}
115
+ currentBlock = currentBlock.nextBlock
104
116
}
105
117
106
118
return customJavaDocComment
0 commit comments