diff --git a/utbot-framework-test/src/main/java/org/utbot/examples/assemble/arrays/ArrayOfComplexArrays.java b/utbot-framework-test/src/main/java/org/utbot/examples/assemble/ArrayOfComplexArrays.java similarity index 78% rename from utbot-framework-test/src/main/java/org/utbot/examples/assemble/arrays/ArrayOfComplexArrays.java rename to utbot-framework-test/src/main/java/org/utbot/examples/assemble/ArrayOfComplexArrays.java index 2feaaeac2a..6c3936004c 100644 --- a/utbot-framework-test/src/main/java/org/utbot/examples/assemble/arrays/ArrayOfComplexArrays.java +++ b/utbot-framework-test/src/main/java/org/utbot/examples/assemble/ArrayOfComplexArrays.java @@ -1,4 +1,4 @@ -package org.utbot.examples.assemble.arrays; +package org.utbot.examples.assemble; /** * A class with array of objects that are arrays of complex fields themselves. diff --git a/utbot-framework-test/src/main/java/org/utbot/examples/assemble/arrays/ArrayOfPrimitiveArrays.java b/utbot-framework-test/src/main/java/org/utbot/examples/assemble/ArrayOfPrimitiveArrays.java similarity index 73% rename from utbot-framework-test/src/main/java/org/utbot/examples/assemble/arrays/ArrayOfPrimitiveArrays.java rename to utbot-framework-test/src/main/java/org/utbot/examples/assemble/ArrayOfPrimitiveArrays.java index 7339f09ad3..de7061c090 100644 --- a/utbot-framework-test/src/main/java/org/utbot/examples/assemble/arrays/ArrayOfPrimitiveArrays.java +++ b/utbot-framework-test/src/main/java/org/utbot/examples/assemble/ArrayOfPrimitiveArrays.java @@ -1,4 +1,4 @@ -package org.utbot.examples.assemble.arrays; +package org.utbot.examples.assemble; /** * A class with a two-dimensional array field. diff --git a/utbot-framework-test/src/main/java/org/utbot/examples/assemble/arrays/AssignedArray.java b/utbot-framework-test/src/main/java/org/utbot/examples/assemble/AssignedArray.java similarity index 73% rename from utbot-framework-test/src/main/java/org/utbot/examples/assemble/arrays/AssignedArray.java rename to utbot-framework-test/src/main/java/org/utbot/examples/assemble/AssignedArray.java index 76235ed977..701f90f318 100644 --- a/utbot-framework-test/src/main/java/org/utbot/examples/assemble/arrays/AssignedArray.java +++ b/utbot-framework-test/src/main/java/org/utbot/examples/assemble/AssignedArray.java @@ -1,4 +1,4 @@ -package org.utbot.examples.assemble.arrays; +package org.utbot.examples.assemble; /** * A class with an array with a default value. diff --git a/utbot-framework-test/src/main/java/org/utbot/examples/assemble/arrays/ComplexArray.java b/utbot-framework-test/src/main/java/org/utbot/examples/assemble/ComplexArray.java similarity index 82% rename from utbot-framework-test/src/main/java/org/utbot/examples/assemble/arrays/ComplexArray.java rename to utbot-framework-test/src/main/java/org/utbot/examples/assemble/ComplexArray.java index 7f60a0377f..f1634add0a 100644 --- a/utbot-framework-test/src/main/java/org/utbot/examples/assemble/arrays/ComplexArray.java +++ b/utbot-framework-test/src/main/java/org/utbot/examples/assemble/ComplexArray.java @@ -1,4 +1,4 @@ -package org.utbot.examples.assemble.arrays; +package org.utbot.examples.assemble; import org.utbot.examples.assemble.PrimitiveFields; diff --git a/utbot-framework-test/src/main/java/org/utbot/examples/assemble/constructors/ComplexConstructor.java b/utbot-framework-test/src/main/java/org/utbot/examples/assemble/ComplexConstructor.java similarity index 85% rename from utbot-framework-test/src/main/java/org/utbot/examples/assemble/constructors/ComplexConstructor.java rename to utbot-framework-test/src/main/java/org/utbot/examples/assemble/ComplexConstructor.java index c6e45ff0ea..27f68f07d7 100644 --- a/utbot-framework-test/src/main/java/org/utbot/examples/assemble/constructors/ComplexConstructor.java +++ b/utbot-framework-test/src/main/java/org/utbot/examples/assemble/ComplexConstructor.java @@ -1,4 +1,4 @@ -package org.utbot.examples.assemble.constructors; +package org.utbot.examples.assemble; /** * A class without default constructor and with complex one. diff --git a/utbot-framework-test/src/main/java/org/utbot/examples/assemble/constructors/ComplexConstructorWithSetter.java b/utbot-framework-test/src/main/java/org/utbot/examples/assemble/ComplexConstructorWithSetter.java similarity index 88% rename from utbot-framework-test/src/main/java/org/utbot/examples/assemble/constructors/ComplexConstructorWithSetter.java rename to utbot-framework-test/src/main/java/org/utbot/examples/assemble/ComplexConstructorWithSetter.java index 72111a23e6..b4b83c4137 100644 --- a/utbot-framework-test/src/main/java/org/utbot/examples/assemble/constructors/ComplexConstructorWithSetter.java +++ b/utbot-framework-test/src/main/java/org/utbot/examples/assemble/ComplexConstructorWithSetter.java @@ -1,4 +1,4 @@ -package org.utbot.examples.assemble.constructors; +package org.utbot.examples.assemble; /** * A class without default constructor and with complex one, diff --git a/utbot-framework-test/src/main/java/org/utbot/examples/assemble/constructors/ConstructorModifyingStatic.java b/utbot-framework-test/src/main/java/org/utbot/examples/assemble/ConstructorModifyingStatic.java similarity index 76% rename from utbot-framework-test/src/main/java/org/utbot/examples/assemble/constructors/ConstructorModifyingStatic.java rename to utbot-framework-test/src/main/java/org/utbot/examples/assemble/ConstructorModifyingStatic.java index eba2e01328..00a567ab52 100644 --- a/utbot-framework-test/src/main/java/org/utbot/examples/assemble/constructors/ConstructorModifyingStatic.java +++ b/utbot-framework-test/src/main/java/org/utbot/examples/assemble/ConstructorModifyingStatic.java @@ -1,4 +1,4 @@ -package org.utbot.examples.assemble.constructors; +package org.utbot.examples.assemble; public class ConstructorModifyingStatic { diff --git a/utbot-framework-test/src/main/java/org/utbot/examples/assemble/defaults/DefaultField.java b/utbot-framework-test/src/main/java/org/utbot/examples/assemble/DefaultField.java similarity index 75% rename from utbot-framework-test/src/main/java/org/utbot/examples/assemble/defaults/DefaultField.java rename to utbot-framework-test/src/main/java/org/utbot/examples/assemble/DefaultField.java index 396f262b5f..09ef14422a 100644 --- a/utbot-framework-test/src/main/java/org/utbot/examples/assemble/defaults/DefaultField.java +++ b/utbot-framework-test/src/main/java/org/utbot/examples/assemble/DefaultField.java @@ -1,4 +1,4 @@ -package org.utbot.examples.assemble.defaults; +package org.utbot.examples.assemble; /** * A class with a field with default value that is not a default value of type. diff --git a/utbot-framework-test/src/main/java/org/utbot/examples/assemble/defaults/DefaultFieldModifiedInConstructor.java b/utbot-framework-test/src/main/java/org/utbot/examples/assemble/DefaultFieldModifiedInConstructor.java similarity index 75% rename from utbot-framework-test/src/main/java/org/utbot/examples/assemble/defaults/DefaultFieldModifiedInConstructor.java rename to utbot-framework-test/src/main/java/org/utbot/examples/assemble/DefaultFieldModifiedInConstructor.java index d96a23d005..d11d42fc14 100644 --- a/utbot-framework-test/src/main/java/org/utbot/examples/assemble/defaults/DefaultFieldModifiedInConstructor.java +++ b/utbot-framework-test/src/main/java/org/utbot/examples/assemble/DefaultFieldModifiedInConstructor.java @@ -1,7 +1,7 @@ -package org.utbot.examples.assemble.defaults; +package org.utbot.examples.assemble; public class DefaultFieldModifiedInConstructor { - int z; + public int z; @SuppressWarnings("Unused") DefaultFieldModifiedInConstructor(int z_) { diff --git a/utbot-framework-test/src/main/java/org/utbot/examples/assemble/defaults/DefaultFieldWithDirectAccessor.java b/utbot-framework-test/src/main/java/org/utbot/examples/assemble/DefaultFieldWithDirectAccessor.java similarity index 77% rename from utbot-framework-test/src/main/java/org/utbot/examples/assemble/defaults/DefaultFieldWithDirectAccessor.java rename to utbot-framework-test/src/main/java/org/utbot/examples/assemble/DefaultFieldWithDirectAccessor.java index e6ad1e2f92..160b116d0b 100644 --- a/utbot-framework-test/src/main/java/org/utbot/examples/assemble/defaults/DefaultFieldWithDirectAccessor.java +++ b/utbot-framework-test/src/main/java/org/utbot/examples/assemble/DefaultFieldWithDirectAccessor.java @@ -1,4 +1,4 @@ -package org.utbot.examples.assemble.defaults; +package org.utbot.examples.assemble; /** * A class with a field with default value that is not a default value of type. diff --git a/utbot-framework-test/src/main/java/org/utbot/examples/assemble/defaults/DefaultFieldWithSetter.java b/utbot-framework-test/src/main/java/org/utbot/examples/assemble/DefaultFieldWithSetter.java similarity index 82% rename from utbot-framework-test/src/main/java/org/utbot/examples/assemble/defaults/DefaultFieldWithSetter.java rename to utbot-framework-test/src/main/java/org/utbot/examples/assemble/DefaultFieldWithSetter.java index 65896c382a..d1ec15f20c 100644 --- a/utbot-framework-test/src/main/java/org/utbot/examples/assemble/defaults/DefaultFieldWithSetter.java +++ b/utbot-framework-test/src/main/java/org/utbot/examples/assemble/DefaultFieldWithSetter.java @@ -1,4 +1,4 @@ -package org.utbot.examples.assemble.defaults; +package org.utbot.examples.assemble; /** * A class with a field with setter default value that is not a default value of type. diff --git a/utbot-framework-test/src/main/java/org/utbot/examples/assemble/DefaultPackagePrivateField.java b/utbot-framework-test/src/main/java/org/utbot/examples/assemble/DefaultPackagePrivateField.java new file mode 100644 index 0000000000..43d9b7ad25 --- /dev/null +++ b/utbot-framework-test/src/main/java/org/utbot/examples/assemble/DefaultPackagePrivateField.java @@ -0,0 +1,9 @@ +package org.utbot.examples.assemble; + +/** + * Need to be located at the same package as [AssembleTestUtils] + * because requires a setter for package-private field. + */ +public class DefaultPackagePrivateField { + int z = 10; +} diff --git a/utbot-framework-test/src/main/java/org/utbot/examples/assemble/constructors/InheritComplexConstructor.java b/utbot-framework-test/src/main/java/org/utbot/examples/assemble/InheritComplexConstructor.java similarity index 87% rename from utbot-framework-test/src/main/java/org/utbot/examples/assemble/constructors/InheritComplexConstructor.java rename to utbot-framework-test/src/main/java/org/utbot/examples/assemble/InheritComplexConstructor.java index 417c686742..c3521d8e04 100644 --- a/utbot-framework-test/src/main/java/org/utbot/examples/assemble/constructors/InheritComplexConstructor.java +++ b/utbot-framework-test/src/main/java/org/utbot/examples/assemble/InheritComplexConstructor.java @@ -1,4 +1,4 @@ -package org.utbot.examples.assemble.constructors; +package org.utbot.examples.assemble; /** * A class with a primitive constructor that inherits a complex constructor. diff --git a/utbot-framework-test/src/main/java/org/utbot/examples/assemble/constructors/InheritPrimitiveConstructor.java b/utbot-framework-test/src/main/java/org/utbot/examples/assemble/InheritPrimitiveConstructor.java similarity index 87% rename from utbot-framework-test/src/main/java/org/utbot/examples/assemble/constructors/InheritPrimitiveConstructor.java rename to utbot-framework-test/src/main/java/org/utbot/examples/assemble/InheritPrimitiveConstructor.java index 835e5e991c..c5fc633d45 100644 --- a/utbot-framework-test/src/main/java/org/utbot/examples/assemble/constructors/InheritPrimitiveConstructor.java +++ b/utbot-framework-test/src/main/java/org/utbot/examples/assemble/InheritPrimitiveConstructor.java @@ -1,4 +1,4 @@ -package org.utbot.examples.assemble.constructors; +package org.utbot.examples.assemble; /** * A class with a primitive constructor that inherits another primitive constructor. diff --git a/utbot-framework-test/src/main/java/org/utbot/examples/assemble/arrays/PrimitiveArray.java b/utbot-framework-test/src/main/java/org/utbot/examples/assemble/PrimitiveArray.java similarity index 73% rename from utbot-framework-test/src/main/java/org/utbot/examples/assemble/arrays/PrimitiveArray.java rename to utbot-framework-test/src/main/java/org/utbot/examples/assemble/PrimitiveArray.java index 5cb668b128..a07b5aa7a4 100644 --- a/utbot-framework-test/src/main/java/org/utbot/examples/assemble/arrays/PrimitiveArray.java +++ b/utbot-framework-test/src/main/java/org/utbot/examples/assemble/PrimitiveArray.java @@ -1,4 +1,4 @@ -package org.utbot.examples.assemble.arrays; +package org.utbot.examples.assemble; /** * A class with an array with elements of primitive type. diff --git a/utbot-framework-test/src/main/java/org/utbot/examples/assemble/constructors/PrimitiveConstructor.java b/utbot-framework-test/src/main/java/org/utbot/examples/assemble/PrimitiveConstructor.java similarity index 85% rename from utbot-framework-test/src/main/java/org/utbot/examples/assemble/constructors/PrimitiveConstructor.java rename to utbot-framework-test/src/main/java/org/utbot/examples/assemble/PrimitiveConstructor.java index 4750277578..9d7c3595e4 100644 --- a/utbot-framework-test/src/main/java/org/utbot/examples/assemble/constructors/PrimitiveConstructor.java +++ b/utbot-framework-test/src/main/java/org/utbot/examples/assemble/PrimitiveConstructor.java @@ -1,4 +1,4 @@ -package org.utbot.examples.assemble.constructors; +package org.utbot.examples.assemble; /** * A class without default constructor and with primitive one. diff --git a/utbot-framework-test/src/main/java/org/utbot/examples/assemble/constructors/PrimitiveConstructorWithDefaultField.java b/utbot-framework-test/src/main/java/org/utbot/examples/assemble/PrimitiveConstructorWithDefaultField.java similarity index 84% rename from utbot-framework-test/src/main/java/org/utbot/examples/assemble/constructors/PrimitiveConstructorWithDefaultField.java rename to utbot-framework-test/src/main/java/org/utbot/examples/assemble/PrimitiveConstructorWithDefaultField.java index 34d257cee4..b39adb250f 100644 --- a/utbot-framework-test/src/main/java/org/utbot/examples/assemble/constructors/PrimitiveConstructorWithDefaultField.java +++ b/utbot-framework-test/src/main/java/org/utbot/examples/assemble/PrimitiveConstructorWithDefaultField.java @@ -1,4 +1,4 @@ -package org.utbot.examples.assemble.constructors; +package org.utbot.examples.assemble; /** * A class without default constructor and with another one with default field diff --git a/utbot-framework-test/src/main/java/org/utbot/examples/assemble/constructors/PrivateConstructor.java b/utbot-framework-test/src/main/java/org/utbot/examples/assemble/PrivateConstructor.java similarity index 76% rename from utbot-framework-test/src/main/java/org/utbot/examples/assemble/constructors/PrivateConstructor.java rename to utbot-framework-test/src/main/java/org/utbot/examples/assemble/PrivateConstructor.java index 4f0d1438f4..2e4d765c92 100644 --- a/utbot-framework-test/src/main/java/org/utbot/examples/assemble/constructors/PrivateConstructor.java +++ b/utbot-framework-test/src/main/java/org/utbot/examples/assemble/PrivateConstructor.java @@ -1,4 +1,4 @@ -package org.utbot.examples.assemble.constructors; +package org.utbot.examples.assemble; /** * A class with private constructor. diff --git a/utbot-framework-test/src/main/java/org/utbot/examples/assemble/constructors/PseudoComplexConstructor.java b/utbot-framework-test/src/main/java/org/utbot/examples/assemble/PseudoComplexConstructor.java similarity index 84% rename from utbot-framework-test/src/main/java/org/utbot/examples/assemble/constructors/PseudoComplexConstructor.java rename to utbot-framework-test/src/main/java/org/utbot/examples/assemble/PseudoComplexConstructor.java index f0a14772e3..4569566bc5 100644 --- a/utbot-framework-test/src/main/java/org/utbot/examples/assemble/constructors/PseudoComplexConstructor.java +++ b/utbot-framework-test/src/main/java/org/utbot/examples/assemble/PseudoComplexConstructor.java @@ -1,4 +1,4 @@ -package org.utbot.examples.assemble.constructors; +package org.utbot.examples.assemble; /** * A class with a constructor that seems to be complex diff --git a/utbot-framework-test/src/main/java/org/utbot/examples/assemble/statics/StaticField.java b/utbot-framework-test/src/main/java/org/utbot/examples/assemble/StaticField.java similarity index 86% rename from utbot-framework-test/src/main/java/org/utbot/examples/assemble/statics/StaticField.java rename to utbot-framework-test/src/main/java/org/utbot/examples/assemble/StaticField.java index 4019957f5d..1653a6d3fd 100644 --- a/utbot-framework-test/src/main/java/org/utbot/examples/assemble/statics/StaticField.java +++ b/utbot-framework-test/src/main/java/org/utbot/examples/assemble/StaticField.java @@ -1,4 +1,4 @@ -package org.utbot.examples.assemble.statics; +package org.utbot.examples.assemble; /** * A class with primitive constructor and static field diff --git a/utbot-framework-test/src/main/java/org/utbot/examples/assemble/arrays/MethodUnderTest.java b/utbot-framework-test/src/main/java/org/utbot/examples/assemble/another/MethodUnderTest.java similarity index 74% rename from utbot-framework-test/src/main/java/org/utbot/examples/assemble/arrays/MethodUnderTest.java rename to utbot-framework-test/src/main/java/org/utbot/examples/assemble/another/MethodUnderTest.java index dad8f455cf..6848f644dc 100644 --- a/utbot-framework-test/src/main/java/org/utbot/examples/assemble/arrays/MethodUnderTest.java +++ b/utbot-framework-test/src/main/java/org/utbot/examples/assemble/another/MethodUnderTest.java @@ -1,4 +1,4 @@ -package org.utbot.examples.assemble.arrays; +package org.utbot.examples.assemble.another; /** * A test class with fake method under test. diff --git a/utbot-framework-test/src/main/java/org/utbot/examples/assemble/defaults/DefaultPackagePrivateField.java b/utbot-framework-test/src/main/java/org/utbot/examples/assemble/defaults/DefaultPackagePrivateField.java deleted file mode 100644 index e28bf48c35..0000000000 --- a/utbot-framework-test/src/main/java/org/utbot/examples/assemble/defaults/DefaultPackagePrivateField.java +++ /dev/null @@ -1,5 +0,0 @@ -package org.utbot.examples.assemble.defaults; - -public class DefaultPackagePrivateField { - int z = 10; -} diff --git a/utbot-framework-test/src/main/java/org/utbot/examples/manual/examples/ArrayOfComplexArraysExample.java b/utbot-framework-test/src/main/java/org/utbot/examples/manual/examples/ArrayOfComplexArraysExample.java index 4f1a0be423..12d8240f08 100644 --- a/utbot-framework-test/src/main/java/org/utbot/examples/manual/examples/ArrayOfComplexArraysExample.java +++ b/utbot-framework-test/src/main/java/org/utbot/examples/manual/examples/ArrayOfComplexArraysExample.java @@ -1,6 +1,6 @@ package org.utbot.examples.manual.examples; -import org.utbot.examples.assemble.arrays.ArrayOfComplexArrays; +import org.utbot.examples.assemble.ArrayOfComplexArrays; public class ArrayOfComplexArraysExample { public int getValue(ArrayOfComplexArrays a) { diff --git a/utbot-framework-test/src/main/java/org/utbot/examples/manual/examples/ArrayOfPrimitiveArraysExample.java b/utbot-framework-test/src/main/java/org/utbot/examples/manual/examples/ArrayOfPrimitiveArraysExample.java index 0ca098705f..189a25de6e 100644 --- a/utbot-framework-test/src/main/java/org/utbot/examples/manual/examples/ArrayOfPrimitiveArraysExample.java +++ b/utbot-framework-test/src/main/java/org/utbot/examples/manual/examples/ArrayOfPrimitiveArraysExample.java @@ -1,6 +1,6 @@ package org.utbot.examples.manual.examples; -import org.utbot.examples.assemble.arrays.ArrayOfPrimitiveArrays; +import org.utbot.examples.assemble.ArrayOfPrimitiveArrays; public class ArrayOfPrimitiveArraysExample { int assign10(ArrayOfPrimitiveArrays a) { diff --git a/utbot-framework-test/src/main/java/org/utbot/examples/manual/examples/AssignedArrayExample.java b/utbot-framework-test/src/main/java/org/utbot/examples/manual/examples/AssignedArrayExample.java index c4b5b0f032..45e142df56 100644 --- a/utbot-framework-test/src/main/java/org/utbot/examples/manual/examples/AssignedArrayExample.java +++ b/utbot-framework-test/src/main/java/org/utbot/examples/manual/examples/AssignedArrayExample.java @@ -1,6 +1,6 @@ package org.utbot.examples.manual.examples; -import org.utbot.examples.assemble.arrays.AssignedArray; +import org.utbot.examples.assemble.AssignedArray; public class AssignedArrayExample { public void foo(AssignedArray aa) { diff --git a/utbot-framework-test/src/test/java/org/utbot/examples/manual/UtBotJavaApiTest.java b/utbot-framework-test/src/test/java/org/utbot/examples/manual/UtBotJavaApiTest.java index 3115f37fca..b04512aafc 100644 --- a/utbot-framework-test/src/test/java/org/utbot/examples/manual/UtBotJavaApiTest.java +++ b/utbot-framework-test/src/test/java/org/utbot/examples/manual/UtBotJavaApiTest.java @@ -9,10 +9,10 @@ import org.utbot.common.PathUtil; import org.utbot.examples.assemble.DirectAccess; import org.utbot.examples.assemble.PrimitiveFields; -import org.utbot.examples.assemble.arrays.ArrayOfComplexArrays; -import org.utbot.examples.assemble.arrays.ArrayOfPrimitiveArrays; -import org.utbot.examples.assemble.arrays.AssignedArray; -import org.utbot.examples.assemble.arrays.ComplexArray; +import org.utbot.examples.assemble.ArrayOfComplexArrays; +import org.utbot.examples.assemble.ArrayOfPrimitiveArrays; +import org.utbot.examples.assemble.AssignedArray; +import org.utbot.examples.assemble.ComplexArray; import org.utbot.examples.manual.examples.*; import org.utbot.examples.manual.examples.customer.B; import org.utbot.examples.manual.examples.customer.C; diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/framework/assemble/AssembleModelGeneratorTests.kt b/utbot-framework-test/src/test/kotlin/org/utbot/framework/assemble/AssembleModelGeneratorTests.kt index 278cfac453..7a252bb33e 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/framework/assemble/AssembleModelGeneratorTests.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/framework/assemble/AssembleModelGeneratorTests.kt @@ -16,27 +16,27 @@ import org.utbot.examples.assemble.ListItem import org.utbot.examples.assemble.NoModifier import org.utbot.examples.assemble.PackagePrivateFields import org.utbot.examples.assemble.PrimitiveFields -import org.utbot.examples.assemble.arrays.ArrayOfComplexArrays -import org.utbot.examples.assemble.arrays.ArrayOfPrimitiveArrays -import org.utbot.examples.assemble.arrays.AssignedArray -import org.utbot.examples.assemble.arrays.ComplexArray -import org.utbot.examples.assemble.arrays.MethodUnderTest -import org.utbot.examples.assemble.arrays.PrimitiveArray -import org.utbot.examples.assemble.constructors.ComplexConstructor -import org.utbot.examples.assemble.constructors.ComplexConstructorWithSetter -import org.utbot.examples.assemble.constructors.ConstructorModifyingStatic -import org.utbot.examples.assemble.constructors.InheritComplexConstructor -import org.utbot.examples.assemble.constructors.InheritPrimitiveConstructor -import org.utbot.examples.assemble.constructors.PrimitiveConstructor -import org.utbot.examples.assemble.constructors.PrimitiveConstructorWithDefaultField -import org.utbot.examples.assemble.constructors.PrivateConstructor -import org.utbot.examples.assemble.constructors.PseudoComplexConstructor -import org.utbot.examples.assemble.defaults.DefaultField -import org.utbot.examples.assemble.defaults.DefaultFieldModifiedInConstructor -import org.utbot.examples.assemble.defaults.DefaultFieldWithDirectAccessor -import org.utbot.examples.assemble.defaults.DefaultFieldWithSetter -import org.utbot.examples.assemble.defaults.DefaultPackagePrivateField -import org.utbot.examples.assemble.statics.StaticField +import org.utbot.examples.assemble.ArrayOfComplexArrays +import org.utbot.examples.assemble.ArrayOfPrimitiveArrays +import org.utbot.examples.assemble.AssignedArray +import org.utbot.examples.assemble.ComplexArray +import org.utbot.examples.assemble.another.MethodUnderTest +import org.utbot.examples.assemble.PrimitiveArray +import org.utbot.examples.assemble.ComplexConstructor +import org.utbot.examples.assemble.ComplexConstructorWithSetter +import org.utbot.examples.assemble.ConstructorModifyingStatic +import org.utbot.examples.assemble.InheritComplexConstructor +import org.utbot.examples.assemble.InheritPrimitiveConstructor +import org.utbot.examples.assemble.PrimitiveConstructor +import org.utbot.examples.assemble.PrimitiveConstructorWithDefaultField +import org.utbot.examples.assemble.PrivateConstructor +import org.utbot.examples.assemble.PseudoComplexConstructor +import org.utbot.examples.assemble.DefaultField +import org.utbot.examples.assemble.DefaultFieldModifiedInConstructor +import org.utbot.examples.assemble.DefaultFieldWithDirectAccessor +import org.utbot.examples.assemble.DefaultFieldWithSetter +import org.utbot.examples.assemble.DefaultPackagePrivateField +import org.utbot.examples.assemble.StaticField import org.utbot.framework.plugin.api.ClassId import org.utbot.framework.plugin.api.ExecutableId import org.utbot.framework.plugin.api.FieldId @@ -58,7 +58,6 @@ import org.utbot.framework.util.SootUtils import org.utbot.framework.util.instanceCounter import org.utbot.framework.util.modelIdCounter import kotlin.reflect.full.functions -import org.utbot.examples.assemble.* import org.utbot.framework.codegen.model.constructor.util.arrayTypeOf /** @@ -150,8 +149,7 @@ class AssembleModelGeneratorTests { fields(testClassId, "a" to 5, "b" to 3) ) - val methodFromAnotherPackage = - MethodUnderTest::class.functions.first() + val methodFromAnotherPackage = MethodUnderTest::class.functions.first() createModelAndAssert(compositeModel, null, methodFromAnotherPackage.executableId) } @@ -413,7 +411,7 @@ class AssembleModelGeneratorTests { val baseClassId = PrimitiveFields::class.id val thisFields = fields(inheritedFieldClassId, "i" to 5, "d" to 3.0) - val baseFields = fields(baseClassId, "a" to 2, "b" to 4) + val baseFields = fields(baseClassId, "b" to 4) val compositeModel = UtCompositeModel( modelIdCounter.incrementAndGet(), @@ -425,7 +423,6 @@ class AssembleModelGeneratorTests { val v1 = statementsChain.addExpectedVariableDecl() statementsChain.add("$v1." + ("i" `=` 5)) statementsChain.add("$v1." + ("d" `=` 3.0)) - statementsChain.add("$v1." + addExpectedSetter("a", 2)) statementsChain.add("$v1." + ("b" `=` 4)) val expectedRepresentation = printExpectedModel(inheritedFieldClassId.simpleName, v1, statementsChain) @@ -1448,9 +1445,9 @@ class AssembleModelGeneratorTests { private fun createModelsAndAssert( models: List, expectedModelRepresentations: List, - assembleTestUtils: ExecutableId = AssembleTestUtils::class.id.allMethods.first(), + assembleTestDummyMethod: ExecutableId = AssembleTestUtils::class.id.allMethods.first(), ) { - val modelsMap = AssembleModelGenerator(assembleTestUtils.classId.packageName).createAssembleModels(models) + val modelsMap = AssembleModelGenerator(assembleTestDummyMethod.classId.packageName).createAssembleModels(models) //we sort values to fix order of models somehow (IdentityHashMap does not guarantee the order) val assembleModels = modelsMap.values .filterIsInstance() diff --git a/utbot-framework-test/src/test/kotlin/org/utbot/framework/modificators/UtBotFieldModificatorsTest.kt b/utbot-framework-test/src/test/kotlin/org/utbot/framework/modificators/UtBotFieldModificatorsTest.kt index a95244365a..1b8eedaa93 100644 --- a/utbot-framework-test/src/test/kotlin/org/utbot/framework/modificators/UtBotFieldModificatorsTest.kt +++ b/utbot-framework-test/src/test/kotlin/org/utbot/framework/modificators/UtBotFieldModificatorsTest.kt @@ -192,7 +192,7 @@ internal class UtBotFieldModificatorsTest { //We use sorting here to make comparing with sorted in advance expected collections easier private fun runFieldModificatorsSearch(analysisMode: AnalysisMode) = - fieldsModificatorsSearcher.findModificators(analysisMode, PrimitiveModifications::class.java.packageName) + fieldsModificatorsSearcher.findModificators(analysisMode) .map { (key, value) -> val modificatorNames = value.filterNot { it.name.startsWith("direct_set_") }.map { it.name } key.name to modificatorNames.toSortedSet() diff --git a/utbot-framework/src/main/kotlin/org/utbot/external/api/UtModelFactory.kt b/utbot-framework/src/main/kotlin/org/utbot/external/api/UtModelFactory.kt index ec12b3319c..cc11e50b98 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/external/api/UtModelFactory.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/external/api/UtModelFactory.kt @@ -8,6 +8,7 @@ import org.utbot.framework.plugin.api.UtArrayModel import org.utbot.framework.plugin.api.UtClassRefModel import org.utbot.framework.plugin.api.UtCompositeModel import org.utbot.framework.plugin.api.UtModel +import org.utbot.framework.plugin.api.util.executableId import org.utbot.framework.plugin.api.util.id import java.lang.reflect.Field import java.lang.reflect.Method diff --git a/utbot-framework/src/main/kotlin/org/utbot/framework/assemble/AssembleModelGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/framework/assemble/AssembleModelGenerator.kt index edd8b669d1..bd454e3e83 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/framework/assemble/AssembleModelGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/framework/assemble/AssembleModelGenerator.kt @@ -36,6 +36,7 @@ import org.utbot.framework.plugin.api.hasDefaultValue import org.utbot.framework.plugin.api.isMockModel import org.utbot.framework.plugin.api.util.defaultValueModel import org.utbot.framework.plugin.api.util.executableId +import org.utbot.framework.plugin.api.util.isSubtypeOf import org.utbot.framework.plugin.api.util.jClass import org.utbot.framework.util.nextModelName import java.lang.reflect.Constructor @@ -43,13 +44,13 @@ import java.util.IdentityHashMap /** * Creates [UtAssembleModel] from any [UtModel] or it's inner models if possible - * during generation test for [methodUnderTest]. + * during generation test for [basePackageName]. * * Needs utContext be set and Soot be initialized. * * Note: Caches class related information, can be reused if classes don't change. */ -class AssembleModelGenerator(private val methodPackageName: String) { +class AssembleModelGenerator(private val basePackageName: String) { //Instantiated models are stored to avoid cyclic references during reference graph analysis private val instantiatedModels: IdentityHashMap = @@ -171,7 +172,7 @@ class AssembleModelGenerator(private val methodPackageName: String) { private fun assembleModel(utModel: UtModel): UtModel { val collectedCallChain = callChain.toMutableList() - // we cannot create an assemble model for an anonymous class instance + // We cannot create an assemble model for an anonymous class instance if (utModel.classId.isAnonymous) { return utModel } @@ -256,7 +257,7 @@ class AssembleModelGenerator(private val methodPackageName: String) { if (fieldId.isFinal) { throw AssembleException("Final field $fieldId can't be set in an object of the class $classId") } - if (!fieldId.type.isAccessibleFrom(methodPackageName)) { + if (!fieldId.type.isAccessibleFrom(basePackageName)) { throw AssembleException( "Field $fieldId can't be set in an object of the class $classId because its type is inaccessible" ) @@ -265,7 +266,8 @@ class AssembleModelGenerator(private val methodPackageName: String) { if (fieldId in constructorInfo.affectedFields || (fieldId !in constructorInfo.setFields && !fieldModel.hasDefaultValue()) ) { - val modifierCall = modifierCall(this, fieldId, assembleModel(fieldModel)) + val assembledModel = assembleModel(fieldModel) + val modifierCall = modifierCall(this, fieldId, assembledModel) callChain.add(modifierCall) } } @@ -397,10 +399,10 @@ class AssembleModelGenerator(private val methodPackageName: String) { } private val ClassId.isVisible : Boolean - get() = this.isPublic || !this.isPrivate && this.packageName.startsWith(methodPackageName) + get() = this.isPublic || !this.isPrivate && this.packageName == basePackageName private val Constructor<*>.isVisible : Boolean - get() = this.isPublic || !this.isPrivate && this.declaringClass.packageName.startsWith(methodPackageName) + get() = this.isPublic || !this.isPrivate && this.declaringClass.packageName == basePackageName /** * Creates setter or direct setter call to set a field. @@ -414,7 +416,7 @@ class AssembleModelGenerator(private val methodPackageName: String) { ): UtStatementModel { val declaringClassId = fieldId.declaringClass - val modifiers = getOrFindSettersAndDirectAccessors(declaringClassId) + val modifiers = getOrFindSettersAndDirectAccessors(instance.classId) val modifier = modifiers[fieldId] ?: throw AssembleException("No setter for field ${fieldId.name} of class ${declaringClassId.name}") @@ -439,9 +441,7 @@ class AssembleModelGenerator(private val methodPackageName: String) { * Finds setters and direct accessors for fields of particular class. */ private fun findSettersAndDirectAccessors(classId: ClassId): Map { - val allModificatorsOfClass = modificatorsSearcher - .findModificators(SettersAndDirectAccessors, methodPackageName) - .map { it.key to it.value.filter { st -> st.classId == classId } } + val allModificatorsOfClass = modificatorsSearcher.findModificators(SettersAndDirectAccessors) return allModificatorsOfClass .mapNotNull { (fieldId, possibleModificators) -> @@ -457,9 +457,12 @@ class AssembleModelGenerator(private val methodPackageName: String) { */ private fun chooseModificator( fieldId: FieldId, - settersAndDirectAccessors: List + settersAndDirectAccessors: Set, ): StatementId? { - val directAccessors = settersAndDirectAccessors.filterIsInstance() + val directAccessors = settersAndDirectAccessors + .filterIsInstance() + .filter {it.fieldId.isAccessibleFrom(basePackageName) } + if (directAccessors.any()) { return directAccessors.singleOrNull() ?: throw AssembleException( @@ -468,7 +471,9 @@ class AssembleModelGenerator(private val methodPackageName: String) { } if (settersAndDirectAccessors.any()) { - return settersAndDirectAccessors.singleOrNull() + return settersAndDirectAccessors + .filterIsInstance() + .singleOrNull { it.isAccessibleFrom(basePackageName) } ?: throw AssembleException( "Field $fieldId has more than one setter: ${settersAndDirectAccessors.joinToString(" ")}" ) diff --git a/utbot-framework/src/main/kotlin/org/utbot/framework/codegen/model/constructor/tree/CgCallableAccessManager.kt b/utbot-framework/src/main/kotlin/org/utbot/framework/codegen/model/constructor/tree/CgCallableAccessManager.kt index 6e06377f6d..83ea4197f3 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/framework/codegen/model/constructor/tree/CgCallableAccessManager.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/framework/codegen/model/constructor/tree/CgCallableAccessManager.kt @@ -129,6 +129,10 @@ internal class CgCallableAccessManagerImpl(val context: CgContext) : CgCallableA ) } // we can access the field only via reflection + + // NOTE that current implementation works only if field access is located + // in the right part of the assignment. However, obtaining this construction + // as an "l-value" seems to be an error in assemble models or somewhere else. is ReflectionOnly -> fieldId.accessWithReflection(this) } } diff --git a/utbot-framework/src/main/kotlin/org/utbot/framework/codegen/model/util/FieldIdUtil.kt b/utbot-framework/src/main/kotlin/org/utbot/framework/codegen/model/util/FieldIdUtil.kt index 29309d46c6..8df76d3d39 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/framework/codegen/model/util/FieldIdUtil.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/framework/codegen/model/util/FieldIdUtil.kt @@ -13,9 +13,7 @@ import org.utbot.framework.plugin.api.util.voidClassId * * @param context context in which code is generated (it is needed because the method needs to know package and language) */ -// TODO: change parameter from packageName: String to context: CgContext in ClassId.isAccessibleFrom and ExecutableId.isAccessibleFrom ? -private fun FieldId.isAccessibleFrom(context: CgContext): Boolean { - val packageName = context.testClassPackageName +fun FieldId.isAccessibleFrom(packageName: String): Boolean { val isClassAccessible = declaringClass.isAccessibleFrom(packageName) val isAccessibleByVisibility = isPublic || (declaringClass.packageName == packageName && (isPackagePrivate || isProtected)) val isAccessibleFromPackageByModifiers = isAccessibleByVisibility && !isSynthetic @@ -36,7 +34,7 @@ internal infix fun FieldId.canBeReadFrom(context: CgContext): Boolean { return true } - return isAccessibleFrom(context) + return isAccessibleFrom(context.testClassPackageName) } private fun FieldId.canBeSetViaSetterFrom(context: CgContext): Boolean = @@ -49,12 +47,12 @@ internal fun FieldId.canBeSetFrom(context: CgContext): Boolean { if (context.codegenLanguage == CodegenLanguage.KOTLIN) { // Kotlin will allow direct write access if both getter and setter is defined // !isAccessibleFrom(context) is important here because above rule applies to final fields only if they are not accessible in Java terms - if (!isAccessibleFrom(context) && !isStatic && canBeReadViaGetterFrom(context) && canBeSetViaSetterFrom(context)) { + if (!isAccessibleFrom(context.testClassPackageName) && !isStatic && canBeReadViaGetterFrom(context) && canBeSetViaSetterFrom(context)) { return true } } - return isAccessibleFrom(context) && !isFinal + return isAccessibleFrom(context.testClassPackageName) && !isFinal } /** diff --git a/utbot-framework/src/main/kotlin/org/utbot/framework/concrete/UtExecutionInstrumentation.kt b/utbot-framework/src/main/kotlin/org/utbot/framework/concrete/UtExecutionInstrumentation.kt index a787dd2ea7..ab0b69e8b2 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/framework/concrete/UtExecutionInstrumentation.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/framework/concrete/UtExecutionInstrumentation.kt @@ -8,6 +8,7 @@ import org.utbot.framework.UtSettings import org.utbot.framework.assemble.AssembleModelGenerator import org.utbot.framework.plugin.api.Coverage import org.utbot.framework.plugin.api.EnvironmentModels +import org.utbot.framework.plugin.api.ExecutableId import org.utbot.framework.plugin.api.FieldId import org.utbot.framework.plugin.api.Instruction import org.utbot.framework.plugin.api.MissingState @@ -98,9 +99,7 @@ class UtConcreteExecutionResult( * * @return [UtConcreteExecutionResult] with converted models. */ - fun convertToAssemble( - packageName: String - ): UtConcreteExecutionResult { + fun convertToAssemble(packageName: String): UtConcreteExecutionResult { val allModels = collectAllModels() val modelsToAssembleModels = AssembleModelGenerator(packageName).createAssembleModels(allModels) diff --git a/utbot-framework/src/main/kotlin/org/utbot/framework/modifications/DirectAccessorsAnalyzer.kt b/utbot-framework/src/main/kotlin/org/utbot/framework/modifications/DirectAccessorsAnalyzer.kt index e4ccdbd77e..2db28db575 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/framework/modifications/DirectAccessorsAnalyzer.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/framework/modifications/DirectAccessorsAnalyzer.kt @@ -17,19 +17,24 @@ class DirectAccessorsAnalyzer { */ fun collectDirectAccesses(classIds: Set): Set = classIds - .flatMap { classId -> collectFieldsInPackage(classId) } + .flatMap { classId -> collectFields(classId) } .map { fieldId -> DirectFieldAccessId(fieldId.declaringClass, directSetterName(fieldId), fieldId) } .toSet() /** - * Collect all fields with different non-private modifiers from class [classId]. + * Collect all fields with different non-private modifiers + * from class [classId] or it's base classes. */ - private fun collectFieldsInPackage(classId: ClassId): Set { - val clazz = classId.jClass + private fun collectFields(classId: ClassId): Set { + var clazz = classId.jClass val fieldIds = mutableSetOf() - fieldIds += clazz.fields fieldIds += clazz.declaredFields.filterNot { Modifier.isPrivate(it.modifiers) } + while (clazz.superclass != null) { + clazz = clazz.superclass + fieldIds += clazz.declaredFields.filterNot { Modifier.isPrivate(it.modifiers) } + } + return fieldIds.map { it.fieldId }.toSet() } diff --git a/utbot-framework/src/main/kotlin/org/utbot/framework/modifications/UtBotFieldsModificatorsSearcher.kt b/utbot-framework/src/main/kotlin/org/utbot/framework/modifications/UtBotFieldsModificatorsSearcher.kt index 4633995979..dfde6cbb4e 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/framework/modifications/UtBotFieldsModificatorsSearcher.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/framework/modifications/UtBotFieldsModificatorsSearcher.kt @@ -16,24 +16,8 @@ class UtBotFieldsModificatorsSearcher { * Finds field modificators. * * @param analysisMode represents which type of modificators (e.g. setters) are considered. - * @param packageName describes a location of package-private methods that need to be considered. */ - fun findModificators(analysisMode: AnalysisMode, packageName: String? = null): Map> { - val modificators = findModificators(analysisMode) - if (packageName == null) { - return modificators - } - - val filteredModifications = mutableMapOf>() - for ((fieldId, statements) in modificators) { - val filteredStmts = statements.filter { it.classId.packageName.startsWith(packageName) }.toSet() - filteredModifications[fieldId] = filteredStmts - } - - return filteredModifications - } - - private fun findModificators(analysisMode: AnalysisMode): Map> { + fun findModificators(analysisMode: AnalysisMode): Map> { statementsStorage.updateCaches() return findModificatorsInCache(analysisMode) }