Skip to content

Commit 7e3c445

Browse files
committed
Some fixes
1 parent 41f3316 commit 7e3c445

File tree

10 files changed

+32
-18
lines changed

10 files changed

+32
-18
lines changed

utbot-framework-api/src/main/kotlin/org/utbot/framework/plugin/api/Api.kt

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ package org.utbot.framework.plugin.api
1111
import org.utbot.common.isDefaultValue
1212
import org.utbot.common.withToStringThreadLocalReentrancyGuard
1313
import org.utbot.framework.UtSettings
14-
import org.utbot.framework.plugin.api.MockFramework.MOCKITO
1514
import org.utbot.framework.plugin.api.impl.FieldIdReflectionStrategy
1615
import org.utbot.framework.plugin.api.impl.FieldIdSootStrategy
1716
import org.utbot.framework.plugin.api.util.booleanClassId
@@ -1084,10 +1083,15 @@ class BuiltinConstructorId(
10841083
classId: ClassId,
10851084
parameters: List<ClassId>,
10861085
// by default, we assume that the builtin constructor is public
1087-
override val isPublic: Boolean = true,
1088-
override val isProtected: Boolean = false,
1089-
override val isPrivate: Boolean = false
1090-
) : ConstructorId(classId, parameters)
1086+
isPublic: Boolean = true,
1087+
isProtected: Boolean = false,
1088+
isPrivate: Boolean = false
1089+
) : ConstructorId(classId, parameters) {
1090+
override val modifiers: Int =
1091+
(if (isPublic) Modifier.PUBLIC else 0) or
1092+
(if (isProtected) Modifier.PROTECTED else 0) or
1093+
(if (isPrivate) Modifier.PRIVATE else 0)
1094+
}
10911095

10921096
open class TypeParameters(val parameters: List<ClassId> = emptyList())
10931097

utbot-framework/src/main/kotlin/org/utbot/engine/UtBotSymbolicEngine.kt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,16 +59,13 @@ import org.utbot.framework.plugin.api.UtOverflowFailure
5959
import org.utbot.framework.plugin.api.UtResult
6060
import org.utbot.framework.plugin.api.UtSymbolicExecution
6161
import org.utbot.framework.util.graph
62-
import org.utbot.framework.plugin.api.util.executableId
6362
import org.utbot.framework.plugin.api.util.isStatic
64-
import org.utbot.framework.plugin.api.onSuccess
6563
import org.utbot.framework.plugin.api.util.description
6664
import org.utbot.framework.plugin.api.util.id
6765
import org.utbot.framework.plugin.api.util.isConstructor
6866
import org.utbot.framework.plugin.api.util.isEnum
6967
import org.utbot.framework.plugin.api.util.utContext
7068
import org.utbot.framework.plugin.api.util.voidClassId
71-
import org.utbot.framework.util.graph
7269
import org.utbot.framework.util.sootMethod
7370
import org.utbot.fuzzer.FallbackModelProvider
7471
import org.utbot.fuzzer.FuzzedMethodDescription

utbot-framework/src/main/kotlin/org/utbot/engine/ValueConstructor.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import org.utbot.framework.plugin.api.UtValueExecutionState
3939
import org.utbot.framework.plugin.api.UtVoidModel
4040
import org.utbot.framework.plugin.api.isMockModel
4141
import org.utbot.framework.plugin.api.util.constructor
42+
import org.utbot.framework.plugin.api.util.isStatic
4243
import org.utbot.framework.plugin.api.util.jField
4344
import org.utbot.framework.plugin.api.util.jClass
4445
import org.utbot.framework.plugin.api.util.method

utbot-framework/src/main/kotlin/org/utbot/engine/util/lambda/LambdaConstructionUtils.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ internal fun constructLambda(
155155
samType: Class<*>,
156156
declaringClass: Class<*>,
157157
lambdaName: String,
158-
capturedReceiver: Any,
158+
capturedReceiver: Any?,
159159
vararg capturedArguments: CapturedArgument
160160
): Any {
161161
val (caller, invokedName, samMethodType, lambdaMethod, lambdaMethodType) =
@@ -164,7 +164,7 @@ internal fun constructLambda(
164164
val lambdaMethodHandle = caller.findVirtual(declaringClass, lambdaName, lambdaMethodType)
165165

166166
val capturedArgumentTypes = capturedArguments.map { it.type }.toTypedArray()
167-
val invokedType = MethodType.methodType(samType, capturedReceiver.javaClass, *capturedArgumentTypes)
167+
val invokedType = MethodType.methodType(samType, declaringClass, *capturedArgumentTypes)
168168
val instantiatedMethodType = getInstantiatedMethodType(lambdaMethod, capturedArgumentTypes)
169169

170170
// Create a CallSite for the given lambda.

utbot-framework/src/main/kotlin/org/utbot/framework/codegen/model/constructor/tree/CgUtilClassConstructor.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package org.utbot.framework.codegen.model.constructor.tree
33
import org.utbot.framework.codegen.model.CodeGenerator
44
import org.utbot.framework.codegen.model.UtilClassKind
55
import org.utbot.framework.codegen.model.constructor.builtin.utUtilsClassId
6+
import org.utbot.framework.codegen.model.tree.CgAuxiliaryClass
67
import org.utbot.framework.codegen.model.tree.CgRegularClassFile
78
import org.utbot.framework.codegen.model.tree.CgUtilMethod
89
import org.utbot.framework.codegen.model.tree.buildRegularClass
@@ -25,6 +26,7 @@ internal object CgUtilClassConstructor {
2526
content += utilClassKind.utilClassVersionComment
2627
content += utilClassKind.utilClassKindComment
2728
content += utilMethodProvider.utilMethodIds.map { CgUtilMethod(it) }
29+
content += CgAuxiliaryClass(utilMethodProvider.capturedArgumentClassId)
2830
}
2931
}
3032
}

utbot-framework/src/main/kotlin/org/utbot/framework/codegen/model/constructor/tree/CgVariableConstructor.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,10 @@ import org.utbot.framework.plugin.api.util.id
5656
import org.utbot.framework.plugin.api.util.intClassId
5757
import org.utbot.framework.plugin.api.util.isArray
5858
import org.utbot.framework.plugin.api.util.isPrimitiveWrapperOrString
59+
import org.utbot.framework.plugin.api.util.isStatic
5960
import org.utbot.framework.plugin.api.util.stringClassId
6061
import org.utbot.framework.plugin.api.util.supertypeOfAnonymousClass
6162
import org.utbot.framework.plugin.api.util.wrapperByPrimitive
62-
import java.lang.reflect.Field
63-
import java.lang.reflect.Modifier
6463

6564
/**
6665
* Constructs CgValue or CgVariable given a UtModel

utbot-framework/src/main/kotlin/org/utbot/framework/codegen/model/constructor/util/CgStatementConstructor.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ internal class CgStatementConstructorImpl(context: CgContext) :
320320
return if (classId isAccessibleFrom testClassPackageName) {
321321
CgGetJavaClass(classId)
322322
} else {
323-
newVar(classCgClassId) { Class::class.id[forName](classId.name) }
323+
newVar(classCgClassId) { classClassId[forName](classId.name) }
324324
}
325325
}
326326

utbot-framework/src/main/kotlin/org/utbot/framework/codegen/model/visitor/UtilMethods.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1302,7 +1302,7 @@ private fun capturedArgumentClass(language: CodegenLanguage) =
13021302
* Captured values are represented as arguments of a synthetic method that lambda is compiled into,
13031303
* hence the name of the class.
13041304
*/
1305-
static class CapturedArgument {
1305+
public static class CapturedArgument {
13061306
private Class<?> type;
13071307
private Object value;
13081308

utbot-framework/src/main/kotlin/org/utbot/framework/concrete/MockValueConstructor.kt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ import org.utbot.engine.util.lambda.CapturedArgument
4848
import org.utbot.engine.util.lambda.constructLambda
4949
import org.utbot.engine.util.lambda.constructStaticLambda
5050
import org.utbot.framework.plugin.api.UtLambdaModel
51+
import org.utbot.framework.plugin.api.util.isStatic
5152
import org.utbot.instrumentation.process.runSandbox
5253

5354
/**
@@ -369,14 +370,15 @@ class MockValueConstructor(
369370
}
370371

371372
private fun constructFromLambdaModel(lambdaModel: UtLambdaModel): Any {
373+
constructedObjects[lambdaModel]?.let { return it }
372374
// A class representing a functional interface.
373375
val samType: Class<*> = lambdaModel.samType.jClass
374376
// A class where the lambda is declared.
375377
val declaringClass: Class<*> = lambdaModel.declaringClass.jClass
376378
// A name of the synthetic method that represents a lambda.
377379
val lambdaName = lambdaModel.lambdaName
378380

379-
return if (lambdaModel.lambdaMethodId.isStatic) {
381+
val lambda = if (lambdaModel.lambdaMethodId.isStatic) {
380382
val capturedArguments = lambdaModel.capturedValues
381383
.map { model -> CapturedArgument(type = model.classId.jClass, value = value(model)) }
382384
.toTypedArray()
@@ -386,12 +388,14 @@ class MockValueConstructor(
386388
?: error("Non-static lambda must capture `this` instance, so there must be at least one captured value")
387389

388390
// Values that the given lambda has captured.
389-
val capturedReceiver = value(capturedReceiverModel) ?: error("Captured receiver of lambda must not be null")
391+
val capturedReceiver = value(capturedReceiverModel)
390392
val capturedArguments = lambdaModel.capturedValues.subList(1, lambdaModel.capturedValues.size)
391393
.map { model -> CapturedArgument(type = model.classId.jClass, value = value(model)) }
392394
.toTypedArray()
393395
constructLambda(samType, declaringClass, lambdaName, capturedReceiver, *capturedArguments)
394396
}
397+
constructedObjects[lambdaModel] = lambda
398+
return lambda
395399
}
396400

397401
/**

utbot-framework/src/main/kotlin/org/utbot/framework/concrete/UtModelConstructor.kt

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import org.utbot.framework.plugin.api.UtAssembleModel
99
import org.utbot.framework.plugin.api.UtClassRefModel
1010
import org.utbot.framework.plugin.api.UtCompositeModel
1111
import org.utbot.framework.plugin.api.UtEnumConstantModel
12+
import org.utbot.framework.plugin.api.UtLambdaModel
1213
import org.utbot.framework.plugin.api.UtModel
1314
import org.utbot.framework.plugin.api.UtNullModel
1415
import org.utbot.framework.plugin.api.UtPrimitiveModel
@@ -82,8 +83,13 @@ class UtModelConstructor(
8283
*
8384
* Handles cache on stateBefore values.
8485
*/
85-
override fun construct(value: Any?, classId: ClassId): UtModel =
86-
when (value) {
86+
override fun construct(value: Any?, classId: ClassId): UtModel {
87+
objectToModelCache[value]?.let { model ->
88+
if (model is UtLambdaModel) {
89+
return model
90+
}
91+
}
92+
return when (value) {
8793
null -> UtNullModel(classId)
8894
is Unit -> UtVoidModel
8995
is Byte,
@@ -107,6 +113,7 @@ class UtModelConstructor(
107113
is Class<*> -> constructFromClass(value)
108114
else -> constructFromAny(value)
109115
}
116+
}
110117

111118
// Q: Is there a way to get rid of duplicated code?
112119

0 commit comments

Comments
 (0)