@@ -2,9 +2,8 @@ package org.utbot.framework.codegen.tree
2
2
3
3
import org.utbot.framework.codegen.domain.builtin.TestClassUtilMethodProvider
4
4
import 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
6
6
import org.utbot.framework.codegen.domain.models.CgClassBody
7
- import org.utbot.framework.codegen.domain.models.CgDeclaration
8
7
import org.utbot.framework.codegen.domain.models.CgFieldDeclaration
9
8
import org.utbot.framework.codegen.domain.models.CgFrameworkUtilMethod
10
9
import org.utbot.framework.codegen.domain.models.CgMethod
@@ -13,21 +12,18 @@ import org.utbot.framework.codegen.domain.models.CgMethodsCluster
13
12
import org.utbot.framework.codegen.domain.models.CgRegion
14
13
import org.utbot.framework.codegen.domain.models.CgStatement
15
14
import 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
19
17
import org.utbot.framework.plugin.api.UtExecution
20
- import org.utbot.framework.plugin.api.UtSpringContextModel
21
18
import org.utbot.framework.plugin.api.util.id
22
- import java.lang.Exception
23
19
24
20
abstract class CgAbstractSpringTestClassConstructor (context : CgContext ) :
25
- CgAbstractTestClassConstructor <SpringTestClassModel >(context) {
21
+ CgAbstractTestClassConstructor <SimpleTestClassModel >(context) {
26
22
27
23
protected val variableConstructor: CgSpringVariableConstructor =
28
24
CgComponents .getVariableConstructorBy(context) as CgSpringVariableConstructor
29
25
30
- override fun constructTestClassBody (testClassModel : SpringTestClassModel ): CgClassBody {
26
+ override fun constructTestClassBody (testClassModel : SimpleTestClassModel ): CgClassBody {
31
27
return buildClassBody(currentTestClass) {
32
28
33
29
// TODO: support inner classes here
@@ -80,7 +76,7 @@ abstract class CgAbstractSpringTestClassConstructor(context: CgContext) :
80
76
return if (regions.any()) regions else null
81
77
}
82
78
83
- abstract fun constructClassFields (testClassModel : SpringTestClassModel ): List <CgFieldDeclaration >
79
+ abstract fun constructClassFields (testClassModel : SimpleTestClassModel ): List <CgFieldDeclaration >
84
80
85
81
/* *
86
82
* Here "additional" means that these tests are not obtained from
@@ -90,49 +86,6 @@ abstract class CgAbstractSpringTestClassConstructor(context: CgContext) :
90
86
91
87
open fun constructAdditionalUtilMethods (): CgMethodsCluster ? = null
92
88
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
- }
136
89
137
90
/* *
138
91
* Clears the results of variable instantiations that occurred
@@ -145,8 +98,7 @@ abstract class CgAbstractSpringTestClassConstructor(context: CgContext) :
145
98
* but it will take very long time to do it now.
146
99
*/
147
100
private fun clearUnwantedVariableModels () {
148
- val trustedListOfModels =
149
- variableConstructor.annotatedModelGroups.values.flatten() + listOf (UtSpringContextModel .wrap())
101
+ val trustedListOfModels = ClassFieldManagerFacade (context).findTrustedModels()
150
102
151
103
valueByUtModelWrapper
152
104
.filterNot { it.key in trustedListOfModels }
0 commit comments