Skip to content

Commit da98f17

Browse files
committed
Attempt to fix #1255
1 parent fdabab5 commit da98f17

File tree

4 files changed

+16
-6
lines changed

4 files changed

+16
-6
lines changed

utbot-framework/src/main/kotlin/org/utbot/framework/codegen/model/constructor/tree/CgUtilClassConstructor.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import org.utbot.framework.codegen.model.UtilClassKind
55
import org.utbot.framework.codegen.model.constructor.builtin.utUtilsClassId
66
import org.utbot.framework.codegen.model.tree.CgAuxiliaryClass
77
import org.utbot.framework.codegen.model.tree.CgRegularClassFile
8+
import org.utbot.framework.codegen.model.tree.CgStaticsRegion
89
import org.utbot.framework.codegen.model.tree.CgUtilMethod
910
import org.utbot.framework.codegen.model.tree.buildRegularClass
1011
import org.utbot.framework.codegen.model.tree.buildRegularClassBody
@@ -25,9 +26,10 @@ internal object CgUtilClassConstructor {
2526
body = buildRegularClassBody {
2627
content += utilClassKind.utilClassVersionComment
2728
content += utilClassKind.utilClassKindComment
28-
content += utilMethodProvider.utilMethodIds.map { CgUtilMethod(it) }
29+
content += CgStaticsRegion("Util methods", utilMethodProvider.utilMethodIds.map { CgUtilMethod(it) })
2930
content += CgAuxiliaryClass(utilMethodProvider.capturedArgumentClassId)
3031
}
32+
isSingleton = true
3133
}
3234
}
3335
}

utbot-framework/src/main/kotlin/org/utbot/framework/codegen/model/tree/Builders.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,9 @@ class CgRegularClassBuilder : CgBuilder<CgRegularClass> {
3939
lateinit var body: CgRegularClassBody
4040
var isStatic: Boolean = false
4141
var isNested: Boolean = false
42+
var isSingleton: Boolean = false
4243

43-
override fun build() = CgRegularClass(id, annotations, superclass, interfaces, body, isStatic, isNested)
44+
override fun build() = CgRegularClass(id, annotations, superclass, interfaces, body, isStatic, isNested, isSingleton)
4445
}
4546

4647
fun buildRegularClass(init: CgRegularClassBuilder.() -> Unit) = CgRegularClassBuilder().apply(init).build()
@@ -52,9 +53,10 @@ class CgTestClassBuilder : CgBuilder<CgTestClass> {
5253
val interfaces: MutableList<ClassId> = mutableListOf()
5354
var isStatic: Boolean = false
5455
var isNested: Boolean = false
56+
var isSingleton: Boolean = false
5557
lateinit var body: CgTestClassBody
5658

57-
override fun build() = CgTestClass(id, annotations, superclass, interfaces, body, isStatic, isNested)
59+
override fun build() = CgTestClass(id, annotations, superclass, interfaces, body, isStatic, isNested, isSingleton)
5860
}
5961

6062
fun buildTestClass(init: CgTestClassBuilder.() -> Unit) = CgTestClassBuilder().apply(init).build()

utbot-framework/src/main/kotlin/org/utbot/framework/codegen/model/tree/CgElement.kt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ sealed class AbstractCgClass<T : AbstractCgClassBody> : CgElement {
144144
abstract val body: T
145145
abstract val isStatic: Boolean
146146
abstract val isNested: Boolean
147+
abstract val isSingleton: Boolean
147148

148149
val packageName
149150
get() = id.packageName
@@ -171,7 +172,8 @@ class CgRegularClass(
171172
override val interfaces: List<ClassId>,
172173
override val body: CgRegularClassBody,
173174
override val isStatic: Boolean,
174-
override val isNested: Boolean
175+
override val isNested: Boolean,
176+
override val isSingleton: Boolean
175177
) : AbstractCgClass<CgRegularClassBody>()
176178

177179
data class CgTestClass(
@@ -181,7 +183,8 @@ data class CgTestClass(
181183
override val interfaces: List<ClassId>,
182184
override val body: CgTestClassBody,
183185
override val isStatic: Boolean,
184-
override val isNested: Boolean
186+
override val isNested: Boolean,
187+
override val isSingleton: Boolean
185188
) : AbstractCgClass<CgTestClassBody>()
186189

187190

utbot-framework/src/main/kotlin/org/utbot/framework/codegen/model/visitor/CgKotlinRenderer.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,10 @@ internal class CgKotlinRenderer(context: CgRendererContext, printer: CgPrinter =
9191
if (!element.isStatic && element.isNested) {
9292
print("inner ")
9393
}
94-
print("class ")
94+
if (element.isSingleton)
95+
print("object ")
96+
else
97+
print("class ")
9598
print(element.simpleName)
9699

97100
if (element.superclass != null || element.interfaces.isNotEmpty()) {

0 commit comments

Comments
 (0)