@@ -2,9 +2,8 @@ package org.utbot.framework.codegen.tree
22
33import org.utbot.framework.codegen.domain.builtin.TestClassUtilMethodProvider
44import org.utbot.framework.codegen.domain.context.CgContext
5- import org.utbot.framework.codegen.domain.models.AnnotationTarget.*
5+ import org.utbot.framework.codegen.domain.models.AnnotationTarget.Method
66import org.utbot.framework.codegen.domain.models.CgClassBody
7- import org.utbot.framework.codegen.domain.models.CgDeclaration
87import org.utbot.framework.codegen.domain.models.CgFieldDeclaration
98import org.utbot.framework.codegen.domain.models.CgFrameworkUtilMethod
109import org.utbot.framework.codegen.domain.models.CgMethod
@@ -13,21 +12,18 @@ import org.utbot.framework.codegen.domain.models.CgMethodsCluster
1312import org.utbot.framework.codegen.domain.models.CgRegion
1413import org.utbot.framework.codegen.domain.models.CgStatement
1514import org.utbot.framework.codegen.domain.models.CgStaticsRegion
16- import org.utbot.framework.codegen.domain.models.CgVariable
17- import org.utbot.framework.codegen.domain.models.SpringTestClassModel
18- import org.utbot.framework.codegen.domain.models.builders.TypedModelWrappers
15+ import org.utbot.framework.codegen.domain.models.SimpleTestClassModel
16+ import org.utbot.framework.codegen.tree.fieldmanager.ClassFieldManagerFacade
1917import org.utbot.framework.plugin.api.UtExecution
20- import org.utbot.framework.plugin.api.UtSpringContextModel
2118import org.utbot.framework.plugin.api.util.id
22- import java.lang.Exception
2319
2420abstract class CgAbstractSpringTestClassConstructor (context : CgContext ) :
25- CgAbstractTestClassConstructor <SpringTestClassModel >(context) {
21+ CgAbstractTestClassConstructor <SimpleTestClassModel >(context) {
2622
2723 protected val variableConstructor: CgSpringVariableConstructor =
2824 CgComponents .getVariableConstructorBy(context) as CgSpringVariableConstructor
2925
30- override fun constructTestClassBody (testClassModel : SpringTestClassModel ): CgClassBody {
26+ override fun constructTestClassBody (testClassModel : SimpleTestClassModel ): CgClassBody {
3127 return buildClassBody(currentTestClass) {
3228
3329 // TODO: support inner classes here
@@ -80,7 +76,7 @@ abstract class CgAbstractSpringTestClassConstructor(context: CgContext) :
8076 return if (regions.any()) regions else null
8177 }
8278
83- abstract fun constructClassFields (testClassModel : SpringTestClassModel ): List <CgFieldDeclaration >
79+ abstract fun constructClassFields (testClassModel : SimpleTestClassModel ): List <CgFieldDeclaration >
8480
8581 /* *
8682 * Here "additional" means that these tests are not obtained from
@@ -90,49 +86,6 @@ abstract class CgAbstractSpringTestClassConstructor(context: CgContext) :
9086
9187 open fun constructAdditionalUtilMethods (): CgMethodsCluster ? = null
9288
93- protected fun constructFieldsWithAnnotation (
94- fieldManager : CgClassFieldManager ,
95- groupedModelsByClassId : TypedModelWrappers ,
96- ): List <CgFieldDeclaration > {
97- val annotationClassId = fieldManager.annotationType
98- val annotation = addAnnotation(annotationClassId, Field )
99-
100- val constructedDeclarations = mutableListOf<CgFieldDeclaration >()
101- for ((classId, modelWrappers) in groupedModelsByClassId) {
102-
103- val modelWrapper = modelWrappers.firstOrNull() ? : continue
104- val model = modelWrapper.model
105-
106- val fieldWithAnnotationIsRequired = fieldManager.fieldWithAnnotationIsRequired(model.classId)
107- if (! fieldWithAnnotationIsRequired) {
108- continue
109- }
110-
111- val baseVarName = fieldManager.constructBaseVarName(model)
112-
113- val createdVariable = variableConstructor.getOrCreateVariable(model, baseVarName) as ? CgVariable
114- ? : error(" `CgVariable` cannot be constructed from a $model model" )
115-
116- val declaration = CgDeclaration (classId, variableName = createdVariable.name, initializer = null )
117-
118- constructedDeclarations + = CgFieldDeclaration (
119- ownerClassId = currentTestClass,
120- declaration,
121- annotation
122- )
123-
124- modelWrappers
125- .forEach { modelWrapper ->
126-
127- valueByUtModelWrapper[modelWrapper] = createdVariable
128-
129- variableConstructor.annotatedModelGroups
130- .getOrPut(annotationClassId) { mutableSetOf () } + = modelWrapper
131- }
132- }
133-
134- return constructedDeclarations
135- }
13689
13790 /* *
13891 * Clears the results of variable instantiations that occurred
@@ -145,8 +98,7 @@ abstract class CgAbstractSpringTestClassConstructor(context: CgContext) :
14598 * but it will take very long time to do it now.
14699 */
147100 private fun clearUnwantedVariableModels () {
148- val trustedListOfModels =
149- variableConstructor.annotatedModelGroups.values.flatten() + listOf (UtSpringContextModel .wrap())
101+ val trustedListOfModels = ClassFieldManagerFacade (context).findTrustedModels()
150102
151103 valueByUtModelWrapper
152104 .filterNot { it.key in trustedListOfModels }
0 commit comments