Skip to content

Commit 0ef4583

Browse files
committed
switching to jcdb: another portion #349
1 parent d8966ad commit 0ef4583

File tree

7 files changed

+25
-27
lines changed

7 files changed

+25
-27
lines changed

utbot-framework-api/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ dependencies {
1414
implementation group: 'io.github.microutils', name: 'kotlin-logging', version: kotlin_logging_version
1515
implementation group: 'org.ow2.asm', name: 'asm', version: asm_version
1616

17-
api group: 'com.github.UnitTestBot.jcdb', name: 'jcdb-core', version: '7b0de88442'
17+
api group: 'com.github.UnitTestBot.jcdb', name: 'jcdb-core', version: '6269be7929'
1818
}
1919

2020
shadowJar {

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,4 +134,9 @@ suspend fun Accessible.isAccessibleFrom(packageName: String): Boolean {
134134

135135
suspend fun ClassId.isClassAccessibleFrom(packageName: String): Boolean {
136136
return isPublic() || (this.packageName == packageName && (isPackagePrivate() || isProtected()))
137-
}
137+
}
138+
139+
val ClassId.isInDefaultPackage: Boolean
140+
get() {
141+
return this is PredefinedPrimitive || packageName.isEmpty()
142+
}

utbot-framework/src/main/kotlin/org/utbot/framework/assemble/AssembleModelGenerator.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import org.utbot.framework.modifications.UtBotFieldsModificatorsSearcher
1414
import org.utbot.framework.plugin.api.*
1515
import org.utbot.framework.plugin.api.util.asExecutable
1616
import org.utbot.framework.plugin.api.util.defaultValueModel
17-
import org.utbot.framework.plugin.api.util.jClass
1817
import org.utbot.framework.util.nextModelName
1918
import org.utbot.jcdb.api.ClassId
2019
import org.utbot.jcdb.api.FieldId
@@ -208,7 +207,7 @@ class AssembleModelGenerator(private val methodUnderTest: UtMethod<*>) {
208207
}
209208

210209
try {
211-
val modelName = nextModelName(compositeModel.classId.jClass.simpleName.decapitalize())
210+
val modelName = nextModelName(compositeModel.classId.simpleName.decapitalize())
212211

213212
val instantiationChain = mutableListOf<UtStatementModel>()
214213
val modificationsChain = mutableListOf<UtStatementModel>()

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

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -709,15 +709,13 @@ internal class CgMethodConstructor(val context: CgContext) : CgContextOwner by c
709709
* We overapproximate this assumption for all parametrized classes because we can't be sure that
710710
* overridden equals doesn't rely on type parameters equals.
711711
*/
712-
private suspend fun CgVariable.hasNotParametrizedCustomEquals(): Boolean {
712+
private fun CgVariable.hasNotParametrizedCustomEquals(): Boolean = runBlocking {
713713
if (type.overridesEquals()) {
714714
// type parameters is list of class type parameters - empty if class is not generic
715-
val resolution = runBlocking { type.resolution() }
716-
717-
return resolution == Raw
715+
type.resolution() == Raw
716+
}else {
717+
false
718718
}
719-
720-
return false
721719
}
722720

723721
/**
@@ -850,7 +848,7 @@ internal class CgMethodConstructor(val context: CgContext) : CgContextOwner by c
850848
// TODO: How to compare arrays of Float and Double wrappers?
851849
// TODO: For example, JUnit5 does not have an assertEquals() overload for these wrappers.
852850
// TODO: So for now we compare arrays of these wrappers as arrays of Objects, but that is probably wrong.
853-
when (expected.type..ifArrayGetElementClass()!!) {
851+
when (expected.type.ifArrayGetElementClass()!!) {
854852
floatClassId -> testFrameworkManager.assertFloatArrayEquals(
855853
typeCast(floatArrayClassId, expected, isSafetyCast = true),
856854
typeCast(floatArrayClassId, actual, isSafetyCast = true),

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

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@ import org.utbot.framework.fields.FieldAccess
1313
import org.utbot.framework.fields.FieldPath
1414
import org.utbot.framework.plugin.api.*
1515
import org.utbot.framework.plugin.api.util.*
16-
import org.utbot.jcdb.api.ClassId
17-
import org.utbot.jcdb.api.MethodId
18-
import org.utbot.jcdb.api.isSubtypeOf
16+
import org.utbot.jcdb.api.*
1917

2018
internal data class EnvironmentFieldStateCache(
2119
val thisInstance: FieldStateCache,
@@ -210,15 +208,15 @@ internal suspend fun ClassId.overridesEquals(): Boolean =
210208
}
211209

212210
// NOTE: this function does not consider executable return type because it is not important in our case
213-
internal fun ClassId.getAmbiguousOverloadsOf(executableId: ExecutableId): Sequence<ExecutableId> {
214-
val allExecutables = when (executableId) {
215-
is MethodExecutableId -> allMethods
216-
is ConstructorExecutableId -> allConstructors
211+
internal fun ClassId.getAmbiguousOverloadsOf(executableId: ExecutableId): Sequence<ExecutableId> = runBlocking {
212+
val methodsOrConstructors = when (executableId) {
213+
is MethodExecutableId -> methods().filter { !it.isConstructor }
214+
is ConstructorExecutableId -> allConstructors()
217215
}
218216

219-
return allExecutables.filter {
217+
methodsOrConstructors.filter {
220218
it.name == executableId.name && it.parameters.size == executableId.executable.parameters.size && it.classId == executableId.classId
221-
}
219+
}.map { it.asExecutable() }.asSequence()
222220
}
223221

224222

@@ -262,7 +260,7 @@ internal infix fun UtModel.isDefaultValueOf(type: ClassId): Boolean =
262260
else -> false
263261
}
264262

265-
internal infix fun UtModel.isNotDefaultValueOf(type: ClassId): Boolean = !this.isDefaultValueOf(type)
263+
internal infix fun UtModel.isNotDefaultValueOf(type: ClassId): Boolean = !isDefaultValueOf(type)
266264

267265
/**
268266
* If the model contains a store for the given [index], return the model of this store.

utbot-framework/src/main/kotlin/org/utbot/fuzzer/FallbackModelProvider.kt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package org.utbot.fuzzer
22

33
import kotlinx.coroutines.runBlocking
4-
import org.utbot.engine.isPublic
54
import org.utbot.framework.concrete.UtModelConstructor
65
import org.utbot.framework.plugin.api.*
76
import org.utbot.framework.plugin.api.util.*
@@ -25,8 +24,8 @@ open class FallbackModelProvider(
2524

2625
private fun createModelByClassId(classId: ClassId): UtModel = runBlocking {
2726
val modelConstructor = UtModelConstructor(IdentityHashMap())
28-
val defaultConstructor = classId.jClass.constructors.firstOrNull {
29-
it.parameters.isEmpty() && it.isPublic
27+
val defaultConstructor = classId.allConstructors().firstOrNull {
28+
it.parameters().isEmpty() && it.isPublic()
3029
}
3130
when {
3231
classId.isPrimitive ->
@@ -42,7 +41,7 @@ open class FallbackModelProvider(
4241
classId.isIterable -> {
4342
@Suppress("RemoveRedundantQualifierName") // ArrayDeque must be taken from java, not from kotlin
4443
val defaultInstance = when {
45-
defaultConstructor != null -> defaultConstructor.newInstance()
44+
defaultConstructor != null -> (defaultConstructor.asExecutable() as ConstructorExecutableId).constructor.newInstance()
4645
classId isSubtypeOf asClass<java.util.ArrayList<*>>() -> ArrayList<Any>()
4746
classId isSubtypeOf asClass<java.util.TreeSet<*>>() -> TreeSet<Any>()
4847
classId isSubtypeOf asClass<java.util.HashMap<*,*>>() -> HashMap<Any, Any>()

utbot-framework/src/test/kotlin/org/utbot/examples/UtModelTestCaseChecker.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import org.utbot.common.ClassLocation
77
import org.utbot.common.FileUtil.findPathToClassFiles
88
import org.utbot.common.FileUtil.locateClass
99
import org.utbot.common.WorkaroundReason.HACK
10-
import org.utbot.common.findField
1110
import org.utbot.common.workaround
1211
import org.utbot.engine.prettify
1312
import org.utbot.framework.UtSettings.checkSolverTimeoutMillis
@@ -148,7 +147,7 @@ internal abstract class UtModelTestCaseChecker(
148147
* Finds field model in [UtCompositeModel] and [UtAssembleModel]. For assemble model supports direct field access only.
149148
*/
150149
protected fun UtModel.findField(fieldName: String): UtModel =
151-
findField(this.classId.jClass.findField(fieldName).fieldId)
150+
findField(classId.findField(fieldName))
152151

153152
/**
154153
* Finds field model in [UtCompositeModel] and [UtAssembleModel]. For assemble model supports direct field access only.

0 commit comments

Comments
 (0)