Skip to content

Commit 43f0728

Browse files
committed
Some code clean up
1 parent 0490ad6 commit 43f0728

File tree

4 files changed

+11
-17
lines changed

4 files changed

+11
-17
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -788,5 +788,5 @@ data class ModelId(
788788
private val executionId: Int,
789789
)
790790

791-
fun UtModel.modelId(executionId: Int = -1): ModelId = ModelId(this.idOrNull(), executionId)
791+
fun UtModel.withId(executionId: Int = -1) = this to ModelId(this.idOrNull(), executionId)
792792

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import org.utbot.framework.codegen.domain.builtin.UtilClassFileMethodProvider
3030
import org.utbot.framework.codegen.domain.builtin.UtilMethodProvider
3131
import org.utbot.framework.codegen.domain.models.SimpleTestClassModel
3232
import org.utbot.framework.codegen.domain.models.CgParameterKind
33-
import org.utbot.framework.codegen.domain.modelId
33+
import org.utbot.framework.codegen.domain.withId
3434
import org.utbot.framework.codegen.services.access.Block
3535
import org.utbot.framework.codegen.tree.EnvironmentFieldStateCache
3636
import org.utbot.framework.codegen.tree.importIfNeeded
@@ -573,7 +573,7 @@ data class CgContext(
573573

574574
override fun getIdByModel(model: UtModel): ModelId {
575575
if (model !in this.modelIds) {
576-
this.modelIds += model to model.modelId()
576+
this.modelIds += model.withId()
577577
}
578578

579579
return modelIds[model]

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package org.utbot.framework.codegen.domain.models.builders
33
import org.utbot.framework.codegen.domain.context.CgContext
44
import org.utbot.framework.codegen.domain.models.CgMethodTestSet
55
import org.utbot.framework.codegen.domain.models.SpringTestClassModel
6-
import org.utbot.framework.codegen.domain.modelId
6+
import org.utbot.framework.codegen.domain.withId
77
import org.utbot.framework.plugin.api.ClassId
88
import org.utbot.framework.plugin.api.UtArrayModel
99
import org.utbot.framework.plugin.api.UtAssembleModel
@@ -61,13 +61,13 @@ class SpringTestClassModelBuilder(val context: CgContext): TestClassModelBuilder
6161
}
6262

6363
private fun collectByThisInstanceModel(model: UtModel, executionIndex: Int): Set<UtModel> {
64-
context.modelIds += model to model.modelId(executionIndex)
64+
context.modelIds += model.withId(executionIndex)
6565

6666
val dependentModels = mutableSetOf<UtModel>()
6767
collectRecursively(model, dependentModels)
6868

6969
dependentModels.forEach { model ->
70-
context.modelIds += model to model.modelId(executionIndex)
70+
context.modelIds += model.withId(executionIndex)
7171
}
7272

7373
return dependentModels

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

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,13 @@ class CgSpringVariableConstructor(context: CgContext) : CgVariableConstructor(co
1818
override fun getOrCreateVariable(model: UtModel, name: String?): CgValue {
1919
val alreadyCreatedInjectMocks = findCgValueByModel(model, injectedMocksModelsVariables)
2020
if (alreadyCreatedInjectMocks != null) {
21-
if (model is UtCompositeModel) {
22-
for (mock in model.fields.values) {
23-
getOrCreateVariable(mock)
24-
}
21+
val fields: Collection<UtModel> = when (model) {
22+
is UtCompositeModel -> model.fields.values
23+
is UtAssembleModel -> model.origin?.fields?.values ?: emptyList()
24+
else -> emptyList()
2525
}
2626

27-
if (model is UtAssembleModel) {
28-
model.origin?.let { compositeModel ->
29-
for (mock in compositeModel.fields.values) {
30-
getOrCreateVariable(mock)
31-
}
32-
}
33-
}
27+
fields.forEach { getOrCreateVariable(it) }
3428

3529
return alreadyCreatedInjectMocks
3630
}

0 commit comments

Comments
 (0)