Skip to content

Commit ef45448

Browse files
committed
Introduced genericObjectClassId & applied comment fix suggestions
1 parent 8b30997 commit ef45448

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

utbot-framework/src/main/kotlin/org/utbot/framework/codegen/domain/builtin/MockitoBuiltins.kt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,14 @@ internal val stubberClassId = BuiltinClassId(
4040
simpleName = "Stubber"
4141
)
4242

43+
// We wrap an Object classId in BuiltinClassId
44+
// in order to deal with [CgExpression.canBeReceiverOf]
45+
// when we want to call ANY method on an object.
46+
internal val genericObjectClassId = BuiltinClassId(
47+
canonicalName = "java.lang.Object",
48+
simpleName = "Object"
49+
)
50+
4351
internal val answerClassId = BuiltinClassId(
4452
canonicalName = "org.mockito.stubbing.Answer",
4553
simpleName = "Answer",
@@ -97,7 +105,7 @@ internal val doNothingMethodId = builtinStaticMethodId(
97105
internal val whenStubberMethodId = builtinMethodId(
98106
classId = stubberClassId,
99107
name = "when",
100-
returnType = stubberClassId,
108+
returnType = genericObjectClassId,
101109
arguments = arrayOf(objectClassId)
102110
)
103111

utbot-framework/src/main/kotlin/org/utbot/framework/codegen/services/access/CgCallableAccessManager.kt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ import org.utbot.framework.codegen.domain.builtin.getMethodId
99
import org.utbot.framework.codegen.domain.builtin.getTargetException
1010
import org.utbot.framework.codegen.domain.builtin.invoke
1111
import org.utbot.framework.codegen.domain.builtin.newInstance
12+
import org.utbot.framework.codegen.domain.builtin.genericObjectClassId
1213
import org.utbot.framework.codegen.domain.builtin.setAccessible
13-
import org.utbot.framework.codegen.domain.builtin.stubberClassId
1414
import org.utbot.framework.codegen.domain.context.CgContext
1515
import org.utbot.framework.codegen.domain.context.CgContextOwner
1616
import org.utbot.framework.codegen.domain.models.CgAllocateArray
@@ -191,24 +191,24 @@ internal class CgCallableAccessManagerImpl(val context: CgContext) : CgCallableA
191191

192192
private infix fun CgExpression.canBeReceiverOf(executable: MethodId): Boolean =
193193
when {
194-
// method of the current test class can be called on its 'this' instance
194+
// this executable can be called on its 'this' instance
195195
currentTestClass == executable.classId && this isThisInstanceOf currentTestClass -> true
196196

197-
// method of the current test class can be called on an object of this class or any of its subtypes
197+
// this executable can be called on an object of this class or any of its subtypes
198198
this.type isSubtypeOf executable.classId -> true
199199

200-
// method of the current test class can be called on builtin type
201-
this.type in builtinCallersWithoutReflection -> true
200+
// this executable can be called on builtin type
201+
this.type is BuiltinClassId && this.type in builtinCallersWithoutReflection -> true
202202

203203
else -> false
204204
}
205205

206-
// Fore some builtin types do not having [ClassId] we need to clarify
207-
// that it is allowed to call their methods without reflection.
206+
// For some builtin types we need to clarify
207+
// that it is allowed to call an executable without reflection.
208208
//
209209
// This approach is used, for example, to render the constructions with stubs
210210
// like `doNothing().when(entityManagerMock).persist(any())`.
211-
private val builtinCallersWithoutReflection = setOf<ClassId>(stubberClassId)
211+
private val builtinCallersWithoutReflection = setOf(genericObjectClassId)
212212

213213
/**
214214
* For Kotlin extension functions, real caller is one of the arguments in JVM method (and declaration class is omitted),

0 commit comments

Comments
 (0)