Skip to content

Commit 024311d

Browse files
committed
Fix subtype check
1 parent 7e3c445 commit 024311d

File tree

2 files changed

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

2 files changed

+17
-5
lines changed

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -794,6 +794,12 @@ open class ClassId @JvmOverloads constructor(
794794
open val outerClass: Class<*>?
795795
get() = jClass.enclosingClass
796796

797+
open val superclass: Class<*>?
798+
get() = jClass.superclass
799+
800+
open val interfaces: Array<Class<*>>
801+
get() = jClass.interfaces
802+
797803
/**
798804
* For member classes returns a name including
799805
* enclosing classes' simple names e.g. `A.B`.
@@ -846,7 +852,7 @@ class BuiltinClassId(
846852
elementClassId: ClassId? = null,
847853
override val canonicalName: String,
848854
override val simpleName: String,
849-
// by default we assume that the class is not a member class
855+
// by default, we assume that the class is not a member class
850856
override val simpleNameWithEnclosings: String = simpleName,
851857
override val isNullable: Boolean = false,
852858
override val isPublic: Boolean = true,
@@ -864,6 +870,10 @@ class BuiltinClassId(
864870
override val allMethods: Sequence<MethodId> = emptySequence(),
865871
override val allConstructors: Sequence<ConstructorId> = emptySequence(),
866872
override val outerClass: Class<*>? = null,
873+
// by default, we assume that the class does not have a superclass (other than Object)
874+
override val superclass: Class<*>? = java.lang.Object::class.java,
875+
// by default, we assume that the class does not implement any interfaces
876+
override val interfaces: Array<Class<*>> = emptyArray(),
867877
override val packageName: String =
868878
when (val index = canonicalName.lastIndexOf('.')) {
869879
-1, 0 -> ""

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,17 +118,19 @@ infix fun ClassId.isSubtypeOf(type: ClassId): Boolean {
118118
if (left == right) {
119119
return true
120120
}
121-
val leftClass = this.jClass
121+
val leftClass = this
122122
val interfaces = sequence {
123123
var types = listOf(leftClass)
124124
while (types.isNotEmpty()) {
125125
yieldAll(types)
126-
types = types.map { it.interfaces }.flatMap { it.toList() }
126+
types = types
127+
.flatMap { it.interfaces.toList() }
128+
.map { it.id }
127129
}
128130
}
129-
val superclasses = generateSequence(leftClass) { it.superclass }
131+
val superclasses = generateSequence(leftClass) { it.superclass?.id }
130132
val superTypes = interfaces + superclasses
131-
return right in superTypes.map { it.id }
133+
return right in superTypes
132134
}
133135

134136
infix fun ClassId.isNotSubtypeOf(type: ClassId): Boolean = !(this isSubtypeOf type)

0 commit comments

Comments
 (0)