1
+ package org.utbot.summary.comment.customtags.symbolic
2
+
3
+ import org.utbot.framework.plugin.api.DocRegularStmt
4
+ import org.utbot.summary.comment.customtags.fuzzer.CommentWithCustomTagForTestProducedByFuzzer
5
+
6
+ /* *
7
+ * Provides a list of supported custom JavaDoc tags.
8
+ */
9
+ class CustomJavaDocTagProvider {
10
+ // The tags' order is important because plugin builds final JavaDoc comment according to it.
11
+ fun getPluginCustomTags (): List <CustomJavaDocTag > =
12
+ listOf (
13
+ CustomJavaDocTag .ClassUnderTest ,
14
+ CustomJavaDocTag .MethodUnderTest ,
15
+ CustomJavaDocTag .ExpectedResult ,
16
+ CustomJavaDocTag .ActualResult ,
17
+ CustomJavaDocTag .Executes ,
18
+ CustomJavaDocTag .Invokes ,
19
+ CustomJavaDocTag .Iterates ,
20
+ CustomJavaDocTag .SwitchCase ,
21
+ CustomJavaDocTag .Recursion ,
22
+ CustomJavaDocTag .ReturnsFrom ,
23
+ CustomJavaDocTag .CaughtException ,
24
+ CustomJavaDocTag .ThrowsException ,
25
+ )
26
+ }
27
+
28
+ sealed class CustomJavaDocTag (
29
+ val name : String ,
30
+ val message : String ,
31
+ private val valueRetriever : (CustomJavaDocComment ) -> Any ,
32
+ private val valueRetrieverFuzzer : ((CommentWithCustomTagForTestProducedByFuzzer ) -> Any )? // TODO: remove after refactoring
33
+ ) {
34
+ object ClassUnderTest :
35
+ CustomJavaDocTag (
36
+ " utbot.classUnderTest" ,
37
+ " Class under test" ,
38
+ CustomJavaDocComment ::classUnderTest,
39
+ CommentWithCustomTagForTestProducedByFuzzer ::classUnderTest
40
+ )
41
+
42
+ object MethodUnderTest :
43
+ CustomJavaDocTag (
44
+ " utbot.methodUnderTest" ,
45
+ " Method under test" ,
46
+ CustomJavaDocComment ::methodUnderTest,
47
+ CommentWithCustomTagForTestProducedByFuzzer ::methodUnderTest
48
+ )
49
+
50
+ object ExpectedResult :
51
+ CustomJavaDocTag (" utbot.expectedResult" , " Expected result" , CustomJavaDocComment ::expectedResult, null )
52
+
53
+ object ActualResult :
54
+ CustomJavaDocTag (" utbot.actualResult" , " Actual result" , CustomJavaDocComment ::actualResult, null )
55
+
56
+ object Executes :
57
+ CustomJavaDocTag (" utbot.executesCondition" , " Executes condition" , CustomJavaDocComment ::executesCondition, null )
58
+
59
+ object Invokes : CustomJavaDocTag(" utbot.invokes" , " Invokes" , CustomJavaDocComment : :invokes, null )
60
+ object Iterates : CustomJavaDocTag(" utbot.iterates" , " Iterates" , CustomJavaDocComment : :iterates, null )
61
+ object SwitchCase :
62
+ CustomJavaDocTag (" utbot.activatesSwitch" , " Activates switch" , CustomJavaDocComment ::switchCase, null )
63
+
64
+ object Recursion :
65
+ CustomJavaDocTag (" utbot.triggersRecursion" , " Triggers recursion " , CustomJavaDocComment ::recursion, null )
66
+
67
+ object ReturnsFrom : CustomJavaDocTag(" utbot.returnsFrom" , " Returns from" , CustomJavaDocComment : :returnsFrom, null )
68
+ object CaughtException :
69
+ CustomJavaDocTag (" utbot.caughtException" , " Caught exception" , CustomJavaDocComment ::caughtException, null )
70
+
71
+ object ThrowsException :
72
+ CustomJavaDocTag (" utbot.throwsException" , " Throws exception" , CustomJavaDocComment ::throwsException, null )
73
+
74
+ fun generateDocStatement (comment : CustomJavaDocComment ): DocRegularStmt ? =
75
+ when (val value = valueRetriever.invoke(comment)) {
76
+ is String -> value.takeIf { it.isNotEmpty() }?.let {
77
+ DocRegularStmt (" @$name $value \n " )
78
+ }
79
+ is List <* > -> value.takeIf { it.isNotEmpty() }?.let {
80
+ val valueToString = value.joinToString(separator = " \n " , postfix = " \n " ) { " @$name $it " }
81
+
82
+ DocRegularStmt (valueToString)
83
+ }
84
+ else -> null
85
+ }
86
+
87
+ // TODO: could be universal with the function above after creation of hierarchy data classes related to the comments
88
+ fun generateDocStatementForTestProducedByFuzzer (comment : CommentWithCustomTagForTestProducedByFuzzer ): DocRegularStmt ? {
89
+ if (valueRetrieverFuzzer != null ) { // TODO: it required only when we have two different retrievers
90
+ return when (val value = valueRetrieverFuzzer!! .invoke(comment)) { // TODO: unsafe !! - resolve
91
+ is String -> value.takeIf { it.isNotEmpty() }?.let {
92
+ DocRegularStmt (" @$name $value \n " )
93
+ }
94
+
95
+ is List <* > -> value.takeIf { it.isNotEmpty() }?.let {
96
+ val valueToString = value.joinToString(separator = " ,\n " , postfix = " \n " )
97
+
98
+ DocRegularStmt (" @$name $valueToString " )
99
+ }
100
+
101
+ else -> null
102
+ }
103
+ }
104
+ return null
105
+ }
106
+ }
0 commit comments