Skip to content

Commit 3fdfa9b

Browse files
committed
Introduce value replacement for common collection types in UtModelConstructor
1 parent 4ac94c6 commit 3fdfa9b

File tree

1 file changed

+18
-4
lines changed
  • utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/execution/constructors

1 file changed

+18
-4
lines changed

utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/execution/constructors/UtModelConstructor.kt

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,10 @@ class UtModelConstructor(
113113
is Long,
114114
is Float,
115115
is Double,
116-
is Boolean -> if (classId.isPrimitive) UtPrimitiveModel(value) else constructFromAny(value, remainingDepth)
116+
is Boolean -> {
117+
if (classId.isPrimitive) UtPrimitiveModel(value)
118+
else constructFromAny(value, classId, remainingDepth)
119+
}
117120

118121
is ByteArray -> constructFromByteArray(value, remainingDepth)
119122
is ShortArray -> constructFromShortArray(value, remainingDepth)
@@ -127,7 +130,7 @@ class UtModelConstructor(
127130
is Enum<*> -> constructFromEnum(value)
128131
is Class<*> -> constructFromClass(value)
129132
is BaseStream<*, *> -> constructFromStream(value)
130-
else -> constructFromAny(value, remainingDepth)
133+
else -> constructFromAny(value, classId, remainingDepth)
131134
}
132135
}
133136

@@ -287,11 +290,22 @@ class UtModelConstructor(
287290
/**
288291
* First tries to construct UtAssembleModel. If failure, constructs UtCompositeModel.
289292
*/
290-
private fun constructFromAny(value: Any, remainingDepth: Long): UtModel =
293+
private fun constructFromAny(value: Any, classId: ClassId, remainingDepth: Long): UtModel =
291294
constructedObjects.getOrElse(value) {
292-
tryConstructCustomModel(value, remainingDepth) ?: constructCompositeModel(value, remainingDepth)
295+
tryConstructCustomModel(value, remainingDepth)
296+
?: findEqualValueOfWellKnownType(value)
297+
?.takeIf { classId.jClass.isInstance(it) }
298+
?.let { tryConstructCustomModel(it, remainingDepth) }
299+
?: constructCompositeModel(value, remainingDepth)
293300
}
294301

302+
private fun findEqualValueOfWellKnownType(value: Any): Any? = when (value) {
303+
is List<*> -> ArrayList(value)
304+
is Set<*> -> LinkedHashSet(value)
305+
is Map<*, *> -> LinkedHashMap(value)
306+
else -> null
307+
}
308+
295309
/**
296310
* Constructs custom UtModel but does it only for predefined list of classes.
297311
*

0 commit comments

Comments
 (0)