Skip to content

Commit bfd5827

Browse files
committed
Fix compilation after rebase
1 parent 40f3228 commit bfd5827

File tree

2 files changed

+65
-70
lines changed

2 files changed

+65
-70
lines changed

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

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,13 @@ interface CgContextOwner {
457457
val getLambdaMethod: MethodId
458458
get() = utilMethodProvider.getLambdaMethodMethodId
459459

460-
fun UtModel.wrap(modelTagName: String? = null): UtModelWrapper
460+
fun UtModel.wrap(modelTagName: String? = null): UtModelWrapper =
461+
UtModelWrapper(
462+
testSetId = currentTestSetId,
463+
executionId = currentExecutionId,
464+
model = this,
465+
modelTagName = modelTagName
466+
)
461467
}
462468

463469
/**
@@ -586,14 +592,6 @@ class CgContext(
586592
}
587593
}
588594

589-
override fun UtModel.wrap(modelTagName: String?): UtModelWrapper =
590-
UtModelWrapper(
591-
testSetId = currentTestSetId,
592-
executionId = currentExecutionId,
593-
model = this,
594-
modelTagName = modelTagName
595-
)
596-
597595
private fun createClassIdForNestedClass(testClassModel: SimpleTestClassModel): ClassId {
598596
val simpleName = "${testClassModel.classUnderTest.simpleName}Test"
599597
return BuiltinClassId(

utbot-framework/src/main/kotlin/org/utbot/framework/codegen/domain/models/builders/SpringTestClassModelBuilder.kt

Lines changed: 58 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package org.utbot.framework.codegen.domain.models.builders
22

33
import org.utbot.framework.codegen.domain.UtModelWrapper
44
import org.utbot.framework.codegen.domain.context.CgContext
5+
import org.utbot.framework.codegen.domain.context.CgContextOwner
56
import org.utbot.framework.codegen.domain.models.CgMethodTestSet
67
import org.utbot.framework.codegen.domain.models.SpringSpecificInformation
78
import org.utbot.framework.codegen.domain.models.SpringTestClassModel
@@ -24,7 +25,9 @@ import org.utbot.framework.plugin.api.util.SpringModelUtils.isAutowiredFromConte
2425

2526
typealias TypedModelWrappers = Map<ClassId, Set<UtModelWrapper>>
2627

27-
class SpringTestClassModelBuilder(val context: CgContext): TestClassModelBuilder() {
28+
class SpringTestClassModelBuilder(val context: CgContext):
29+
TestClassModelBuilder(),
30+
CgContextOwner by context {
2831

2932
override fun createTestClassModel(classUnderTest: ClassId, testSets: List<CgMethodTestSet>): SpringTestClassModel {
3033
val baseModel = SimpleTestClassModelBuilder(context).createTestClassModel(classUnderTest, testSets)
@@ -43,23 +46,21 @@ class SpringTestClassModelBuilder(val context: CgContext): TestClassModelBuilder
4346
val thisInstancesDependentModels = mutableSetOf<UtModelWrapper>()
4447
val stateBeforeDependentModels = mutableSetOf<UtModelWrapper>()
4548

46-
with(context) {
47-
for ((testSetIndex, testSet) in testSets.withIndex()) {
48-
withTestSetIdScope(testSetIndex) {
49-
for ((executionIndex, execution) in testSet.executions.withIndex()) {
50-
withExecutionIdScope(executionIndex) {
51-
setOf(execution.stateBefore.thisInstance, execution.stateAfter.thisInstance)
52-
.filterNotNull()
53-
.forEach { model ->
54-
thisInstanceModels += model.wrap()
55-
thisInstancesDependentModels += collectByModel(model)
56-
57-
}
58-
59-
(execution.stateBefore.parameters + execution.stateBefore.thisInstance)
60-
.filterNotNull()
61-
.forEach { model -> stateBeforeDependentModels += collectByModel(model) }
62-
}
49+
for ((testSetIndex, testSet) in testSets.withIndex()) {
50+
withTestSetIdScope(testSetIndex) {
51+
for ((executionIndex, execution) in testSet.executions.withIndex()) {
52+
withExecutionIdScope(executionIndex) {
53+
setOf(execution.stateBefore.thisInstance, execution.stateAfter.thisInstance)
54+
.filterNotNull()
55+
.forEach { model ->
56+
thisInstanceModels += model.wrap()
57+
thisInstancesDependentModels += collectByModel(model)
58+
59+
}
60+
61+
(execution.stateBefore.parameters + execution.stateBefore.thisInstance)
62+
.filterNotNull()
63+
.forEach { model -> stateBeforeDependentModels += collectByModel(model) }
6364
}
6465
}
6566
}
@@ -84,9 +85,7 @@ class SpringTestClassModelBuilder(val context: CgContext): TestClassModelBuilder
8485
private fun collectByModel(model: UtModel): Set<UtModelWrapper> {
8586
val dependentModels = mutableSetOf<UtModelWrapper>()
8687

87-
with(context){
88-
collectRecursively(model.wrap(), dependentModels)
89-
}
88+
collectRecursively(model.wrap(), dependentModels)
9089

9190
return dependentModels
9291
}
@@ -106,51 +105,49 @@ class SpringTestClassModelBuilder(val context: CgContext): TestClassModelBuilder
106105
return
107106
}
108107

109-
with(context) {
110-
when (val currentModel = currentModelWrapper.model) {
111-
is UtNullModel,
112-
is UtPrimitiveModel,
113-
is UtClassRefModel,
114-
is UtVoidModel,
115-
is UtEnumConstantModel -> {}
116-
is UtCustomModel -> currentModel.origin?.let {
117-
collectRecursively(it.wrap(currentModelWrapper.modelTagName), allModels)
118-
}
119-
is UtLambdaModel -> {
120-
currentModel.capturedValues.forEach { collectRecursively(it.wrap(), allModels) }
121-
}
122-
is UtArrayModel -> {
123-
currentModel.stores.values.forEach { collectRecursively(it.wrap(), allModels) }
124-
if (currentModel.stores.count() < currentModel.length) {
125-
collectRecursively(currentModel.constModel.wrap(), allModels)
126-
}
108+
when (val currentModel = currentModelWrapper.model) {
109+
is UtNullModel,
110+
is UtPrimitiveModel,
111+
is UtClassRefModel,
112+
is UtVoidModel,
113+
is UtEnumConstantModel -> {}
114+
is UtCustomModel -> currentModel.origin?.let {
115+
collectRecursively(it.wrap(currentModelWrapper.modelTagName), allModels)
116+
}
117+
is UtLambdaModel -> {
118+
currentModel.capturedValues.forEach { collectRecursively(it.wrap(), allModels) }
119+
}
120+
is UtArrayModel -> {
121+
currentModel.stores.values.forEach { collectRecursively(it.wrap(), allModels) }
122+
if (currentModel.stores.count() < currentModel.length) {
123+
collectRecursively(currentModel.constModel.wrap(), allModels)
127124
}
128-
is UtCompositeModel -> {
129-
// Here we traverse fields only.
130-
// Traversing mocks as well will result in wrong models playing
131-
// a role of class fields with @Mock annotation.
132-
currentModel.fields.forEach { (fieldId, model) ->
133-
// We use `modelTagName` in order to distinguish mock models
134-
val modeTagName = if(model.isMockModel()) fieldId.name else null
135-
collectRecursively(model.wrap(modeTagName), allModels)
136-
}
125+
}
126+
is UtCompositeModel -> {
127+
// Here we traverse fields only.
128+
// Traversing mocks as well will result in wrong models playing
129+
// a role of class fields with @Mock annotation.
130+
currentModel.fields.forEach { (fieldId, model) ->
131+
// We use `modelTagName` in order to distinguish mock models
132+
val modeTagName = if(model.isMockModel()) fieldId.name else null
133+
collectRecursively(model.wrap(modeTagName), allModels)
137134
}
138-
is UtAssembleModel -> {
139-
currentModel.origin?.let { collectRecursively(it.wrap(), allModels) }
140-
141-
currentModel.instantiationCall.instance?.let { collectRecursively(it.wrap(), allModels) }
142-
currentModel.instantiationCall.params.forEach { collectRecursively(it.wrap(), allModels) }
143-
144-
currentModel.modificationsChain.forEach { stmt ->
145-
stmt.instance?.let { collectRecursively(it.wrap(), allModels) }
146-
when (stmt) {
147-
is UtStatementCallModel -> stmt.params.forEach { collectRecursively(it.wrap(), allModels) }
148-
is UtDirectSetFieldModel -> collectRecursively(stmt.fieldModel.wrap(), allModels)
149-
}
135+
}
136+
is UtAssembleModel -> {
137+
currentModel.origin?.let { collectRecursively(it.wrap(), allModels) }
138+
139+
currentModel.instantiationCall.instance?.let { collectRecursively(it.wrap(), allModels) }
140+
currentModel.instantiationCall.params.forEach { collectRecursively(it.wrap(), allModels) }
141+
142+
currentModel.modificationsChain.forEach { stmt ->
143+
stmt.instance?.let { collectRecursively(it.wrap(), allModels) }
144+
when (stmt) {
145+
is UtStatementCallModel -> stmt.params.forEach { collectRecursively(it.wrap(), allModels) }
146+
is UtDirectSetFieldModel -> collectRecursively(stmt.fieldModel.wrap(), allModels)
150147
}
151148
}
152-
//Python, JavaScript, Go models are not required in Spring
153149
}
150+
//Python, JavaScript, Go models are not required in Spring
154151
}
155152
}
156153
}

0 commit comments

Comments
 (0)