@@ -24,6 +24,7 @@ import org.utbot.framework.plugin.api.UtMethodTestSet
2424import org.utbot.framework.codegen.model.constructor.TestClassModel
2525import org.utbot.framework.codegen.model.tree.CgDocRegularStmt
2626import org.utbot.framework.codegen.model.tree.CgDocumentationComment
27+ import java.util.*
2728
2829class CodeGenerator (
2930 private val classUnderTest : ClassId ,
@@ -147,20 +148,20 @@ sealed class UtilClassKind(
147148 /* *
148149 * Contains comments specifying the version and the kind of util class being generated and
149150 */
150- val utilClassDocumentation: CgDocumentationComment
151- get() = CgDocumentationComment (
151+ fun utilClassDocumentation ( codegenLanguage : CodegenLanguage ) : CgDocumentationComment
152+ = CgDocumentationComment (
152153 listOf (
153154 CgDocRegularStmt (utilClassKindCommentText),
154- CgDocRegularStmt (" $UTIL_CLASS_VERSION_COMMENT_PREFIX${utilClassVersion} " ),
155+ CgDocRegularStmt (" $UTIL_CLASS_VERSION_COMMENT_PREFIX${utilClassVersion(codegenLanguage) } " ),
155156 )
156157 )
157158
158159 /* *
159160 * The version of util class being generated.
160161 * For more details see [UtilClassFileMethodProvider.UTIL_CLASS_VERSION].
161162 */
162- val utilClassVersion: String
163- get() = UtilClassFileMethodProvider .UTIL_CLASS_VERSION
163+ fun utilClassVersion ( codegenLanguage : CodegenLanguage ) : String
164+ = UtilClassFileMethodProvider (codegenLanguage) .UTIL_CLASS_VERSION
164165
165166 /* *
166167 * The text of comment specifying the kind of util class.
@@ -175,15 +176,21 @@ sealed class UtilClassKind(
175176 /* *
176177 * A kind of regular UtUtils class. "Regular" here means that this class does not use a mock framework.
177178 */
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+ ) {
179185 override val utilClassKindCommentText: String
180186 get() = " This is a regular UtUtils class (without mock framework usage)"
181187 }
182188
183189 /* *
184190 * A kind of UtUtils class that uses a mock framework. At the moment the framework is Mockito.
185191 */
186- object UtUtilsWithMockito : UtilClassKind(UtilClassFileMethodProvider , mockFrameworkUsed = true , priority = 1 ) {
192+ class UtUtilsWithMockito (val codegenLanguage : CodegenLanguage ) :
193+ UtilClassKind (UtilClassFileMethodProvider (codegenLanguage), mockFrameworkUsed = true , priority = 1 ) {
187194 override val utilClassKindCommentText: String
188195 get() = " This is UtUtils class with Mockito support"
189196 }
@@ -197,7 +204,7 @@ sealed class UtilClassKind(
197204 * @return the text of the generated util class file.
198205 */
199206 fun getUtilClassText (codegenLanguage : CodegenLanguage ): String {
200- val utilClassFile = CgUtilClassConstructor .constructUtilsClassFile(this )
207+ val utilClassFile = CgUtilClassConstructor .constructUtilsClassFile(this , codegenLanguage )
201208 val renderer = CgAbstractRenderer .makeRenderer(this , codegenLanguage)
202209 utilClassFile.accept(renderer)
203210 return renderer.toString()
@@ -212,10 +219,13 @@ sealed class UtilClassKind(
212219 */
213220 const val UTIL_CLASS_VERSION_COMMENT_PREFIX = " UtUtils class version: "
214221
215- fun utilClassKindByCommentOrNull (comment : String ): UtilClassKind ? {
222+ fun utilClassKindByCommentOrNull (
223+ comment : String ,
224+ codegenLanguage : CodegenLanguage )
225+ : UtilClassKind ? {
216226 return when (comment) {
217- RegularUtUtils .utilClassKindCommentText -> RegularUtUtils
218- UtUtilsWithMockito .utilClassKindCommentText -> UtUtilsWithMockito
227+ RegularUtUtils (codegenLanguage) .utilClassKindCommentText -> RegularUtUtils (codegenLanguage)
228+ UtUtilsWithMockito (codegenLanguage) .utilClassKindCommentText -> UtUtilsWithMockito (codegenLanguage)
219229 else -> null
220230 }
221231 }
@@ -228,24 +238,27 @@ sealed class UtilClassKind(
228238 internal fun fromCgContextOrNull (context : CgContext ): UtilClassKind ? {
229239 if (context.requiredUtilMethods.isEmpty()) return null
230240 if (! context.mockFrameworkUsed) {
231- return RegularUtUtils
241+ return RegularUtUtils (context.codegenLanguage)
232242 }
233243 return when (context.mockFramework) {
234- MockFramework .MOCKITO -> UtUtilsWithMockito
244+ MockFramework .MOCKITO -> UtUtilsWithMockito (context.codegenLanguage)
235245 // in case we will add any other mock frameworks, newer Kotlin compiler versions
236246 // will report a non-exhaustive 'when', so we will not forget to support them here as well
237247 }
238248 }
239249
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"
242252 const val PACKAGE_DELIMITER = " ."
243253
244254 /* *
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 ].
247257 */
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 }
250263 }
251264}
0 commit comments