Skip to content

Commit

Permalink
fix statics construction
Browse files Browse the repository at this point in the history
  • Loading branch information
SBOne-Kenobi committed Dec 8, 2022
1 parent b5f40fc commit b3a8464
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ object UtExecutionInstrumentation : Instrumentation<UtConcreteExecutionResult> {
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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -58,11 +59,20 @@ class ModelConstructionContext(
constructor.construct(it.value, it.clazz.id)
}

fun constructStatics(staticFields: Set<FieldId>): Map<FieldId, UtModel> =
staticFields.associateWith { fieldId ->
fun constructStatics(
stateBefore: EnvironmentModels,
staticFields: Map<FieldId, UtConcreteValue<*>>
): Map<FieldId, UtModel> =
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)
}
}
}

Expand Down

0 comments on commit b3a8464

Please sign in to comment.