@@ -24,6 +24,7 @@ import org.utbot.framework.plugin.api.UtMethodTestSet
24
24
import org.utbot.framework.codegen.model.constructor.TestClassModel
25
25
import org.utbot.framework.codegen.model.tree.CgDocRegularStmt
26
26
import org.utbot.framework.codegen.model.tree.CgDocumentationComment
27
+ import java.util.*
27
28
28
29
class CodeGenerator (
29
30
private val classUnderTest : ClassId ,
@@ -147,20 +148,20 @@ sealed class UtilClassKind(
147
148
/* *
148
149
* Contains comments specifying the version and the kind of util class being generated and
149
150
*/
150
- val utilClassDocumentation: CgDocumentationComment
151
- get() = CgDocumentationComment (
151
+ fun utilClassDocumentation ( codegenLanguage : CodegenLanguage ) : CgDocumentationComment
152
+ = CgDocumentationComment (
152
153
listOf (
153
154
CgDocRegularStmt (utilClassKindCommentText),
154
- CgDocRegularStmt (" $UTIL_CLASS_VERSION_COMMENT_PREFIX${utilClassVersion} " ),
155
+ CgDocRegularStmt (" $UTIL_CLASS_VERSION_COMMENT_PREFIX${utilClassVersion(codegenLanguage) } " ),
155
156
)
156
157
)
157
158
158
159
/* *
159
160
* The version of util class being generated.
160
161
* For more details see [UtilClassFileMethodProvider.UTIL_CLASS_VERSION].
161
162
*/
162
- val utilClassVersion: String
163
- get() = UtilClassFileMethodProvider .UTIL_CLASS_VERSION
163
+ fun utilClassVersion ( codegenLanguage : CodegenLanguage ) : String
164
+ = UtilClassFileMethodProvider (codegenLanguage) .UTIL_CLASS_VERSION
164
165
165
166
/* *
166
167
* The text of comment specifying the kind of util class.
@@ -175,15 +176,21 @@ sealed class UtilClassKind(
175
176
/* *
176
177
* A kind of regular UtUtils class. "Regular" here means that this class does not use a mock framework.
177
178
*/
178
- object RegularUtUtils : UtilClassKind(UtilClassFileMethodProvider , mockFrameworkUsed = false , priority = 0 ) {
179
+ class RegularUtUtils (val codegenLanguage : CodegenLanguage ) :
180
+ UtilClassKind (
181
+ UtilClassFileMethodProvider (codegenLanguage),
182
+ mockFrameworkUsed = false ,
183
+ priority = 0 ,
184
+ ) {
179
185
override val utilClassKindCommentText: String
180
186
get() = " This is a regular UtUtils class (without mock framework usage)"
181
187
}
182
188
183
189
/* *
184
190
* A kind of UtUtils class that uses a mock framework. At the moment the framework is Mockito.
185
191
*/
186
- object UtUtilsWithMockito : UtilClassKind(UtilClassFileMethodProvider , mockFrameworkUsed = true , priority = 1 ) {
192
+ class UtUtilsWithMockito (val codegenLanguage : CodegenLanguage ) :
193
+ UtilClassKind (UtilClassFileMethodProvider (codegenLanguage), mockFrameworkUsed = true , priority = 1 ) {
187
194
override val utilClassKindCommentText: String
188
195
get() = " This is UtUtils class with Mockito support"
189
196
}
@@ -197,7 +204,7 @@ sealed class UtilClassKind(
197
204
* @return the text of the generated util class file.
198
205
*/
199
206
fun getUtilClassText (codegenLanguage : CodegenLanguage ): String {
200
- val utilClassFile = CgUtilClassConstructor .constructUtilsClassFile(this )
207
+ val utilClassFile = CgUtilClassConstructor .constructUtilsClassFile(this , codegenLanguage )
201
208
val renderer = CgAbstractRenderer .makeRenderer(this , codegenLanguage)
202
209
utilClassFile.accept(renderer)
203
210
return renderer.toString()
@@ -212,10 +219,13 @@ sealed class UtilClassKind(
212
219
*/
213
220
const val UTIL_CLASS_VERSION_COMMENT_PREFIX = " UtUtils class version: "
214
221
215
- fun utilClassKindByCommentOrNull (comment : String ): UtilClassKind ? {
222
+ fun utilClassKindByCommentOrNull (
223
+ comment : String ,
224
+ codegenLanguage : CodegenLanguage )
225
+ : UtilClassKind ? {
216
226
return when (comment) {
217
- RegularUtUtils .utilClassKindCommentText -> RegularUtUtils
218
- UtUtilsWithMockito .utilClassKindCommentText -> UtUtilsWithMockito
227
+ RegularUtUtils (codegenLanguage) .utilClassKindCommentText -> RegularUtUtils (codegenLanguage)
228
+ UtUtilsWithMockito (codegenLanguage) .utilClassKindCommentText -> UtUtilsWithMockito (codegenLanguage)
219
229
else -> null
220
230
}
221
231
}
@@ -228,24 +238,27 @@ sealed class UtilClassKind(
228
238
internal fun fromCgContextOrNull (context : CgContext ): UtilClassKind ? {
229
239
if (context.requiredUtilMethods.isEmpty()) return null
230
240
if (! context.mockFrameworkUsed) {
231
- return RegularUtUtils
241
+ return RegularUtUtils (context.codegenLanguage)
232
242
}
233
243
return when (context.mockFramework) {
234
- MockFramework .MOCKITO -> UtUtilsWithMockito
244
+ MockFramework .MOCKITO -> UtUtilsWithMockito (context.codegenLanguage)
235
245
// in case we will add any other mock frameworks, newer Kotlin compiler versions
236
246
// will report a non-exhaustive 'when', so we will not forget to support them here as well
237
247
}
238
248
}
239
249
240
- const val UT_UTILS_PACKAGE_NAME = " org.utbot.runtime.utils"
241
- const val UT_UTILS_CLASS_NAME = " UtUtils"
250
+ const val UT_UTILS_BASE_PACKAGE_NAME = " org.utbot.runtime.utils"
251
+ const val UT_UTILS_INSTANCE_NAME = " UtUtils"
242
252
const val PACKAGE_DELIMITER = " ."
243
253
244
254
/* *
245
- * List of package names of UtUtils class.
246
- * See whole package name at [UT_UTILS_PACKAGE_NAME ].
255
+ * List of package name components of UtUtils class.
256
+ * See whole package name at [UT_UTILS_BASE_PACKAGE_NAME ].
247
257
*/
248
- val utilsPackages: List <String >
249
- get() = UT_UTILS_PACKAGE_NAME .split(PACKAGE_DELIMITER )
258
+ fun utilsPackageNames (codegenLanguage : CodegenLanguage ): List <String >
259
+ = UT_UTILS_BASE_PACKAGE_NAME .split(PACKAGE_DELIMITER ) + codegenLanguage.name.lowercase(Locale .getDefault())
260
+
261
+ fun utilsPackageFullName (codegenLanguage : CodegenLanguage ): String
262
+ = utilsPackageNames(codegenLanguage).joinToString { PACKAGE_DELIMITER }
250
263
}
251
264
}
0 commit comments