@@ -5,9 +5,6 @@ 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.forName
9
- import org.utbot.framework.codegen.model.constructor.builtin.getDeclaredConstructor
10
- import org.utbot.framework.codegen.model.constructor.builtin.getDeclaredMethod
11
8
import org.utbot.framework.codegen.model.constructor.builtin.getMethodId
12
9
import org.utbot.framework.codegen.model.constructor.builtin.getTargetException
13
10
import org.utbot.framework.codegen.model.constructor.builtin.invoke
@@ -271,15 +268,15 @@ internal class CgCallableAccessManagerImpl(val context: CgContext) : CgCallableA
271
268
}
272
269
273
270
if (this .isStatic && caller != null && codegenLanguage == CodegenLanguage .KOTLIN ) {
274
- error(" In Kotlin, unlike Java, static methods cannot be called on an object " )
271
+ error(" In Kotlin, unlike Java, static methods cannot be called on an instance: $this " )
275
272
}
276
273
277
274
// If method is from current test class, then it may not have a caller.
278
275
if (this .classId == currentTestClass && caller == null ) {
279
276
return true
280
277
}
281
278
282
- requireNotNull(caller) { " Method must have a caller, unless it is the method of the current test class or a static method" }
279
+ requireNotNull(caller) { " Method must have a caller, unless it is the method of the current test class or a static method: $this " }
283
280
return caller canBeReceiverOf this
284
281
}
285
282
@@ -295,7 +292,7 @@ internal class CgCallableAccessManagerImpl(val context: CgContext) : CgCallableA
295
292
}
296
293
297
294
if (this .isStatic && accessor != null && codegenLanguage == CodegenLanguage .KOTLIN ) {
298
- error(" In Kotlin, unlike Java, static fields cannot be accessed by an object" )
295
+ error(" In Kotlin, unlike Java, static fields cannot be accessed by an object: $this " )
299
296
}
300
297
301
298
// if field is declared in the current test class
@@ -313,7 +310,7 @@ internal class CgCallableAccessManagerImpl(val context: CgContext) : CgCallableA
313
310
}
314
311
315
312
requireNotNull(accessor) {
316
- " Field access must have a non-null accessor, unless it is the field of the current test class or a static field"
313
+ " Field access must have a non-null accessor, unless it is the field of the current test class or a static field: $this "
317
314
}
318
315
319
316
if (this .declaringClass == accessor.type) {
@@ -359,6 +356,20 @@ internal class CgCallableAccessManagerImpl(val context: CgContext) : CgCallableA
359
356
/* *
360
357
* Check if the field represented by @receiver is hidden when accessed from an instance of [subclass].
361
358
*
359
+ * Brief description: this method collects all types from hierarchy in between [subclass] (inclusive)
360
+ * up to the class where the field is declared (exclusive) and checks if any of these classes declare
361
+ * a field with the same name (thus hiding the given field). For examples and more details read documentation below.
362
+ *
363
+ * The **contract** of this method is as follows:
364
+ * [subclass] must be a subclass of `this.declaringClass` (and they **must not** be the same class).
365
+ * That is because if they are equal (we try to access field from instance of its own class),
366
+ * then the field is not hidden. And if [subclass] is actually not a subclass, but a superclass of a class
367
+ * where the field is declared, then this check makes no sense (superclass cannot hide field of a subclass).
368
+ * Lastly, if these classes are not related in terms of inheritance, then there must be some error,
369
+ * because such checks also make no sense.
370
+ *
371
+ * **Examples**.
372
+ *
362
373
* For example, given classes:
363
374
* ```
364
375
* class A { int x; }
@@ -406,6 +417,11 @@ internal class CgCallableAccessManagerImpl(val context: CgContext) : CgCallableA
406
417
* If such field is found, then the field is hidden, otherwise - not.
407
418
*/
408
419
private infix fun FieldId.isFieldHiddenIn (subclass : Class <* >): Boolean {
420
+ // see the documentation of this method for more details on this requirement
421
+ require(subclass.id != this .declaringClass) {
422
+ " A given subclass must not be equal to the declaring class of the field: $subclass "
423
+ }
424
+
409
425
// supertypes (classes and interfaces) from subclass (inclusive) up to superclass (exclusive)
410
426
val supertypes = sequence {
411
427
var types = generateSequence(subclass) { it.superclass }
0 commit comments