Skip to content

Commit ab0a529

Browse files
committed
Replace generics with bounds when converting to ut models
1 parent e8a30d7 commit ab0a529

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

utbot-junit-contest/src/main/kotlin/org/utbot/contest/usvm/ConverterUtils.kt

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,25 @@
11
package org.utbot.contest.usvm
22

33
import org.jacodb.analysis.library.analyzers.thisInstance
4+
import org.jacodb.api.JcArrayType
45
import org.jacodb.api.JcClassOrInterface
56
import org.jacodb.api.JcClasspath
67
import org.jacodb.api.JcField
78
import org.jacodb.api.JcMethod
89
import org.jacodb.api.JcPrimitiveType
10+
import org.jacodb.api.JcRefType
911
import org.jacodb.api.JcType
1012
import org.jacodb.api.TypeName
1113
import org.jacodb.api.ext.boolean
1214
import org.jacodb.api.ext.byte
1315
import org.jacodb.api.ext.char
1416
import org.jacodb.api.ext.double
15-
import org.jacodb.api.ext.findClassOrNull
1617
import org.jacodb.api.ext.float
1718
import org.jacodb.api.ext.int
1819
import org.jacodb.api.ext.long
1920
import org.jacodb.api.ext.short
2021
import org.jacodb.api.ext.void
22+
import org.jacodb.api.ext.toType
2123
import org.usvm.instrumentation.testcase.api.UTestInst
2224
import org.usvm.instrumentation.testcase.descriptor.UTestObjectDescriptor
2325
import org.usvm.instrumentation.testcase.descriptor.UTestValueDescriptor
@@ -37,7 +39,6 @@ import org.utbot.framework.plugin.api.util.floatClassId
3739
import org.utbot.framework.plugin.api.util.id
3840
import org.utbot.framework.plugin.api.util.intClassId
3941
import org.utbot.framework.plugin.api.util.longClassId
40-
import org.utbot.framework.plugin.api.util.objectClassId
4142
import org.utbot.framework.plugin.api.util.shortClassId
4243
import org.utbot.framework.plugin.api.util.utContext
4344
import org.utbot.framework.plugin.api.util.voidClassId
@@ -55,10 +56,18 @@ fun JcMethod.toExecutableId(classpath: JcClasspath): ExecutableId {
5556
return MethodId(type, this.name, returnClassId, parameters)
5657
}
5758

59+
private fun JcType.replaceToBoundIfGeneric(): JcType {
60+
return when (this) {
61+
is JcArrayType -> this.classpath.arrayTypeOf(elementType.replaceToBoundIfGeneric())
62+
is JcRefType -> this.jcClass.toType()
63+
else -> this
64+
}
65+
}
66+
5867
val JcType?.classId: ClassId
5968
get() {
6069
if (this !is JcPrimitiveType) {
61-
return this?.toJavaClass(utContext.classLoader)?.id
70+
return this?.replaceToBoundIfGeneric()?.toJavaClass(utContext.classLoader)?.id
6271
?: error("Can not construct classId for $this")
6372
}
6473

0 commit comments

Comments
 (0)