@@ -5,25 +5,9 @@ import org.utbot.framework.codegen.Junit5
5
5
import org.utbot.framework.codegen.TestNg
6
6
import org.utbot.framework.codegen.model.constructor.builtin.any
7
7
import org.utbot.framework.codegen.model.constructor.builtin.anyOfClass
8
- import org.utbot.framework.codegen.model.constructor.builtin.arraysDeepEqualsMethodId
9
- import org.utbot.framework.codegen.model.constructor.builtin.buildLambdaMethodId
10
- import org.utbot.framework.codegen.model.constructor.builtin.buildStaticLambdaMethodId
11
- import org.utbot.framework.codegen.model.constructor.builtin.createArrayMethodId
12
- import org.utbot.framework.codegen.model.constructor.builtin.createInstanceMethodId
13
- import org.utbot.framework.codegen.model.constructor.builtin.deepEqualsMethodId
14
8
import org.utbot.framework.codegen.model.constructor.builtin.forName
15
- import org.utbot.framework.codegen.model.constructor.builtin.getArrayLengthMethodId
16
- import org.utbot.framework.codegen.model.constructor.builtin.getLambdaCapturedArgumentValuesMethodId
17
9
import org.utbot.framework.codegen.model.constructor.builtin.getDeclaredConstructor
18
10
import org.utbot.framework.codegen.model.constructor.builtin.getDeclaredMethod
19
- import org.utbot.framework.codegen.model.constructor.builtin.getEnumConstantByNameMethodId
20
- import org.utbot.framework.codegen.model.constructor.builtin.getFieldValueMethodId
21
- import org.utbot.framework.codegen.model.constructor.builtin.getInstantiatedMethodTypeMethodId
22
- import org.utbot.framework.codegen.model.constructor.builtin.getLambdaCapturedArgumentTypesMethodId
23
- import org.utbot.framework.codegen.model.constructor.builtin.getLambdaMethodMethodId
24
- import org.utbot.framework.codegen.model.constructor.builtin.getLookupInMethodId
25
- import org.utbot.framework.codegen.model.constructor.builtin.getSingleAbstractMethodMethodId
26
- import org.utbot.framework.codegen.model.constructor.builtin.getStaticFieldValueMethodId
27
11
import org.utbot.framework.codegen.model.constructor.builtin.getTargetException
28
12
import org.utbot.framework.codegen.model.constructor.builtin.invoke
29
13
import org.utbot.framework.codegen.model.constructor.builtin.newInstance
@@ -130,7 +114,7 @@ internal class CgCallableAccessManagerImpl(val context: CgContext) : CgCallableA
130
114
// Builtin methods does not have jClass, so [methodId.method] will crash on it,
131
115
// so we need to collect required exceptions manually from source codes
132
116
if (methodId is BuiltinMethodId ) {
133
- findExceptionTypesOf( methodId)
117
+ methodId.findExceptionTypes( )
134
118
.forEach { addExceptionIfNeeded(it) }
135
119
return
136
120
}
@@ -168,51 +152,6 @@ internal class CgCallableAccessManagerImpl(val context: CgContext) : CgCallableA
168
152
}
169
153
}
170
154
171
- private fun BuiltinConstructorId.findExceptionTypes (): Set <ClassId > {
172
- // At the moment we do not have builtin ids for constructors that throw exceptions,
173
- // so we have this trivial when-expression. But if we ever add ids for such constructors,
174
- // then we **must** specify their exceptions here, so that we take them into account when generating code.
175
- @Suppress(" UNUSED_EXPRESSION" )
176
- return when (this ) {
177
- else -> emptySet()
178
- }
179
- }
180
-
181
- // WARN: if you make changes in the following sets of exceptions,
182
- // don't forget to change them in hardcoded [UtilMethods] as well
183
- private fun BuiltinMethodId.findExceptionTypes (): Set <ClassId > {
184
- if (! this .isUtil) return emptySet()
185
-
186
- with (outerMostTestClass) {
187
- return when (this @findExceptionTypes) {
188
- getEnumConstantByNameMethodId -> setOf (IllegalAccessException ::class .id)
189
- getStaticFieldValueMethodId,
190
- getFieldValueMethodId,
191
- setStaticFieldMethodId,
192
- setFieldMethodId -> setOf (IllegalAccessException ::class .id, NoSuchFieldException ::class .id)
193
- createInstanceMethodId -> setOf (Exception ::class .id)
194
- getUnsafeInstanceMethodId -> setOf (ClassNotFoundException ::class .id, NoSuchFieldException ::class .id, IllegalAccessException ::class .id)
195
- createArrayMethodId -> setOf (ClassNotFoundException ::class .id)
196
- deepEqualsMethodId,
197
- arraysDeepEqualsMethodId,
198
- iterablesDeepEqualsMethodId,
199
- streamsDeepEqualsMethodId,
200
- mapsDeepEqualsMethodId,
201
- hasCustomEqualsMethodId,
202
- getArrayLengthMethodId,
203
- getLambdaCapturedArgumentTypesMethodId,
204
- getLambdaCapturedArgumentValuesMethodId,
205
- getInstantiatedMethodTypeMethodId,
206
- getLambdaMethodMethodId,
207
- getSingleAbstractMethodMethodId -> emptySet()
208
- buildStaticLambdaMethodId,
209
- buildLambdaMethodId -> setOf (Throwable ::class .id)
210
- getLookupInMethodId -> setOf (IllegalAccessException ::class .id, NoSuchFieldException ::class .id)
211
- else -> error(" Unknown util method ${this @findExceptionTypes} " )
212
- }
213
- }
214
- }
215
-
216
155
private infix fun CgExpression?.canBeReceiverOf (executable : MethodId ): Boolean =
217
156
when {
218
157
// TODO: rewrite by using CgMethodId, etc.
@@ -436,33 +375,51 @@ internal class CgCallableAccessManagerImpl(val context: CgContext) : CgCallableA
436
375
return argumentsArrayVariable
437
376
}
438
377
378
+ private fun BuiltinConstructorId.findExceptionTypes (): Set <ClassId > {
379
+ // At the moment we do not have builtin ids for constructors that throw exceptions,
380
+ // so we have this trivial when-expression. But if we ever add ids for such constructors,
381
+ // then we **must** specify their exceptions here, so that we take them into account when generating code.
382
+ @Suppress(" UNUSED_EXPRESSION" )
383
+ return when (this ) {
384
+ else -> emptySet()
385
+ }
386
+ }
387
+
439
388
// WARN: if you make changes in the following sets of exceptions,
440
389
// don't forget to change them in hardcoded [UtilMethods] as well
441
- private fun findExceptionTypesOf ( methodId : MethodId ): Set <ClassId > {
390
+ private fun BuiltinMethodId. findExceptionTypes ( ): Set <ClassId > {
442
391
// TODO: at the moment we treat BuiltinMethodIds that are not util method ids
443
392
// as if they have no exceptions. This should be fixed by storing exception types in BuiltinMethodId
444
393
// or allowing us to access actual java.lang.Class for classes from mockito and other libraries
445
394
// (this could be possibly solved by using user project's class loaders in UtContext)
446
- if (methodId !in utilMethodProvider.utilMethodIds ) return emptySet()
395
+ if (! isUtil( this ) ) return emptySet()
447
396
448
397
with (utilMethodProvider) {
449
- return when (methodId ) {
450
- getEnumConstantByNameMethodId -> setOf (java.lang. IllegalAccessException ::class .id)
398
+ return when (this @findExceptionTypes ) {
399
+ getEnumConstantByNameMethodId -> setOf (IllegalAccessException ::class .id)
451
400
getStaticFieldValueMethodId,
452
401
getFieldValueMethodId,
453
402
setStaticFieldMethodId,
454
- setFieldMethodId -> setOf (java.lang. IllegalAccessException ::class .id, java.lang. NoSuchFieldException ::class .id)
403
+ setFieldMethodId -> setOf (IllegalAccessException ::class .id, NoSuchFieldException ::class .id)
455
404
createInstanceMethodId -> setOf (Exception ::class .id)
456
- getUnsafeInstanceMethodId -> setOf (java.lang. ClassNotFoundException ::class .id, java.lang. NoSuchFieldException ::class .id, java.lang. IllegalAccessException ::class .id)
457
- createArrayMethodId -> setOf (java.lang. ClassNotFoundException ::class .id)
405
+ getUnsafeInstanceMethodId -> setOf (ClassNotFoundException ::class .id, NoSuchFieldException ::class .id, IllegalAccessException ::class .id)
406
+ createArrayMethodId -> setOf (ClassNotFoundException ::class .id)
458
407
deepEqualsMethodId,
459
408
arraysDeepEqualsMethodId,
460
409
iterablesDeepEqualsMethodId,
461
410
streamsDeepEqualsMethodId,
462
411
mapsDeepEqualsMethodId,
463
412
hasCustomEqualsMethodId,
464
- getArrayLengthMethodId -> emptySet()
465
- else -> error(" Unknown util method $this " )
413
+ getArrayLengthMethodId,
414
+ getLambdaCapturedArgumentTypesMethodId,
415
+ getLambdaCapturedArgumentValuesMethodId,
416
+ getInstantiatedMethodTypeMethodId,
417
+ getLambdaMethodMethodId,
418
+ getSingleAbstractMethodMethodId -> emptySet()
419
+ buildStaticLambdaMethodId,
420
+ buildLambdaMethodId -> setOf (Throwable ::class .id)
421
+ getLookupInMethodId -> setOf (IllegalAccessException ::class .id, NoSuchFieldException ::class .id)
422
+ else -> error(" Unknown util method ${this @findExceptionTypes} " )
466
423
}
467
424
}
468
425
}
0 commit comments