File tree Expand file tree Collapse file tree 2 files changed +15
-14
lines changed
utbot-framework/src/main/kotlin/org/utbot/framework/codegen/model/constructor Expand file tree Collapse file tree 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
5555import kotlinx.collections.immutable.persistentMapOf
5656import kotlinx.collections.immutable.persistentSetOf
5757import org.utbot.framework.codegen.model.constructor.builtin.streamsDeepEqualsMethodId
58+ import org.utbot.framework.plugin.api.util.isSubtypeOf
5859
5960/* *
6061 * Interface for all code generation context aware entities
@@ -232,7 +233,14 @@ internal interface CgContextOwner {
232233 currentExecutable = method.callable.executableId
233234 }
234235
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+
236244 if (collectedExceptions.add(exception)) {
237245 importIfNeeded(exception)
238246 }
@@ -416,9 +424,9 @@ internal data class CgContext(
416424 val simpleName = testClassCustomName ? : " ${createTestClassName(classUnderTest.name)} Test"
417425 val name = " $packagePrefix$simpleName "
418426 BuiltinClassId (
419- name = name,
420- canonicalName = name,
421- simpleName = simpleName
427+ name = name,
428+ canonicalName = name,
429+ simpleName = simpleName
422430 )
423431 }
424432
Original file line number Diff line number Diff line change @@ -127,14 +127,7 @@ internal class CgCallableAccessManagerImpl(val context: CgContext) : CgCallableA
127127 // Builtin methods does not have jClass, so [methodId.method] will crash on it,
128128 // so we need to collect required exceptions manually from source codes
129129 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) }
138131 return
139132 }
140133
@@ -148,13 +141,13 @@ internal class CgCallableAccessManagerImpl(val context: CgContext) : CgCallableA
148141 return
149142 }
150143
151- methodId.method.exceptionTypes.forEach { addException (it.id) }
144+ methodId.method.exceptionTypes.forEach { addExceptionIfNeeded (it.id) }
152145 }
153146
154147 private fun newConstructorCall (constructorId : ConstructorId ) {
155148 importIfNeeded(constructorId.classId)
156149 for (exception in constructorId.exceptions) {
157- addException (exception)
150+ addExceptionIfNeeded (exception)
158151 }
159152 }
160153
You can’t perform that action at this time.
0 commit comments