Skip to content

Commit 4928997

Browse files
committed
Another attempt to fix everything
1 parent 88ba10c commit 4928997

File tree

7 files changed

+23
-23
lines changed

7 files changed

+23
-23
lines changed

utbot-framework-test/src/test/kotlin/org/utbot/framework/assemble/AssembleModelGeneratorTests.kt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,7 @@ class AssembleModelGeneratorTests {
149149
fields(testClassId, "a" to 5, "b" to 3)
150150
)
151151

152-
val methodFromAnotherPackage =
153-
MethodUnderTest::class.functions.first()
152+
val methodFromAnotherPackage = MethodUnderTest::class.functions.first()
154153

155154
createModelAndAssert(compositeModel, null, methodFromAnotherPackage.executableId)
156155
}
@@ -1449,7 +1448,7 @@ class AssembleModelGeneratorTests {
14491448
expectedModelRepresentations: List<String?>,
14501449
assembleTestDummyMethod: ExecutableId = AssembleTestUtils::class.id.allMethods.first(),
14511450
) {
1452-
val modelsMap = AssembleModelGenerator(assembleTestDummyMethod).createAssembleModels(models)
1451+
val modelsMap = AssembleModelGenerator(assembleTestDummyMethod.classId.packageName).createAssembleModels(models)
14531452
//we sort values to fix order of models somehow (IdentityHashMap does not guarantee the order)
14541453
val assembleModels = modelsMap.values
14551454
.filterIsInstance<UtAssembleModel>()

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ class Resolver(
133133
private val instrumentation = mutableListOf<UtInstrumentation>()
134134
private val requiredInstanceFields = mutableMapOf<Address, Set<FieldId>>()
135135

136-
private val assembleModelGenerator = AssembleModelGenerator(methodUnderTest)
136+
private val assembleModelGenerator = AssembleModelGenerator(methodUnderTest.classId.packageName)
137137

138138
/**
139139
* Contains FieldId of the static field which is construction at the moment and null of there is no such field.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -639,7 +639,7 @@ private suspend fun ConcreteExecutor<UtConcreteExecutionResult, UtExecutionInstr
639639
methodUnderTest.signature,
640640
arrayOf(),
641641
parameters = UtConcreteExecutionData(stateBefore, instrumentation)
642-
).convertToAssemble(methodUnderTest)
642+
).convertToAssemble(methodUnderTest.classId.packageName)
643643

644644
/**
645645
* Before pushing our states for concrete execution, we have to be sure that every state is consistent.

utbot-framework/src/main/kotlin/org/utbot/external/api/UtModelFactory.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class UtModelFactory(
4949
classUnderTest: Class<*>,
5050
models: List<UtModel>
5151
): IdentityHashMap<UtModel, UtModel> =
52-
AssembleModelGenerator(methodUnderTest.executableId)
52+
AssembleModelGenerator(classUnderTest.packageName)
5353
.createAssembleModels(models)
5454

5555
@JvmOverloads

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

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,13 @@ import java.util.IdentityHashMap
4343

4444
/**
4545
* Creates [UtAssembleModel] from any [UtModel] or it's inner models if possible
46-
* during generation test for [methodUnderTest].
46+
* during generation test for [methodPackageName].
4747
*
4848
* Needs utContext be set and Soot be initialized.
4949
*
5050
* Note: Caches class related information, can be reused if classes don't change.
5151
*/
52-
class AssembleModelGenerator(private val methodUnderTest: ExecutableId) {
52+
class AssembleModelGenerator(private val methodPackageName: String) {
5353

5454
//Instantiated models are stored to avoid cyclic references during reference graph analysis
5555
private val instantiatedModels: IdentityHashMap<UtModel, UtReferenceModel> =
@@ -100,7 +100,8 @@ class AssembleModelGenerator(private val methodUnderTest: ExecutableId) {
100100
* Note: Two identity equal [UtModel]s are represented by one instance model.
101101
*/
102102
fun createAssembleModels(models: List<UtModel>): IdentityHashMap<UtModel, UtModel> {
103-
if (!UtSettings.useAssembleModelGenerator) {
103+
val allModelsAreLocatedInPackage = models.all { it.classId.packageName.startsWith(methodPackageName)}
104+
if (!UtSettings.useAssembleModelGenerator || !allModelsAreLocatedInPackage) {
104105
return IdentityHashMap<UtModel, UtModel>().apply { models.forEach { put(it, it) } }
105106
}
106107

@@ -256,7 +257,7 @@ class AssembleModelGenerator(private val methodUnderTest: ExecutableId) {
256257
if (fieldId.isFinal) {
257258
throw AssembleException("Final field $fieldId can't be set in an object of the class $classId")
258259
}
259-
if (!fieldId.type.isAccessibleFrom(methodUnderTest.classId.packageName)) {
260+
if (!fieldId.type.isAccessibleFrom(methodPackageName)) {
260261
throw AssembleException(
261262
"Field $fieldId can't be set in an object of the class $classId because its type is inaccessible"
262263
)
@@ -398,10 +399,10 @@ class AssembleModelGenerator(private val methodUnderTest: ExecutableId) {
398399
}
399400

400401
private val ClassId.isVisible : Boolean
401-
get() = this.isPublic || !this.isPrivate && this.packageName.startsWith(methodUnderTest.classId.packageName)
402+
get() = this.isPublic || !this.isPrivate && this.packageName.startsWith(methodPackageName)
402403

403404
private val Constructor<*>.isVisible : Boolean
404-
get() = this.isPublic || !this.isPrivate && this.declaringClass.packageName.startsWith(methodUnderTest.classId.packageName)
405+
get() = this.isPublic || !this.isPrivate && this.declaringClass.packageName.startsWith(methodPackageName)
405406

406407
/**
407408
* Creates setter or direct setter call to set a field.
@@ -441,7 +442,7 @@ class AssembleModelGenerator(private val methodUnderTest: ExecutableId) {
441442
*/
442443
private fun findSettersAndDirectAccessors(classId: ClassId): Map<FieldId, StatementId> {
443444
val allModificatorsOfClass = modificatorsSearcher
444-
.findModificators(SettersAndDirectAccessors, methodUnderTest)
445+
.findModificators(SettersAndDirectAccessors, classId)
445446
.map { it.key to it.value.filter { st -> st.classId == classId } }
446447

447448
return allModificatorsOfClass

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,10 @@ class UtConcreteExecutionResult(
9999
*
100100
* @return [UtConcreteExecutionResult] with converted models.
101101
*/
102-
fun convertToAssemble(methodUnderTest: ExecutableId): UtConcreteExecutionResult {
102+
fun convertToAssemble(packageName: String): UtConcreteExecutionResult {
103103
val allModels = collectAllModels()
104104

105-
val modelsToAssembleModels = AssembleModelGenerator(methodUnderTest).createAssembleModels(allModels)
105+
val modelsToAssembleModels = AssembleModelGenerator(packageName).createAssembleModels(allModels)
106106
return updateWithAssembleModels(modelsToAssembleModels)
107107
}
108108

utbot-framework/src/main/kotlin/org/utbot/framework/modifications/UtBotFieldsModificatorsSearcher.kt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,16 @@ class UtBotFieldsModificatorsSearcher {
2020
* @param analysisMode represents which type of modificators (e.g. setters) are considered.
2121
* @param methodUnderTest describes an analyzed method an it's location.
2222
*/
23-
fun findModificators(analysisMode: AnalysisMode, methodUnderTest: ExecutableId? = null): Map<FieldId, Set<StatementId>> {
23+
fun findModificators(analysisMode: AnalysisMode, classUnderTest: ClassId? = null): Map<FieldId, Set<StatementId>> {
2424
val modificators = findModificators(analysisMode)
2525

26-
if (methodUnderTest == null) {
26+
if (classUnderTest == null) {
2727
return modificators
2828
}
2929

3030
val filteredModifications = mutableMapOf<FieldId, Set<StatementId>>()
3131
for ((fieldId, statements) in modificators) {
32-
val filteredStmts = statements.filter { stmt -> fieldId.isAccessibleBy(stmt, methodUnderTest!!) }
32+
val filteredStmts = statements.filter { stmt -> fieldId.isAccessibleBy(stmt, classUnderTest!!) }
3333
filteredModifications[fieldId] = filteredStmts.toSet()
3434
}
3535

@@ -39,15 +39,15 @@ class UtBotFieldsModificatorsSearcher {
3939
/**
4040
* Verifies that this field is accessible with [statementId] from the location of [methodUnderTest].
4141
*/
42-
private fun FieldId.isAccessibleBy(statementId: StatementId, methodUnderTest: ExecutableId): Boolean {
43-
val basePackageName = methodUnderTest.classId.packageName
42+
private fun FieldId.isAccessibleBy(statementId: StatementId, classUnderTest: ClassId): Boolean {
43+
val basePackageName = classUnderTest.packageName
4444
val classPackageName = statementId.classId.packageName
4545

4646
if (this.isPublic) return true
47-
if (this.isProtected) return classPackageName == basePackageName || statementId.classId.isSubtypeOf(methodUnderTest.classId)
47+
if (this.isProtected) return classPackageName == basePackageName || statementId.classId.isSubtypeOf(classUnderTest)
4848
if (this.isPackagePrivate) return classPackageName == basePackageName
49-
if (this.isPrivate) methodUnderTest.classId == statementId.classId
50-
return true
49+
if (this.isPrivate) return classUnderTest == statementId.classId
50+
return error("Unexpected modifier for field $this")
5151
}
5252

5353
private fun findModificators(analysisMode: AnalysisMode): Map<FieldId, Set<StatementId>> {

0 commit comments

Comments
 (0)