@@ -46,7 +46,6 @@ import org.utbot.framework.plugin.api.UtMethod
46
46
import org.utbot.framework.plugin.api.UtModel
47
47
import org.utbot.framework.plugin.api.UtReferenceModel
48
48
import org.utbot.framework.plugin.api.UtTestCase
49
- import org.utbot.framework.plugin.api.util.executableId
50
49
import java.util.IdentityHashMap
51
50
import kotlinx.collections.immutable.PersistentList
52
51
import kotlinx.collections.immutable.PersistentMap
@@ -55,6 +54,11 @@ import kotlinx.collections.immutable.persistentListOf
55
54
import kotlinx.collections.immutable.persistentMapOf
56
55
import kotlinx.collections.immutable.persistentSetOf
57
56
import org.utbot.framework.codegen.model.constructor.builtin.streamsDeepEqualsMethodId
57
+ import org.utbot.framework.plugin.api.util.isSubtypeOf
58
+ import org.utbot.framework.plugin.api.util.isNotSubtypeOf
59
+ import org.utbot.framework.plugin.api.util.isCheckedException
60
+ import org.utbot.framework.plugin.api.util.id
61
+ import org.utbot.framework.plugin.api.util.executableId
58
62
59
63
/* *
60
64
* Interface for all code generation context aware entities
@@ -232,7 +236,25 @@ internal interface CgContextOwner {
232
236
currentExecutable = method.callable.executableId
233
237
}
234
238
235
- fun addException (exception : ClassId ) {
239
+ fun addExceptionIfNeeded (exception : ClassId ) {
240
+ when (exception) {
241
+ is BuiltinClassId -> {}
242
+ else -> {
243
+ if (exception isNotSubtypeOf Throwable ::class .id) {
244
+ error(" Class $exception which is not a Throwable was passed" )
245
+ }
246
+
247
+ val isUnchecked = ! exception.isCheckedException
248
+ val alreadyAdded =
249
+ collectedExceptions.any { existingException -> exception isSubtypeOf existingException }
250
+
251
+ if (isUnchecked || alreadyAdded) return
252
+
253
+ collectedExceptions
254
+ .removeIf { existingException -> existingException isSubtypeOf exception }
255
+ }
256
+ }
257
+
236
258
if (collectedExceptions.add(exception)) {
237
259
importIfNeeded(exception)
238
260
}
@@ -416,9 +438,9 @@ internal data class CgContext(
416
438
val simpleName = testClassCustomName ? : " ${createTestClassName(classUnderTest.name)} Test"
417
439
val name = " $packagePrefix$simpleName "
418
440
BuiltinClassId (
419
- name = name,
420
- canonicalName = name,
421
- simpleName = simpleName
441
+ name = name,
442
+ canonicalName = name,
443
+ simpleName = simpleName
422
444
)
423
445
}
424
446
0 commit comments