Skip to content

Commit 2583bd8

Browse files
committed
Fixed Hierarchy.chunkIdForField & minor changes
1 parent f6419ee commit 2583bd8

File tree

3 files changed

+5
-14
lines changed
  • utbot-framework/src/main/kotlin/org/utbot/engine
  • utbot-framework-api/src/main/kotlin/org/utbot/framework/plugin/api

3 files changed

+5
-14
lines changed

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -806,9 +806,6 @@ enum class FieldIdStrategyValues {
806806
*/
807807
open class FieldId(val declaringClass: ClassId, val name: String) {
808808

809-
init {
810-
//assert(declaringClass.jClass.declaredFields.any { it.name == name })
811-
}
812809
object Strategy {
813810
var value: FieldIdStrategyValues = FieldIdStrategyValues.Soot
814811
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ fun ClassId.fieldOrNull(fieldId: FieldId): Field? {
290290
return null
291291
return try {
292292
fieldId.field
293-
} catch (e: Exception) {
293+
} catch (e: IllegalStateException) {
294294
null
295295
}
296296
}

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

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,11 @@ class Hierarchy(private val typeRegistry: TypeRegistry) {
2828
type as? RefType ?: error("$type is not a refType")
2929

3030
val realType = typeRegistry.findRealType(type) as RefType
31+
val realFieldDeclaringClass = typeRegistry.findRealType(field.declaringClass.type) as RefType
3132

32-
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}")
41-
return ChunkId("$ancestorType", field.name)
33+
if (realFieldDeclaringClass.sootClass !in ancestors(realType.sootClass.id))
34+
error("No such field ${field.subSignature} found in ${realType.sootClass.name}")
35+
return ChunkId("$realFieldDeclaringClass", field.name)
4236
}
4337

4438
/**

0 commit comments

Comments
 (0)