From b3a846459bfa759b576bf151f79efcea7b8cdafb Mon Sep 17 00:00:00 2001 From: Rustam Sadykov Date: Thu, 8 Dec 2022 14:56:56 +0300 Subject: [PATCH] fix statics construction --- .../concrete/UtExecutionInstrumentation.kt | 2 +- .../concrete/phases/ModelConstructionContext.kt | 16 +++++++++++++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/utbot-framework/src/main/kotlin/org/utbot/framework/concrete/UtExecutionInstrumentation.kt b/utbot-framework/src/main/kotlin/org/utbot/framework/concrete/UtExecutionInstrumentation.kt index 0ade2e9dbb..6c01687d28 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/framework/concrete/UtExecutionInstrumentation.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/framework/concrete/UtExecutionInstrumentation.kt @@ -169,7 +169,7 @@ object UtExecutionInstrumentation : Instrumentation { val executionResult = convertToExecutionResult(concreteResult, returnClassId) val stateAfterParametersWithThis = constructParameters(params) - val stateAfterStatics = constructStatics(statics.keys/* + traceHandler.computePutStatics()*/) + val stateAfterStatics = constructStatics(stateBefore, statics) val (stateAfterThis, stateAfterParameters) = if (stateBefore.thisInstance == null) { null to stateAfterParametersWithThis } else { diff --git a/utbot-framework/src/main/kotlin/org/utbot/framework/concrete/phases/ModelConstructionContext.kt b/utbot-framework/src/main/kotlin/org/utbot/framework/concrete/phases/ModelConstructionContext.kt index f33be90842..ca6a8fdd13 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/framework/concrete/phases/ModelConstructionContext.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/framework/concrete/phases/ModelConstructionContext.kt @@ -6,6 +6,7 @@ import org.utbot.common.withAccessibility import org.utbot.framework.concrete.constructors.UtCompositeModelStrategy import org.utbot.framework.concrete.constructors.UtModelConstructor import org.utbot.framework.plugin.api.ClassId +import org.utbot.framework.plugin.api.EnvironmentModels import org.utbot.framework.plugin.api.FieldId import org.utbot.framework.plugin.api.TimeoutException import org.utbot.framework.plugin.api.UtConcreteValue @@ -58,11 +59,20 @@ class ModelConstructionContext( constructor.construct(it.value, it.clazz.id) } - fun constructStatics(staticFields: Set): Map = - staticFields.associateWith { fieldId -> + fun constructStatics( + stateBefore: EnvironmentModels, + staticFields: Map> + ): Map = + staticFields.keys.associateWith { fieldId -> fieldId.jField.run { val computedValue = withAccessibility { get(null) } - constructor.construct(computedValue, fieldId.type) + val knownModel = stateBefore.statics[fieldId] + val knownValue = staticFields[fieldId]?.value + if (knownModel != null && knownValue != null && knownValue == computedValue) { + knownModel + } else { + constructor.construct(computedValue, fieldId.type) + } } }