Skip to content

Commit ca7df7c

Browse files
Save already created mock model in models to variables cache #2494 #2595 (#2532)
1 parent fbf87e3 commit ca7df7c

File tree

5 files changed

+8
-15
lines changed

5 files changed

+8
-15
lines changed

utbot-framework/src/main/kotlin/org/utbot/framework/codegen/domain/context/CgContext.kt

+1-9
Original file line numberDiff line numberDiff line change
@@ -20,22 +20,19 @@ import org.utbot.framework.codegen.domain.builtin.UtilClassFileMethodProvider
2020
import org.utbot.framework.codegen.domain.builtin.UtilMethodProvider
2121
import org.utbot.framework.codegen.domain.models.*
2222
import org.utbot.framework.codegen.services.access.Block
23-
import org.utbot.framework.codegen.services.access.CgFieldStateManager
2423
import org.utbot.framework.codegen.tree.EnvironmentFieldStateCache
2524
import org.utbot.framework.codegen.tree.importIfNeeded
2625
import org.utbot.framework.plugin.api.BuiltinClassId
2726
import org.utbot.framework.plugin.api.ClassId
2827
import org.utbot.framework.codegen.services.language.CgLanguageAssistant
2928
import org.utbot.framework.codegen.tree.fieldmanager.CgAbstractClassFieldManager
30-
import org.utbot.framework.codegen.tree.fieldmanager.CgClassFieldManager
3129
import org.utbot.framework.plugin.api.CodegenLanguage
3230
import org.utbot.framework.plugin.api.ExecutableId
3331
import org.utbot.framework.plugin.api.FieldId
3432
import org.utbot.framework.plugin.api.MethodId
3533
import org.utbot.framework.plugin.api.MockFramework
3634
import org.utbot.framework.plugin.api.UtExecution
3735
import org.utbot.framework.plugin.api.UtModel
38-
import org.utbot.framework.plugin.api.UtReferenceModel
3936
import org.utbot.framework.plugin.api.util.id
4037
import org.utbot.framework.plugin.api.util.isCheckedException
4138
import org.utbot.framework.plugin.api.util.isSubtypeOf
@@ -344,14 +341,9 @@ interface CgContextOwner {
344341
return result
345342
}
346343

347-
fun updateVariableScope(variable: CgVariable, model: UtModel? = null) {
344+
fun rememberVariableForModel(variable: CgVariable, model: UtModel? = null) {
348345
model?.let {
349346
valueByUtModelWrapper[it.wrap()] = variable
350-
(model as UtReferenceModel).let { refModel ->
351-
refModel.id.let {
352-
valueByUtModelWrapper[model.wrap()] = variable
353-
}
354-
}
355347
}
356348
}
357349

utbot-framework/src/main/kotlin/org/utbot/framework/codegen/services/framework/MockFrameworkManager.kt

+2-1
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,8 @@ private class MockitoMocker(context: CgContext) : ObjectMocker(context) {
185185

186186
override fun createMock(model: UtCompositeModel, baseName: String): CgVariable {
187187
val modelClass = getClassOf(model.classId)
188-
val mockObject = newVar(model.classId, baseName = baseName, isMock = true) { mock(modelClass) }
188+
val mockObject =
189+
newVar(model.classId, model = model, baseName = baseName, isMock = true) { mock(modelClass) }
189190

190191
mockForVariable(model, mockObject)
191192

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ internal class CgStatementConstructorImpl(context: CgContext) :
209209
}
210210

211211
classRef?.let { declaredClassRefs = declaredClassRefs.put(it, declaration.variable) }
212-
updateVariableScope(declaration.variable, model)
212+
rememberVariableForModel(declaration.variable, model)
213213

214214
return Either.left(declaration)
215215
}
@@ -469,7 +469,7 @@ internal class CgStatementConstructorImpl(context: CgContext) :
469469

470470
override fun declareVariable(type: ClassId, name: String): CgVariable =
471471
CgVariable(name, type).also {
472-
updateVariableScope(it)
472+
rememberVariableForModel(it)
473473
}
474474

475475
override fun wrapTypeIfRequired(baseType: ClassId): ClassId =

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -540,7 +540,7 @@ open class CgVariableConstructor(val context: CgContext) :
540540
): Pair<CgVariable, CgDeclaration> {
541541
val declaration = CgDeclaration(variableType, baseVariableName.toVarName(), initializer.resolve())
542542
val variable = declaration.variable
543-
updateVariableScope(variable)
543+
rememberVariableForModel(variable)
544544
return variable to declaration
545545
}
546546

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ class PythonCgStatementConstructorImpl(context: CgContext) :
9494
variableName = name
9595
initializer = expr
9696
}
97-
updateVariableScope(declaration.variable, model)
97+
rememberVariableForModel(declaration.variable, model)
9898
return Either.left(declaration)
9999
}
100100

@@ -280,7 +280,7 @@ class PythonCgStatementConstructorImpl(context: CgContext) :
280280

281281
override fun declareVariable(type: ClassId, name: String): CgVariable =
282282
CgVariable(name, type).also {
283-
updateVariableScope(it)
283+
rememberVariableForModel(it)
284284
}
285285

286286
override fun guardExpression(baseType: ClassId, expression: CgExpression): ExpressionWithType {

0 commit comments

Comments
 (0)