Skip to content

Commit f6419ee

Browse files
committed
Fixed behavior to match tests
1 parent 66761f6 commit f6419ee

File tree

4 files changed

+17
-15
lines changed

4 files changed

+17
-15
lines changed

utbot-framework-api/src/main/kotlin/org/utbot/framework/plugin/api/Api.kt

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -519,20 +519,13 @@ data class UtDirectSetFieldModel(
519519
val fieldId: FieldId,
520520
val fieldModel: UtModel,
521521
) : UtStatementModel(instance) {
522-
private val fieldName
523-
get() =
524-
if (instance.classId == fieldId.declaringClass)
525-
"${instance.modelName}.${fieldId.name}"
526-
else
527-
"${instance.modelName}.(${fieldId.declaringClass.name})${fieldId.name}"
528-
529522

530523
override fun toString(): String = withToStringThreadLocalReentrancyGuard {
531524
val modelRepresentation = when (fieldModel) {
532525
is UtAssembleModel -> fieldModel.modelName
533526
else -> fieldModel.toString()
534527
}
535-
"$fieldName = $modelRepresentation"
528+
"${instance.modelName}.${fieldId.name} = $modelRepresentation"
536529
}
537530

538531
}
@@ -813,6 +806,9 @@ enum class FieldIdStrategyValues {
813806
*/
814807
open class FieldId(val declaringClass: ClassId, val name: String) {
815808

809+
init {
810+
//assert(declaringClass.jClass.declaredFields.any { it.name == name })
811+
}
816812
object Strategy {
817813
var value: FieldIdStrategyValues = FieldIdStrategyValues.Soot
818814
}

utbot-framework-api/src/main/kotlin/org/utbot/framework/plugin/api/util/IdUtil.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,11 @@ val ClassId.isIterableOrMap: Boolean
288288
fun ClassId.fieldOrNull(fieldId: FieldId): Field? {
289289
if (this.isNotSubtypeOf(fieldId.declaringClass))
290290
return null
291-
return fieldId.field
291+
return try {
292+
fieldId.field
293+
} catch (e: Exception) {
294+
null
295+
}
292296
}
293297

294298
fun ClassId.hasField(fieldId: FieldId): Boolean = fieldOrNull(fieldId) != null

utbot-framework/src/main/kotlin/org/utbot/engine/Hierarchy.kt

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,14 @@ class Hierarchy(private val typeRegistry: TypeRegistry) {
3030
val realType = typeRegistry.findRealType(type) as RefType
3131

3232

33-
val ancestorType = field.declaringClass
34-
//val ancestorType = ancestors(realType.sootClass.id).firstOrNull { it.declaresField(field.subSignature) }?.type
35-
//?: error("No such field ${field.subSignature} found in ${realType.sootClass.name}")
33+
/*val ancestorType = field.declaringClass
34+
val ancestorType2 = ancestors(realType.sootClass.id).firstOrNull { it.declaresField(field.subSignature) }?.type
35+
?: error("No such field ${field.subSignature} found in ${realType.sootClass.name}")*/
36+
val ancestorType = if (field.declaringClass in ancestors(realType.sootClass.id))
37+
field.declaringClass
38+
else
39+
ancestors(realType.sootClass.id).firstOrNull { it.declaresField(field.subSignature) }?.type
40+
?: error("No such field ${field.subSignature} found in ${realType.sootClass.name}")
3641
return ChunkId("$ancestorType", field.name)
3742
}
3843

utbot-framework/src/test/kotlin/org/utbot/examples/objects/HiddenFieldExampleTest.kt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import org.junit.jupiter.api.Test
77

88
internal class HiddenFieldExampleTest : UtValueTestCaseChecker(testClass = HiddenFieldExample::class) {
99
@Test
10-
// Engine creates HiddenFieldSuccClass instead of HiddenFieldSuperClass, feels wrong field and matchers fail
1110
fun testCheckHiddenField() {
1211
check(
1312
HiddenFieldExample::checkHiddenField,
@@ -21,8 +20,6 @@ internal class HiddenFieldExampleTest : UtValueTestCaseChecker(testClass = Hidde
2120
}
2221

2322
@Test
24-
//@Disabled("SAT-315 Engine cannot work with hidden fields")
25-
// Engine translates calls to super.b as calls to succ.b
2623
fun testCheckSuccField() {
2724
check(
2825
HiddenFieldExample::checkSuccField,

0 commit comments

Comments
 (0)