@@ -2,13 +2,20 @@ package api
22
33import framework.api.js.JsClassId
44import framework.api.js.JsEmptyClassId
5+ import framework.api.js.JsMethodId
56import framework.api.js.JsNullModel
67import framework.api.js.JsPrimitiveModel
78import framework.api.js.JsUndefinedModel
9+ import framework.api.js.util.defaultJsValueModel
10+ import framework.api.js.util.isJsArray
11+ import framework.api.js.util.isJsMap
12+ import framework.api.js.util.isJsSet
813import framework.api.js.util.jsErrorClassId
914import framework.api.js.util.jsUndefinedClassId
1015import fuzzer.JsIdProvider
1116import org.utbot.framework.plugin.api.ClassId
17+ import org.utbot.framework.plugin.api.ConstructorId
18+ import org.utbot.framework.plugin.api.UtArrayModel
1219import org.utbot.framework.plugin.api.UtAssembleModel
1320import org.utbot.framework.plugin.api.UtExecutableCallModel
1421import org.utbot.framework.plugin.api.UtModel
@@ -20,10 +27,7 @@ class JsUtModelConstructor : UtModelConstructorInterface {
2027 @Suppress(" NAME_SHADOWING" )
2128 override fun construct (value : Any? , classId : ClassId ): UtModel {
2229 val classId = classId as JsClassId
23- when (classId) {
24- jsUndefinedClassId -> return JsUndefinedModel (classId)
25- jsErrorClassId -> return UtModel (jsErrorClassId)
26- }
30+ if (classId == jsErrorClassId) return UtModel (jsErrorClassId)
2731 return when (value) {
2832 null -> JsNullModel (classId)
2933 is Byte ,
@@ -35,7 +39,9 @@ class JsUtModelConstructor : UtModelConstructorInterface {
3539 is Double ,
3640 is String ,
3741 is Boolean -> JsPrimitiveModel (value)
38-
42+ is List <* > -> {
43+ constructStructure(classId, value)
44+ }
3945 is Map <* , * > -> {
4046 constructObject(classId, value)
4147 }
@@ -44,6 +50,79 @@ class JsUtModelConstructor : UtModelConstructorInterface {
4450 }
4551 }
4652
53+ private fun constructStructure (classId : JsClassId , values : List <Any ?>): UtModel {
54+ return when {
55+ classId.isJsSet -> {
56+ UtAssembleModel (
57+ id = JsIdProvider .createId(),
58+ classId = classId,
59+ modelName = " " ,
60+ instantiationCall = UtExecutableCallModel (
61+ null ,
62+ ConstructorId (classId, emptyList()),
63+ emptyList()
64+ ),
65+ modificationsChainProvider = { mutableListOf () }
66+ ).apply {
67+ this .modificationsChain as MutableList + = values.map { value ->
68+ UtExecutableCallModel (
69+ this ,
70+ JsMethodId (
71+ classId = classId,
72+ name = " add" ,
73+ returnTypeNotLazy = jsUndefinedClassId,
74+ parametersNotLazy = listOf (jsUndefinedClassId)
75+ ),
76+ listOf (construct(value, jsUndefinedClassId))
77+ )
78+ }
79+ }
80+ }
81+ classId.isJsArray -> {
82+ UtArrayModel (
83+ id = JsIdProvider .createId(),
84+ classId = classId,
85+ stores = buildMap {
86+ putAll(values.indices.zip(values.map {
87+ construct(it, jsUndefinedClassId)
88+ }))
89+ } as MutableMap <Int , UtModel >,
90+ length = values.size,
91+ constModel = jsUndefinedClassId.defaultJsValueModel()
92+ )
93+ }
94+ classId.isJsMap -> {
95+ UtAssembleModel (
96+ id = JsIdProvider .createId(),
97+ classId = classId,
98+ modelName = " " ,
99+ instantiationCall = UtExecutableCallModel (
100+ null ,
101+ ConstructorId (classId, emptyList()),
102+ emptyList()
103+ ),
104+ modificationsChainProvider = { mutableListOf () }
105+ ).apply {
106+ this .modificationsChain as MutableList + = values.map { value ->
107+ UtExecutableCallModel (
108+ this ,
109+ JsMethodId (
110+ classId = classId,
111+ name = " set" ,
112+ returnTypeNotLazy = jsUndefinedClassId,
113+ parametersNotLazy = listOf (jsUndefinedClassId, jsUndefinedClassId)
114+ ),
115+ (value as Pair <Any ?, Any ?>).toList().map { construct(it, jsUndefinedClassId) }
116+ )
117+ }
118+ }
119+ }
120+ else -> throw UnsupportedOperationException (
121+ " Can't make UtModel from JavaScript structure with ${classId.name} type"
122+ )
123+ }
124+ }
125+
47126 @Suppress(" UNCHECKED_CAST" )
48127 private fun constructObject (classId : JsClassId , value : Any? ): UtModel {
49128 val constructor = classId.allConstructors.first()
0 commit comments