Skip to content

Commit 19b0f78

Browse files
Modificators processing in AssembleModelGenerator and UtBotFieldModificatorsSearcher corrected (#1029)
* Improve modificators analysis in UtBotFieldModificatorsSearcher and AssembleModelGenerator * Apply review comments * Fixed test * One more correction for package names
1 parent eed1557 commit 19b0f78

35 files changed

+104
-107
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package org.utbot.examples.assemble.arrays;
1+
package org.utbot.examples.assemble;
22

33
/**
44
* A class with array of objects that are arrays of complex fields themselves.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package org.utbot.examples.assemble.arrays;
1+
package org.utbot.examples.assemble;
22

33
/**
44
* A class with a two-dimensional array field.

utbot-framework-test/src/main/java/org/utbot/examples/assemble/arrays/AssignedArray.java renamed to utbot-framework-test/src/main/java/org/utbot/examples/assemble/AssignedArray.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package org.utbot.examples.assemble.arrays;
1+
package org.utbot.examples.assemble;
22

33
/**
44
* A class with an array with a default value.

utbot-framework-test/src/main/java/org/utbot/examples/assemble/arrays/ComplexArray.java renamed to utbot-framework-test/src/main/java/org/utbot/examples/assemble/ComplexArray.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package org.utbot.examples.assemble.arrays;
1+
package org.utbot.examples.assemble;
22

33
import org.utbot.examples.assemble.PrimitiveFields;
44

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package org.utbot.examples.assemble.constructors;
1+
package org.utbot.examples.assemble;
22

33
/**
44
* A class without default constructor and with complex one.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package org.utbot.examples.assemble.constructors;
1+
package org.utbot.examples.assemble;
22

33
/**
44
* A class without default constructor and with complex one,
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package org.utbot.examples.assemble.constructors;
1+
package org.utbot.examples.assemble;
22

33
public class ConstructorModifyingStatic {
44

utbot-framework-test/src/main/java/org/utbot/examples/assemble/defaults/DefaultField.java renamed to utbot-framework-test/src/main/java/org/utbot/examples/assemble/DefaultField.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package org.utbot.examples.assemble.defaults;
1+
package org.utbot.examples.assemble;
22

33
/**
44
* A class with a field with default value that is not a default value of type.
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
package org.utbot.examples.assemble.defaults;
1+
package org.utbot.examples.assemble;
22

33
public class DefaultFieldModifiedInConstructor {
4-
int z;
4+
public int z;
55

66
@SuppressWarnings("Unused")
77
DefaultFieldModifiedInConstructor(int z_) {
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package org.utbot.examples.assemble.defaults;
1+
package org.utbot.examples.assemble;
22

33
/**
44
* A class with a field with default value that is not a default value of type.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package org.utbot.examples.assemble.defaults;
1+
package org.utbot.examples.assemble;
22

33
/**
44
* A class with a field with setter default value that is not a default value of type.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package org.utbot.examples.assemble;
2+
3+
/**
4+
* Need to be located at the same package as [AssembleTestUtils]
5+
* because requires a setter for package-private field.
6+
*/
7+
public class DefaultPackagePrivateField {
8+
int z = 10;
9+
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package org.utbot.examples.assemble.constructors;
1+
package org.utbot.examples.assemble;
22

33
/**
44
* A class with a primitive constructor that inherits a complex constructor.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package org.utbot.examples.assemble.constructors;
1+
package org.utbot.examples.assemble;
22

33
/**
44
* A class with a primitive constructor that inherits another primitive constructor.

utbot-framework-test/src/main/java/org/utbot/examples/assemble/arrays/PrimitiveArray.java renamed to utbot-framework-test/src/main/java/org/utbot/examples/assemble/PrimitiveArray.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package org.utbot.examples.assemble.arrays;
1+
package org.utbot.examples.assemble;
22

33
/**
44
* A class with an array with elements of primitive type.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package org.utbot.examples.assemble.constructors;
1+
package org.utbot.examples.assemble;
22

33
/**
44
* A class without default constructor and with primitive one.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package org.utbot.examples.assemble.constructors;
1+
package org.utbot.examples.assemble;
22

33
/**
44
* A class without default constructor and with another one with default field
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package org.utbot.examples.assemble.constructors;
1+
package org.utbot.examples.assemble;
22

33
/**
44
* A class with private constructor.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package org.utbot.examples.assemble.constructors;
1+
package org.utbot.examples.assemble;
22

33
/**
44
* A class with a constructor that seems to be complex

utbot-framework-test/src/main/java/org/utbot/examples/assemble/statics/StaticField.java renamed to utbot-framework-test/src/main/java/org/utbot/examples/assemble/StaticField.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package org.utbot.examples.assemble.statics;
1+
package org.utbot.examples.assemble;
22

33
/**
44
* A class with primitive constructor and static field

utbot-framework-test/src/main/java/org/utbot/examples/assemble/arrays/MethodUnderTest.java renamed to utbot-framework-test/src/main/java/org/utbot/examples/assemble/another/MethodUnderTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package org.utbot.examples.assemble.arrays;
1+
package org.utbot.examples.assemble.another;
22

33
/**
44
* A test class with fake method under test.

utbot-framework-test/src/main/java/org/utbot/examples/assemble/defaults/DefaultPackagePrivateField.java

Lines changed: 0 additions & 5 deletions
This file was deleted.

utbot-framework-test/src/main/java/org/utbot/examples/manual/examples/ArrayOfComplexArraysExample.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package org.utbot.examples.manual.examples;
22

3-
import org.utbot.examples.assemble.arrays.ArrayOfComplexArrays;
3+
import org.utbot.examples.assemble.ArrayOfComplexArrays;
44

55
public class ArrayOfComplexArraysExample {
66
public int getValue(ArrayOfComplexArrays a) {

utbot-framework-test/src/main/java/org/utbot/examples/manual/examples/ArrayOfPrimitiveArraysExample.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package org.utbot.examples.manual.examples;
22

3-
import org.utbot.examples.assemble.arrays.ArrayOfPrimitiveArrays;
3+
import org.utbot.examples.assemble.ArrayOfPrimitiveArrays;
44

55
public class ArrayOfPrimitiveArraysExample {
66
int assign10(ArrayOfPrimitiveArrays a) {

utbot-framework-test/src/main/java/org/utbot/examples/manual/examples/AssignedArrayExample.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package org.utbot.examples.manual.examples;
22

3-
import org.utbot.examples.assemble.arrays.AssignedArray;
3+
import org.utbot.examples.assemble.AssignedArray;
44

55
public class AssignedArrayExample {
66
public void foo(AssignedArray aa) {

utbot-framework-test/src/test/java/org/utbot/examples/manual/UtBotJavaApiTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99
import org.utbot.common.PathUtil;
1010
import org.utbot.examples.assemble.DirectAccess;
1111
import org.utbot.examples.assemble.PrimitiveFields;
12-
import org.utbot.examples.assemble.arrays.ArrayOfComplexArrays;
13-
import org.utbot.examples.assemble.arrays.ArrayOfPrimitiveArrays;
14-
import org.utbot.examples.assemble.arrays.AssignedArray;
15-
import org.utbot.examples.assemble.arrays.ComplexArray;
12+
import org.utbot.examples.assemble.ArrayOfComplexArrays;
13+
import org.utbot.examples.assemble.ArrayOfPrimitiveArrays;
14+
import org.utbot.examples.assemble.AssignedArray;
15+
import org.utbot.examples.assemble.ComplexArray;
1616
import org.utbot.examples.manual.examples.*;
1717
import org.utbot.examples.manual.examples.customer.B;
1818
import org.utbot.examples.manual.examples.customer.C;

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

Lines changed: 25 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -16,27 +16,27 @@ import org.utbot.examples.assemble.ListItem
1616
import org.utbot.examples.assemble.NoModifier
1717
import org.utbot.examples.assemble.PackagePrivateFields
1818
import org.utbot.examples.assemble.PrimitiveFields
19-
import org.utbot.examples.assemble.arrays.ArrayOfComplexArrays
20-
import org.utbot.examples.assemble.arrays.ArrayOfPrimitiveArrays
21-
import org.utbot.examples.assemble.arrays.AssignedArray
22-
import org.utbot.examples.assemble.arrays.ComplexArray
23-
import org.utbot.examples.assemble.arrays.MethodUnderTest
24-
import org.utbot.examples.assemble.arrays.PrimitiveArray
25-
import org.utbot.examples.assemble.constructors.ComplexConstructor
26-
import org.utbot.examples.assemble.constructors.ComplexConstructorWithSetter
27-
import org.utbot.examples.assemble.constructors.ConstructorModifyingStatic
28-
import org.utbot.examples.assemble.constructors.InheritComplexConstructor
29-
import org.utbot.examples.assemble.constructors.InheritPrimitiveConstructor
30-
import org.utbot.examples.assemble.constructors.PrimitiveConstructor
31-
import org.utbot.examples.assemble.constructors.PrimitiveConstructorWithDefaultField
32-
import org.utbot.examples.assemble.constructors.PrivateConstructor
33-
import org.utbot.examples.assemble.constructors.PseudoComplexConstructor
34-
import org.utbot.examples.assemble.defaults.DefaultField
35-
import org.utbot.examples.assemble.defaults.DefaultFieldModifiedInConstructor
36-
import org.utbot.examples.assemble.defaults.DefaultFieldWithDirectAccessor
37-
import org.utbot.examples.assemble.defaults.DefaultFieldWithSetter
38-
import org.utbot.examples.assemble.defaults.DefaultPackagePrivateField
39-
import org.utbot.examples.assemble.statics.StaticField
19+
import org.utbot.examples.assemble.ArrayOfComplexArrays
20+
import org.utbot.examples.assemble.ArrayOfPrimitiveArrays
21+
import org.utbot.examples.assemble.AssignedArray
22+
import org.utbot.examples.assemble.ComplexArray
23+
import org.utbot.examples.assemble.another.MethodUnderTest
24+
import org.utbot.examples.assemble.PrimitiveArray
25+
import org.utbot.examples.assemble.ComplexConstructor
26+
import org.utbot.examples.assemble.ComplexConstructorWithSetter
27+
import org.utbot.examples.assemble.ConstructorModifyingStatic
28+
import org.utbot.examples.assemble.InheritComplexConstructor
29+
import org.utbot.examples.assemble.InheritPrimitiveConstructor
30+
import org.utbot.examples.assemble.PrimitiveConstructor
31+
import org.utbot.examples.assemble.PrimitiveConstructorWithDefaultField
32+
import org.utbot.examples.assemble.PrivateConstructor
33+
import org.utbot.examples.assemble.PseudoComplexConstructor
34+
import org.utbot.examples.assemble.DefaultField
35+
import org.utbot.examples.assemble.DefaultFieldModifiedInConstructor
36+
import org.utbot.examples.assemble.DefaultFieldWithDirectAccessor
37+
import org.utbot.examples.assemble.DefaultFieldWithSetter
38+
import org.utbot.examples.assemble.DefaultPackagePrivateField
39+
import org.utbot.examples.assemble.StaticField
4040
import org.utbot.framework.plugin.api.ClassId
4141
import org.utbot.framework.plugin.api.ExecutableId
4242
import org.utbot.framework.plugin.api.FieldId
@@ -58,7 +58,6 @@ import org.utbot.framework.util.SootUtils
5858
import org.utbot.framework.util.instanceCounter
5959
import org.utbot.framework.util.modelIdCounter
6060
import kotlin.reflect.full.functions
61-
import org.utbot.examples.assemble.*
6261
import org.utbot.framework.codegen.model.constructor.util.arrayTypeOf
6362

6463
/**
@@ -150,8 +149,7 @@ class AssembleModelGeneratorTests {
150149
fields(testClassId, "a" to 5, "b" to 3)
151150
)
152151

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

156154
createModelAndAssert(compositeModel, null, methodFromAnotherPackage.executableId)
157155
}
@@ -413,7 +411,7 @@ class AssembleModelGeneratorTests {
413411
val baseClassId = PrimitiveFields::class.id
414412

415413
val thisFields = fields(inheritedFieldClassId, "i" to 5, "d" to 3.0)
416-
val baseFields = fields(baseClassId, "a" to 2, "b" to 4)
414+
val baseFields = fields(baseClassId, "b" to 4)
417415

418416
val compositeModel = UtCompositeModel(
419417
modelIdCounter.incrementAndGet(),
@@ -425,7 +423,6 @@ class AssembleModelGeneratorTests {
425423
val v1 = statementsChain.addExpectedVariableDecl<InheritedField>()
426424
statementsChain.add("$v1." + ("i" `=` 5))
427425
statementsChain.add("$v1." + ("d" `=` 3.0))
428-
statementsChain.add("$v1." + addExpectedSetter("a", 2))
429426
statementsChain.add("$v1." + ("b" `=` 4))
430427

431428
val expectedRepresentation = printExpectedModel(inheritedFieldClassId.simpleName, v1, statementsChain)
@@ -1448,9 +1445,9 @@ class AssembleModelGeneratorTests {
14481445
private fun createModelsAndAssert(
14491446
models: List<UtModel>,
14501447
expectedModelRepresentations: List<String?>,
1451-
assembleTestUtils: ExecutableId = AssembleTestUtils::class.id.allMethods.first(),
1448+
assembleTestDummyMethod: ExecutableId = AssembleTestUtils::class.id.allMethods.first(),
14521449
) {
1453-
val modelsMap = AssembleModelGenerator(assembleTestUtils.classId.packageName).createAssembleModels(models)
1450+
val modelsMap = AssembleModelGenerator(assembleTestDummyMethod.classId.packageName).createAssembleModels(models)
14541451
//we sort values to fix order of models somehow (IdentityHashMap does not guarantee the order)
14551452
val assembleModels = modelsMap.values
14561453
.filterIsInstance<UtAssembleModel>()

utbot-framework-test/src/test/kotlin/org/utbot/framework/modificators/UtBotFieldModificatorsTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ internal class UtBotFieldModificatorsTest {
192192

193193
//We use sorting here to make comparing with sorted in advance expected collections easier
194194
private fun runFieldModificatorsSearch(analysisMode: AnalysisMode) =
195-
fieldsModificatorsSearcher.findModificators(analysisMode, PrimitiveModifications::class.java.packageName)
195+
fieldsModificatorsSearcher.findModificators(analysisMode)
196196
.map { (key, value) ->
197197
val modificatorNames = value.filterNot { it.name.startsWith("direct_set_") }.map { it.name }
198198
key.name to modificatorNames.toSortedSet()

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import org.utbot.framework.plugin.api.UtArrayModel
88
import org.utbot.framework.plugin.api.UtClassRefModel
99
import org.utbot.framework.plugin.api.UtCompositeModel
1010
import org.utbot.framework.plugin.api.UtModel
11+
import org.utbot.framework.plugin.api.util.executableId
1112
import org.utbot.framework.plugin.api.util.id
1213
import java.lang.reflect.Field
1314
import java.lang.reflect.Method

0 commit comments

Comments
 (0)