File tree 2 files changed +15
-14
lines changed
utbot-framework/src/main/kotlin/org/utbot/framework/codegen/model/constructor
2 files changed +15
-14
lines changed Original file line number Diff line number Diff line change @@ -55,6 +55,7 @@ import kotlinx.collections.immutable.persistentListOf
55
55
import kotlinx.collections.immutable.persistentMapOf
56
56
import kotlinx.collections.immutable.persistentSetOf
57
57
import org.utbot.framework.codegen.model.constructor.builtin.streamsDeepEqualsMethodId
58
+ import org.utbot.framework.plugin.api.util.isSubtypeOf
58
59
59
60
/* *
60
61
* Interface for all code generation context aware entities
@@ -232,7 +233,14 @@ internal interface CgContextOwner {
232
233
currentExecutable = method.callable.executableId
233
234
}
234
235
235
- fun addException (exception : ClassId ) {
236
+ fun addExceptionIfNeeded (exception : ClassId ) {
237
+ collectedExceptions.forEach {
238
+ if (it isSubtypeOf exception) return
239
+ }
240
+ collectedExceptions.forEach {
241
+ if (exception isSubtypeOf it) collectedExceptions.remove(it)
242
+ }
243
+
236
244
if (collectedExceptions.add(exception)) {
237
245
importIfNeeded(exception)
238
246
}
@@ -416,9 +424,9 @@ internal data class CgContext(
416
424
val simpleName = testClassCustomName ? : " ${createTestClassName(classUnderTest.name)} Test"
417
425
val name = " $packagePrefix$simpleName "
418
426
BuiltinClassId (
419
- name = name,
420
- canonicalName = name,
421
- simpleName = simpleName
427
+ name = name,
428
+ canonicalName = name,
429
+ simpleName = simpleName
422
430
)
423
431
}
424
432
Original file line number Diff line number Diff line change @@ -127,14 +127,7 @@ internal class CgCallableAccessManagerImpl(val context: CgContext) : CgCallableA
127
127
// Builtin methods does not have jClass, so [methodId.method] will crash on it,
128
128
// so we need to collect required exceptions manually from source codes
129
129
if (methodId is BuiltinMethodId ) {
130
- methodId.findExceptionTypes().forEach { addException(it) }
131
- return
132
- }
133
- // If [InvocationTargetException] is thrown manually in test, we need
134
- // to add "throws Throwable" and other exceptions are not required so on.
135
- if (methodId == getTargetException) {
136
- collectedExceptions.clear()
137
- addException(Throwable ::class .id)
130
+ methodId.findExceptionTypes().forEach { addExceptionIfNeeded(it) }
138
131
return
139
132
}
140
133
@@ -148,13 +141,13 @@ internal class CgCallableAccessManagerImpl(val context: CgContext) : CgCallableA
148
141
return
149
142
}
150
143
151
- methodId.method.exceptionTypes.forEach { addException (it.id) }
144
+ methodId.method.exceptionTypes.forEach { addExceptionIfNeeded (it.id) }
152
145
}
153
146
154
147
private fun newConstructorCall (constructorId : ConstructorId ) {
155
148
importIfNeeded(constructorId.classId)
156
149
for (exception in constructorId.exceptions) {
157
- addException (exception)
150
+ addExceptionIfNeeded (exception)
158
151
}
159
152
}
160
153
You can’t perform that action at this time.
0 commit comments