From b5786ef3a1688a5c4f9e3bcd8252114127ecc660 Mon Sep 17 00:00:00 2001 From: Egor Kulikov Date: Tue, 23 Aug 2022 15:29:59 +0300 Subject: [PATCH 1/2] Added the ClassId for ParametrizedType --- .../kotlin/org/utbot/framework/plugin/api/util/IdUtil.kt | 5 +++-- .../codegen/model/constructor/tree/CgMethodConstructor.kt | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/utbot-framework-api/src/main/kotlin/org/utbot/framework/plugin/api/util/IdUtil.kt b/utbot-framework-api/src/main/kotlin/org/utbot/framework/plugin/api/util/IdUtil.kt index c54a5a5098..e3313416d5 100644 --- a/utbot-framework-api/src/main/kotlin/org/utbot/framework/plugin/api/util/IdUtil.kt +++ b/utbot-framework-api/src/main/kotlin/org/utbot/framework/plugin/api/util/IdUtil.kt @@ -14,6 +14,7 @@ import java.lang.reflect.Constructor import java.lang.reflect.Executable import java.lang.reflect.Field import java.lang.reflect.Method +import java.lang.reflect.ParameterizedType import java.lang.reflect.Type import java.util.concurrent.atomic.AtomicInteger import kotlin.contracts.ExperimentalContracts @@ -270,8 +271,8 @@ val Class<*>.id: ClassId /** * [java.lang.reflect.ParameterizedType.getRawType] now returns [Type] instead of [Class]. */ -val Type.id: ClassId - get() = TODO("Java 11 transition") +val ParameterizedType.id: ClassId + get() = ClassId(this.rawType.typeName) val KClass<*>.id: ClassId get() = java.id diff --git a/utbot-framework/src/main/kotlin/org/utbot/framework/codegen/model/constructor/tree/CgMethodConstructor.kt b/utbot-framework/src/main/kotlin/org/utbot/framework/codegen/model/constructor/tree/CgMethodConstructor.kt index 56fe6caf80..1ab2f70fe7 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/framework/codegen/model/constructor/tree/CgMethodConstructor.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/framework/codegen/model/constructor/tree/CgMethodConstructor.kt @@ -1292,7 +1292,7 @@ internal class CgMethodConstructor(val context: CgContext) : CgContextOwner by c val argumentType = when { paramType is Class<*> && paramType.isArray -> paramType.id - paramType is ParameterizedType -> paramType.rawType.id + paramType is ParameterizedType -> paramType.id else -> ClassId(paramType.typeName) } From 9d1918bbc2f1f2053939e94be2d778b10ad8f622 Mon Sep 17 00:00:00 2001 From: Egor Kulikov Date: Tue, 23 Aug 2022 16:01:54 +0300 Subject: [PATCH 2/2] Improve documentation --- .../main/kotlin/org/utbot/framework/plugin/api/util/IdUtil.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/utbot-framework-api/src/main/kotlin/org/utbot/framework/plugin/api/util/IdUtil.kt b/utbot-framework-api/src/main/kotlin/org/utbot/framework/plugin/api/util/IdUtil.kt index e3313416d5..c758bf9bbb 100644 --- a/utbot-framework-api/src/main/kotlin/org/utbot/framework/plugin/api/util/IdUtil.kt +++ b/utbot-framework-api/src/main/kotlin/org/utbot/framework/plugin/api/util/IdUtil.kt @@ -269,7 +269,8 @@ val Class<*>.id: ClassId } /** - * [java.lang.reflect.ParameterizedType.getRawType] now returns [Type] instead of [Class]. + * We should specially handle the case of a generic type that is a [Type] and not a [Class]. + * Returns a [ClassId] for the corresponding raw type. */ val ParameterizedType.id: ClassId get() = ClassId(this.rawType.typeName)