Skip to content

Commit 275697c

Browse files
committed
Additional work
1 parent a2ee3b4 commit 275697c

File tree

5 files changed

+203
-167
lines changed

5 files changed

+203
-167
lines changed

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -685,10 +685,6 @@ open class ClassId(
685685
open val isSynthetic: Boolean
686686
get() = jClass.isSynthetic
687687

688-
// open val isNullable: Boolean
689-
// // Treat simple class ids as non-nullable
690-
// get() = false
691-
692688
/**
693689
* Collects all declared methods (including private and protected) from class and all its superclasses to sequence
694690
*/

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,21 @@ val idToPrimitive: Map<ClassId, Class<*>> = mapOf(
236236
*/
237237
fun isPrimitiveWrapperOrString(type: ClassId): Boolean = (type in primitiveWrappers) || (type == stringClassId)
238238

239+
/**
240+
* Returns a wrapper of a given type if it is primitive or a type itself otherwise.
241+
*/
242+
fun wrapIfPrimitive(type: ClassId): ClassId = when (type) {
243+
booleanClassId -> booleanWrapperClassId
244+
byteClassId -> byteWrapperClassId
245+
charClassId -> charWrapperClassId
246+
shortClassId -> shortWrapperClassId
247+
intClassId -> intWrapperClassId
248+
longClassId -> longWrapperClassId
249+
floatClassId -> floatWrapperClassId
250+
doubleClassId -> doubleWrapperClassId
251+
else -> type
252+
}
253+
239254
/**
240255
* Note: currently uses class$innerClass form to load classes with classloader.
241256
*/
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package org.utbot.framework.assemble
2+
3+
import org.utbot.framework.plugin.api.UtAssembleModel
4+
import org.utbot.framework.plugin.api.UtExecutableCallModel
5+
import org.utbot.framework.plugin.api.UtPrimitiveModel
6+
import org.utbot.framework.plugin.api.util.booleanClassId
7+
import org.utbot.framework.plugin.api.util.charClassId
8+
import org.utbot.framework.plugin.api.util.doubleClassId
9+
import org.utbot.framework.plugin.api.util.executableId
10+
import org.utbot.framework.plugin.api.util.floatClassId
11+
import org.utbot.framework.plugin.api.util.intClassId
12+
import org.utbot.framework.plugin.api.util.longClassId
13+
import org.utbot.framework.plugin.api.util.shortClassId
14+
import org.utbot.framework.plugin.api.util.wrapIfPrimitive
15+
16+
/**
17+
* Creates [UtAssembleModel] of the wrapper for a given [UtPrimitiveModel].
18+
*/
19+
fun assemble(model: UtPrimitiveModel): UtAssembleModel {
20+
val modelType = model.classId
21+
val assembledModelType = wrapIfPrimitive(modelType)
22+
23+
val constructorCall = when (modelType) {
24+
shortClassId -> java.lang.Short::class.java.getConstructor(Short::class.java)
25+
intClassId -> java.lang.Integer::class.java.getConstructor(Int::class.java)
26+
longClassId -> java.lang.Long::class.java.getConstructor(Long::class.java)
27+
charClassId -> java.lang.Character::class.java.getConstructor(Char::class.java)
28+
booleanClassId -> java.lang.Boolean::class.java.getConstructor(Boolean::class.java)
29+
floatClassId -> java.lang.Float::class.java.getConstructor(Float::class.java)
30+
doubleClassId -> java.lang.Double::class.java.getConstructor(Double::class.java)
31+
else -> error("Model type $modelType is void or non-primitive")
32+
}
33+
34+
val constructorCallModel = UtExecutableCallModel(
35+
instance = null,
36+
executable = constructorCall.executableId,
37+
params = listOf(model),
38+
returnValue = null,
39+
)
40+
41+
return UtAssembleModel(
42+
id = null,
43+
classId = assembledModelType,
44+
modelName = modelType.canonicalName,
45+
instantiationChain = listOf(constructorCallModel),
46+
modificationsChain = emptyList(),
47+
)
48+
}

0 commit comments

Comments
 (0)