Skip to content

Commit 403b01b

Browse files
committed
switching to jcdb: another portion #349
1 parent 6fe710e commit 403b01b

32 files changed

+261
-433
lines changed

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

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -767,7 +767,7 @@ class BuiltinClassId(
767767

768768
override suspend fun outerMethod() = null
769769

770-
override suspend fun signature() = Raw
770+
override suspend fun resolution() = Raw
771771

772772
override suspend fun superclass() = null
773773
override suspend fun access() = Opcodes.ACC_PUBLIC
@@ -856,19 +856,19 @@ inline fun <T> withReflection(block: () -> T): T {
856856
* avoid using class loader to load a possibly missing class.
857857
*/
858858
//@Suppress("unused")
859-
class BuiltinFieldId(
860-
declaringClass: ClassId,
861-
override val name: String,
862-
// by default we assume that the builtin field is public and non-final
863-
override val isPublic: Boolean = true,
864-
override val isPrivate: Boolean = false,
865-
override val isFinal: Boolean = false,
866-
override val isSynthetic: Boolean = false,
867-
) : FieldId {
868-
override suspend fun type(): ClassId {
869-
TODO("Not yet implemented")
870-
}
871-
}
859+
//class BuiltinFieldId(
860+
// declaringClass: ClassId,
861+
// override val name: String,
862+
// // by default we assume that the builtin field is public and non-final
863+
// override val isPublic: Boolean = true,
864+
// override val isPrivate: Boolean = false,
865+
// override val isFinal: Boolean = false,
866+
// override val isSynthetic: Boolean = false,
867+
//) : FieldId {
868+
// override suspend fun type(): ClassId {
869+
// TODO("Not yet implemented")
870+
// }
871+
//}
872872

873873
sealed class StatementId {
874874
abstract val classId: ClassId
@@ -901,10 +901,11 @@ sealed class ExecutableId {
901901
get() = !(isPublic || isProtected || isPrivate)
902902

903903
val signature: String
904-
get() {
905-
val args = parameters.joinToString(separator = "") { it.name }
906-
val retType = returnType.name
907-
return "$name($args)$retType"
904+
get() = runBlocking {
905+
methodId.signature(false)
906+
// val args = parameters.joinToString(separator = "") { it.name }
907+
// val retType = returnType.name
908+
// return "$name($args)$retType"
908909
}
909910

910911
override fun equals(other: Any?): Boolean {

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

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,18 @@ val MethodId.returnType: ClassId
9999
val MethodId.parameters: List<ClassId>
100100
get() = runBlocking { parameters() }
101101

102+
val MethodId.signature: String
103+
get() = runBlocking { signature(false) }
104+
105+
val MethodId.internalSignature: String
106+
get() = runBlocking { signature(true) }
107+
108+
109+
infix fun ClassId.blockingIsSubtypeOf(another: ClassId): Boolean = runBlocking {
110+
this@blockingIsSubtypeOf isSubtypeOf another
111+
}
112+
113+
infix fun ClassId.blockingIsNotSubtypeOf(another: ClassId): Boolean = !this.blockingIsSubtypeOf(another)
102114

103115
/**
104116
* we will count item accessible if it is whether public
@@ -114,7 +126,8 @@ suspend fun Accessible.isAccessibleFrom(packageName: String): Boolean {
114126
else -> throw IllegalStateException("unknown type $this")
115127
}
116128

117-
val isAccessibleFromPackageByModifiers = isPublic() || (classId.packageName == packageName && (isPackagePrivate() || isProtected()))
129+
val isAccessibleFromPackageByModifiers =
130+
isPublic() || (classId.packageName == packageName && (isPackagePrivate() || isProtected()))
118131

119132
return classId.isClassAccessibleFrom(packageName) && isAccessibleFromPackageByModifiers
120133
}

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

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -417,21 +417,38 @@ fun ExecutableId.isConstructor(): Boolean {
417417
/**
418418
* Construct MethodId
419419
*/
420-
fun methodId(classId: ClassId, name: String, returnType: ClassId, vararg arguments: ClassId): MethodId = runBlocking{
420+
fun methodId(classId: ClassId, name: String, returnType: ClassId, vararg arguments: ClassId): MethodId = runBlocking {
421421
classId.methods().first {
422422
it.name == name && it.returnType == returnType && it.parameters().toTypedArray().contentEquals(arguments)
423423
}
424424
}
425425

426+
fun MethodId.asExecutable(): ExecutableId {
427+
if (isConstructor()) {
428+
return ConstructorExecutableId(this)
429+
}
430+
return MethodExecutableId(this)
431+
}
432+
433+
fun MethodId.asExecutableMethod(): MethodExecutableId {
434+
if (isConstructor()) {
435+
throw IllegalStateException("Method $this is a constructor")
436+
}
437+
return MethodExecutableId(this)
438+
}
439+
426440
/**
427441
* Construct ConstructorId
428442
*/
429-
fun constructorId(classId: ClassId, vararg arguments: ClassId): ConstructorExecutableId = runBlocking {
443+
fun constructorId(classId: ClassId, arguments: List<ClassId> = emptyList()): ConstructorExecutableId = runBlocking {
444+
val argsArray = arguments.toTypedArray()
430445
ConstructorExecutableId(classId.methods().first {
431-
it.name == "<init>" && it.parameters().toTypedArray().contentEquals(arguments)
446+
it.name == "<init>" && it.parameters().toTypedArray().contentEquals(argsArray)
432447
})
433448
}
434449

450+
fun constructorId(classId: ClassId, vararg arguments: ClassId) = constructorId(classId, arguments.toList())
451+
435452
fun builtinMethodId(
436453
classId: BuiltinClassId,
437454
name: String,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ abstract class BaseContainerWrapper(containerClassName: String) : BaseOverridden
107107
)
108108

109109
modificationsChain += parameterModels.map {
110-
UtExecutableCallModel(this, modificationMethodId, it)
110+
UtExecutableCallModel(this, modificationMethodId.asExecutable(), it)
111111
}
112112
}
113113
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.utbot.engine
22

3-
import org.utbot.framework.plugin.api.ClassId
3+
import org.utbot.framework.plugin.api.packageName
4+
import org.utbot.jcdb.api.ClassId
45

56
/**
67
* Mock strategies.

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import org.utbot.engine.util.mockListeners.MockListenerController
1212
import org.utbot.framework.plugin.api.UtModel
1313
import org.utbot.framework.plugin.api.id
1414
import org.utbot.framework.plugin.api.packageName
15+
import org.utbot.framework.plugin.api.signature
1516
import org.utbot.framework.plugin.api.util.id
1617
import org.utbot.framework.plugin.api.util.isRefType
1718
import org.utbot.framework.util.executableId

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

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,7 @@ import org.utbot.common.WorkaroundReason.MAKE_SYMBOLIC
44
import org.utbot.common.workaround
55
import org.utbot.engine.UtListClass.UT_ARRAY_LIST
66
import org.utbot.engine.UtListClass.UT_LINKED_LIST
7-
import org.utbot.engine.UtOptionalClass.UT_OPTIONAL
8-
import org.utbot.engine.UtOptionalClass.UT_OPTIONAL_DOUBLE
9-
import org.utbot.engine.UtOptionalClass.UT_OPTIONAL_INT
10-
import org.utbot.engine.UtOptionalClass.UT_OPTIONAL_LONG
7+
import org.utbot.engine.UtOptionalClass.*
118
import org.utbot.engine.UtStreamClass.UT_STREAM
129
import org.utbot.engine.overrides.collections.AssociativeArray
1310
import org.utbot.engine.overrides.collections.RangeModifiableUnlimitedArray
@@ -18,12 +15,7 @@ import org.utbot.engine.overrides.strings.UtString
1815
import org.utbot.engine.overrides.strings.UtStringBuffer
1916
import org.utbot.engine.overrides.strings.UtStringBuilder
2017
import org.utbot.engine.pc.UtAddrExpression
21-
import org.utbot.framework.plugin.api.UtAssembleModel
22-
import org.utbot.framework.plugin.api.UtExecutableCallModel
23-
import org.utbot.framework.plugin.api.UtModel
24-
import org.utbot.framework.plugin.api.UtPrimitiveModel
25-
import org.utbot.framework.plugin.api.UtStatementModel
26-
import org.utbot.framework.plugin.api.id
18+
import org.utbot.framework.plugin.api.*
2719
import org.utbot.framework.plugin.api.util.constructorId
2820
import org.utbot.framework.plugin.api.util.id
2921
import org.utbot.framework.plugin.api.util.stringClassId
@@ -32,10 +24,7 @@ import soot.RefType
3224
import soot.Scene
3325
import soot.SootClass
3426
import soot.SootMethod
35-
import java.util.Optional
36-
import java.util.OptionalDouble
37-
import java.util.OptionalInt
38-
import java.util.OptionalLong
27+
import java.util.*
3928
import java.util.concurrent.CopyOnWriteArrayList
4029
import kotlin.reflect.KClass
4130

@@ -237,7 +226,7 @@ data class ThrowableWrapper(val throwable: Throwable) : WrapperInterface {
237226
null -> UtExecutableCallModel(null, constructorId(classId), emptyList(), this)
238227
else -> UtExecutableCallModel(
239228
null,
240-
constructorId(classId, stringClassId),
229+
constructorId(classId, listOf(stringClassId)),
241230
listOf(UtPrimitiveModel(message)),
242231
this,
243232
)

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

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -95,21 +95,20 @@ class OptionalWrapper(private val utOptionalClass: UtOptionalClass) : BaseOverri
9595
}
9696
return if (!isPresent) {
9797
UtExecutableCallModel(
98-
null, MethodId(
98+
null, methodId(
9999
classId,
100100
"empty",
101-
classId,
102-
emptyList()
103-
), emptyList(), model
101+
classId
102+
).asExecutable(), emptyList(), model
104103
)
105104
} else {
106105
UtExecutableCallModel(
107-
null, MethodId(
106+
null, methodId(
108107
classId,
109108
"of",
110109
classId,
111-
listOf(utOptionalClass.elementClassId)
112-
), listOf(valueModel), model
110+
utOptionalClass.elementClassId
111+
).asExecutable(), listOf(valueModel), model
113112
)
114113
}
115114
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ abstract class StreamWrapper(
6666

6767
instantiationChain += UtExecutableCallModel(
6868
instance = null,
69-
executable = builder,
69+
executable = builder.asExecutable(),
7070
params = params,
7171
returnValue = this
7272
)

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ import org.utbot.framework.util.graph
2828
import org.utbot.jcdb.api.ClassId
2929
import org.utbot.jcdb.api.FieldId
3030
import org.utbot.jcdb.api.MethodId
31-
import org.utbot.jcdb.api.findFieldOrNull
3231
import soot.*
3332
import soot.jimple.*
3433
import soot.jimple.internal.*
@@ -688,7 +687,7 @@ class Traverser(
688687
val declaringClassType = fieldRef.field.declaringClass.type
689688
val fieldTypeId = fieldRef.field.type.classId
690689
val generator = UtMockInfoGenerator { mockAddr ->
691-
val fieldId = FieldId(declaringClassType.id, fieldRef.field.name)
690+
val fieldId = declaringClassType.id.findField(fieldRef.field.name)
692691
UtFieldMockInfo(fieldTypeId, mockAddr, fieldId, ownerAddr = null)
693692
}
694693
findOrCreateStaticObject(declaringClassType, generator)
@@ -1498,7 +1497,7 @@ class Traverser(
14981497
}
14991498
val generator = (value.field.type as? RefType)?.let { refType ->
15001499
UtMockInfoGenerator { mockAddr ->
1501-
val fieldId = objectType.id.findFieldOrNull(value.field.name)
1500+
val fieldId = objectType.id.findField(value.field.name)
15021501
UtFieldMockInfo(refType.id, mockAddr, fieldId, instance.addr)
15031502
}
15041503
}
@@ -1560,7 +1559,7 @@ class Traverser(
15601559

15611560
val generator = (field.type as? RefType)?.let { refType ->
15621561
UtMockInfoGenerator { mockAddr ->
1563-
val fieldId = declaringClassType.id.findFieldOrNull(field.name)
1562+
val fieldId = declaringClassType.id.findField(field.name)
15641563
UtFieldMockInfo(refType.id, mockAddr, fieldId, ownerAddr = null)
15651564
}
15661565
}
@@ -1908,7 +1907,7 @@ class Traverser(
19081907
private fun recordInstanceFieldRead(addr: UtAddrExpression, field: SootField) {
19091908
val realType = typeRegistry.findRealType(field.declaringClass.type)
19101909
if (realType is RefType) {
1911-
val readOperation = InstanceFieldReadOperation(addr, realType.id.findFieldOrNull(field.name))
1910+
val readOperation = InstanceFieldReadOperation(addr, realType.id.findField(field.name))
19121911
queuedSymbolicStateUpdates += MemoryUpdate(instanceFieldReads = persistentSetOf(readOperation))
19131912
}
19141913
}

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

Lines changed: 8 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,8 @@
11
package org.utbot.engine
22

33
import kotlinx.collections.immutable.persistentListOf
4-
import kotlinx.coroutines.CancellationException
5-
import kotlinx.coroutines.Job
6-
import kotlinx.coroutines.currentCoroutineContext
7-
import kotlinx.coroutines.ensureActive
8-
import kotlinx.coroutines.flow.Flow
9-
import kotlinx.coroutines.flow.FlowCollector
10-
import kotlinx.coroutines.flow.flow
11-
import kotlinx.coroutines.flow.onCompletion
12-
import kotlinx.coroutines.flow.onStart
13-
import kotlinx.coroutines.isActive
14-
import kotlinx.coroutines.job
15-
import kotlinx.coroutines.yield
4+
import kotlinx.coroutines.*
5+
import kotlinx.coroutines.flow.*
166
import mu.KotlinLogging
177
import org.utbot.analytics.EngineAnalyticsContext
188
import org.utbot.analytics.FeatureProcessor
@@ -22,27 +12,10 @@ import org.utbot.common.bracket
2212
import org.utbot.common.debug
2313
import org.utbot.common.workaround
2414
import org.utbot.engine.MockStrategy.NO_MOCKS
25-
import org.utbot.engine.pc.UtArraySelectExpression
26-
import org.utbot.engine.pc.UtBoolExpression
27-
import org.utbot.engine.pc.UtContextInitializer
28-
import org.utbot.engine.pc.UtSolver
29-
import org.utbot.engine.pc.UtSolverStatusSAT
30-
import org.utbot.engine.pc.findTheMostNestedAddr
31-
import org.utbot.engine.pc.mkEq
32-
import org.utbot.engine.pc.mkInt
33-
import org.utbot.engine.selectors.PathSelector
34-
import org.utbot.engine.selectors.StrategyOption
35-
import org.utbot.engine.selectors.coveredNewSelector
36-
import org.utbot.engine.selectors.cpInstSelector
37-
import org.utbot.engine.selectors.forkDepthSelector
38-
import org.utbot.engine.selectors.inheritorsSelector
39-
import org.utbot.engine.selectors.nnRewardGuidedSelector
15+
import org.utbot.engine.pc.*
16+
import org.utbot.engine.selectors.*
4017
import org.utbot.engine.selectors.nurs.NonUniformRandomSearch
41-
import org.utbot.engine.selectors.pollUntilFastSAT
42-
import org.utbot.engine.selectors.randomPathSelector
43-
import org.utbot.engine.selectors.randomSelector
4418
import org.utbot.engine.selectors.strategies.GraphViz
45-
import org.utbot.engine.selectors.subpathGuidedSelector
4619
import org.utbot.engine.symbolic.SymbolicState
4720
import org.utbot.engine.symbolic.asHardConstraint
4821
import org.utbot.engine.util.mockListeners.MockListener
@@ -58,41 +31,17 @@ import org.utbot.framework.UtSettings.useDebugVisualization
5831
import org.utbot.framework.concrete.UtConcreteExecutionData
5932
import org.utbot.framework.concrete.UtConcreteExecutionResult
6033
import org.utbot.framework.concrete.UtExecutionInstrumentation
61-
import org.utbot.framework.plugin.api.ClassId
62-
import org.utbot.framework.plugin.api.ConcreteExecutionFailureException
63-
import org.utbot.framework.plugin.api.EnvironmentModels
64-
import org.utbot.framework.plugin.api.Instruction
65-
import org.utbot.framework.plugin.api.MissingState
34+
import org.utbot.framework.plugin.api.*
6635
import org.utbot.framework.plugin.api.Step
67-
import org.utbot.framework.plugin.api.UtAssembleModel
68-
import org.utbot.framework.plugin.api.UtConcreteExecutionFailure
69-
import org.utbot.framework.plugin.api.UtError
70-
import org.utbot.framework.plugin.api.UtExecution
71-
import org.utbot.framework.plugin.api.UtInstrumentation
72-
import org.utbot.framework.plugin.api.UtMethod
73-
import org.utbot.framework.plugin.api.UtNullModel
74-
import org.utbot.framework.plugin.api.UtOverflowFailure
75-
import org.utbot.framework.plugin.api.UtResult
36+
import org.utbot.framework.plugin.api.util.*
7637
import org.utbot.framework.util.graph
77-
import org.utbot.framework.plugin.api.onSuccess
78-
import org.utbot.framework.plugin.api.util.executableId
79-
import org.utbot.framework.plugin.api.util.id
80-
import org.utbot.framework.plugin.api.util.utContext
81-
import org.utbot.framework.plugin.api.util.description
8238
import org.utbot.framework.util.jimpleBody
83-
import org.utbot.framework.plugin.api.util.voidClassId
84-
import org.utbot.fuzzer.FallbackModelProvider
85-
import org.utbot.fuzzer.FuzzedMethodDescription
86-
import org.utbot.fuzzer.FuzzedValue
87-
import org.utbot.fuzzer.ModelProvider
88-
import org.utbot.fuzzer.Trie
89-
import org.utbot.fuzzer.collectConstantsForFuzzer
90-
import org.utbot.fuzzer.defaultModelProviders
91-
import org.utbot.fuzzer.fuzz
39+
import org.utbot.fuzzer.*
9240
import org.utbot.fuzzer.names.MethodBasedNameSuggester
9341
import org.utbot.fuzzer.names.ModelBasedNameSuggester
9442
import org.utbot.fuzzer.providers.ObjectModelProvider
9543
import org.utbot.instrumentation.ConcreteExecutor
44+
import org.utbot.jcdb.api.ClassId
9645
import soot.jimple.Stmt
9746
import soot.tagkit.ParamNamesTag
9847
import java.lang.reflect.Method

0 commit comments

Comments
 (0)