Skip to content

Commit d554c3c

Browse files
Separate CgClassFile and TestsGenerationReport (#1345)
Refactor CgClassFile, remove report from it
1 parent 0bb97ff commit d554c3c

File tree

7 files changed

+18
-34
lines changed

7 files changed

+18
-34
lines changed

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,13 @@ open class CodeGenerator(
8181
): CodeGeneratorResult = withCustomContext(testClassCustomName) {
8282
context.withTestClassFileScope {
8383
val testClassModel = TestClassModel.fromTestSets(classUnderTest, cgTestSets)
84-
val testClassFile = CgTestClassConstructor(context).construct(testClassModel)
84+
val cgClassConstructor = CgTestClassConstructor(context)
85+
val testClassFile = cgClassConstructor.construct(testClassModel)
86+
8587
CodeGeneratorResult(
8688
generatedCode = renderClassFile(testClassFile),
8789
utilClassKind = UtilClassKind.fromCgContextOrNull(context),
88-
testsGenerationReport = testClassFile.testsGenerationReport
90+
testsGenerationReport = cgClassConstructor.testsGenerationReport
8991
)
9092
}
9193
}

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

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,16 @@ import org.utbot.framework.codegen.model.tree.CgRegion
2121
import org.utbot.framework.codegen.model.tree.CgSimpleRegion
2222
import org.utbot.framework.codegen.model.tree.CgStaticsRegion
2323
import org.utbot.framework.codegen.model.tree.CgClass
24+
import org.utbot.framework.codegen.model.tree.CgClassFile
2425
import org.utbot.framework.codegen.model.tree.CgRealNestedClassesRegion
25-
import org.utbot.framework.codegen.model.tree.CgTestClassFile
2626
import org.utbot.framework.codegen.model.tree.CgTestMethod
2727
import org.utbot.framework.codegen.model.tree.CgTestMethodCluster
2828
import org.utbot.framework.codegen.model.tree.CgTripleSlashMultilineComment
2929
import org.utbot.framework.codegen.model.tree.CgUtilEntity
3030
import org.utbot.framework.codegen.model.tree.CgUtilMethod
3131
import org.utbot.framework.codegen.model.tree.buildClass
3232
import org.utbot.framework.codegen.model.tree.buildClassBody
33-
import org.utbot.framework.codegen.model.tree.buildTestClassFile
33+
import org.utbot.framework.codegen.model.tree.buildClassFile
3434
import org.utbot.framework.codegen.model.visitor.importUtilMethodDependencies
3535
import org.utbot.framework.plugin.api.ClassId
3636
import org.utbot.framework.plugin.api.MethodId
@@ -53,16 +53,15 @@ open class CgTestClassConstructor(val context: CgContext) :
5353
private val nameGenerator = getNameGeneratorBy(context)
5454
private val testFrameworkManager = getTestFrameworkManagerBy(context)
5555

56-
protected val testsGenerationReport: TestsGenerationReport = TestsGenerationReport()
56+
val testsGenerationReport = TestsGenerationReport()
5757

5858
/**
5959
* Given a testClass model constructs CgTestClass
6060
*/
61-
open fun construct(testClassModel: TestClassModel): CgTestClassFile {
62-
return buildTestClassFile {
61+
open fun construct(testClassModel: TestClassModel): CgClassFile {
62+
return buildClassFile {
6363
this.declaredClass = withTestClassScope { constructTestClass(testClassModel) }
6464
imports += context.collectedImports
65-
testsGenerationReport = this@CgTestClassConstructor.testsGenerationReport
6665
}
6766
}
6867

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

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,6 @@ class CgClassFileBuilder : CgBuilder<CgClassFile> {
2121

2222
fun buildClassFile(init: CgClassFileBuilder.() -> Unit) = CgClassFileBuilder().apply(init).build()
2323

24-
class CgTestClassFileBuilder : CgBuilder<CgTestClassFile> {
25-
val imports: MutableList<Import> = mutableListOf()
26-
lateinit var declaredClass: CgClass
27-
lateinit var testsGenerationReport: TestsGenerationReport
28-
29-
override fun build() = CgTestClassFile(imports, declaredClass, testsGenerationReport)
30-
}
31-
32-
fun buildTestClassFile(init: CgTestClassFileBuilder.() -> Unit) = CgTestClassFileBuilder().apply(init).build()
33-
3424
class CgClassBuilder : CgBuilder<CgClass> {
3525
lateinit var id: ClassId
3626
val annotations: MutableList<CgAnnotation> = mutableListOf()

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

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ interface CgElement {
3636
// TODO: order of cases is important here due to inheritance between some of the element types
3737
fun <R> accept(visitor: CgVisitor<R>): R = visitor.run {
3838
when (val element = this@CgElement) {
39-
is CgTestClassFile -> visit(element)
4039
is CgClassFile -> visit(element)
4140
is CgClass -> visit(element)
4241
is CgClassBody -> visit(element)
@@ -125,12 +124,6 @@ open class CgClassFile(
125124
open val declaredClass: CgClass,
126125
): CgElement
127126

128-
data class CgTestClassFile(
129-
override val imports: List<Import>,
130-
override val declaredClass: CgClass,
131-
val testsGenerationReport: TestsGenerationReport
132-
) : CgClassFile(imports, declaredClass)
133-
134127
class CgClass(
135128
val id: ClassId,
136129
val annotations: List<CgAnnotation>,

utbot-js/src/main/kotlin/codegen/JsCodeGenerator.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import org.utbot.framework.codegen.model.constructor.CgMethodTestSet
1414
import org.utbot.framework.codegen.model.constructor.TestClassModel
1515
import org.utbot.framework.codegen.model.constructor.context.CgContext
1616
import org.utbot.framework.codegen.model.constructor.tree.CgTestClassConstructor
17-
import org.utbot.framework.codegen.model.tree.CgTestClassFile
1817
import org.utbot.framework.codegen.model.visitor.CgAbstractRenderer
1918
import org.utbot.framework.plugin.api.CodegenLanguage
2019
import org.utbot.framework.plugin.api.ExecutableId
@@ -78,7 +77,7 @@ class JsCodeGenerator(
7877
}
7978
}
8079

81-
private fun renderClassFile(file: CgTestClassFile): String {
80+
private fun renderClassFile(file: CgClassFile): String {
8281
val renderer = CgAbstractRenderer.makeRenderer(context)
8382
file.accept(renderer)
8483
return renderer.toString()

utbot-python/src/main/kotlin/org/utbot/python/framework/codegen/model/PythonCodeGenerator.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,10 @@ class PythonCodeGenerator(
6666
context.withTestClassFileScope {
6767
val testClassModel = TestClassModel(classUnderTest, cgTestSets)
6868
context.collectedImports.addAll(importModules)
69-
val testClassFile = PythonCgTestClassConstructor(context).construct(testClassModel)
70-
CodeGeneratorResult(renderClassFile(testClassFile), testClassFile.testsGenerationReport)
69+
val cgTestClassConstructor = PythonCgTestClassConstructor(context)
70+
71+
val testClassFile = cgTestClassConstructor.construct(testClassModel)
72+
CodeGeneratorResult(renderClassFile(testClassFile), cgTestClassConstructor.testsGenerationReport)
7173
}
7274
}
7375
}

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,17 @@ package org.utbot.python.framework.codegen.model.constructor.tree
33
import org.utbot.framework.codegen.model.constructor.TestClassModel
44
import org.utbot.framework.codegen.model.constructor.context.CgContext
55
import org.utbot.framework.codegen.model.constructor.tree.CgTestClassConstructor
6-
import org.utbot.framework.codegen.model.tree.CgTestClassFile
7-
import org.utbot.framework.codegen.model.tree.buildTestClassFile
6+
import org.utbot.framework.codegen.model.tree.CgClassFile
7+
import org.utbot.framework.codegen.model.tree.buildClassFile
88

99
internal class PythonCgTestClassConstructor(context: CgContext) : CgTestClassConstructor(context) {
10-
override fun construct(testClassModel: TestClassModel): CgTestClassFile {
11-
return buildTestClassFile {
10+
override fun construct(testClassModel: TestClassModel): CgClassFile {
11+
return buildClassFile {
1212
this.declaredClass = withTestClassScope {
1313
with(currentTestClassContext) { testClassSuperclass = testFramework.testSuperClass }
1414
constructTestClass(testClassModel)
1515
}
1616
imports.addAll(context.collectedImports)
17-
testsGenerationReport = this@PythonCgTestClassConstructor.testsGenerationReport
1817
}
1918
}
2019
}

0 commit comments

Comments
 (0)