Skip to content

Commit 8d83084

Browse files
author
Kamenev Yury
committed
Fixed review issues
1 parent 981a597 commit 8d83084

File tree

13 files changed

+188
-178
lines changed

13 files changed

+188
-178
lines changed

utbot-framework/src/main/java/org/utbot/engine/overrides/stream/Stream.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,42 +8,42 @@
88

99
import static org.utbot.engine.overrides.UtOverrideMock.executeConcretely;
1010

11-
@SuppressWarnings({"UnnecessaryInterfaceModifier", "unused"})
11+
@SuppressWarnings("unused")
1212
@UtClassMock(target = java.util.stream.Stream.class, internalUsage = true)
1313
public interface Stream<E> extends BaseStream<E, Stream<E>> {
1414
@SuppressWarnings("unchecked")
15-
public static <E> java.util.stream.Stream<E> of(E element) {
15+
static <E> java.util.stream.Stream<E> of(E element) {
1616
Object[] data = new Object[1];
1717
data[0] = element;
1818

1919
return new UtStream<>((E[]) data, 1);
2020
}
2121

2222
@SuppressWarnings("unchecked")
23-
public static <E> java.util.stream.Stream<E> of(E... elements) {
23+
static <E> java.util.stream.Stream<E> of(E... elements) {
2424
int size = elements.length;
2525

2626
return new UtStream<>(elements, size);
2727
}
2828

2929
@SuppressWarnings("unchecked")
30-
public static <E> java.util.stream.Stream<E> empty() {
30+
static <E> java.util.stream.Stream<E> empty() {
3131
return new UtStream<>((E[]) new Object[]{}, 0);
3232
}
3333

34-
public static <E> java.util.stream.Stream<E> generate(Supplier<E> s) {
34+
static <E> java.util.stream.Stream<E> generate(Supplier<E> s) {
3535
// as "generate" method produces an infinite stream, we cannot analyze it symbolically
3636
executeConcretely();
3737
return null;
3838
}
3939

40-
public static <E> java.util.stream.Stream<E> iterate(final E seed, final UnaryOperator<E> f) {
40+
static <E> java.util.stream.Stream<E> iterate(final E seed, final UnaryOperator<E> f) {
4141
// as "iterate" method produces an infinite stream, we cannot analyze it symbolically
4242
executeConcretely();
4343
return null;
4444
}
4545

46-
public static <E> java.util.stream.Stream<E> concat(
46+
static <E> java.util.stream.Stream<E> concat(
4747
java.util.stream.Stream<? extends E> a,
4848
java.util.stream.Stream<? extends E> b
4949
) {

utbot-framework/src/main/java/org/utbot/engine/overrides/stream/UtStream.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,12 @@
44
import org.utbot.engine.overrides.collections.RangeModifiableUnlimitedArray;
55
import org.utbot.engine.overrides.collections.UtGenericStorage;
66

7-
import java.util.*;
7+
import java.util.Comparator;
8+
import java.util.Iterator;
9+
import java.util.NoSuchElementException;
10+
import java.util.Optional;
11+
import java.util.Spliterator;
12+
import java.util.Spliterators;
813
import java.util.function.BiConsumer;
914
import java.util.function.BiFunction;
1015
import java.util.function.BinaryOperator;
@@ -24,6 +29,7 @@
2429
import org.jetbrains.annotations.NotNull;
2530

2631
import static org.utbot.api.mock.UtMock.assume;
32+
import static org.utbot.api.mock.UtMock.assumeOrExecuteConcretely;
2733
import static org.utbot.engine.ResolverKt.HARD_MAX_ARRAY_SIZE;
2834
import static org.utbot.engine.overrides.UtOverrideMock.alreadyVisited;
2935
import static org.utbot.engine.overrides.UtOverrideMock.executeConcretely;
@@ -91,7 +97,7 @@ void preconditionCheck() {
9197

9298
assume(elementData.end >= 0);
9399
// we can create a stream for an array using Stream.of
94-
assume(elementData.end <= HARD_MAX_ARRAY_SIZE);
100+
assumeOrExecuteConcretely(elementData.end <= HARD_MAX_ARRAY_SIZE);
95101

96102
visit(this);
97103
}
@@ -313,7 +319,8 @@ public Stream<E> limit(long maxSize) {
313319
throw new IllegalArgumentException();
314320
}
315321

316-
// TODO how to process long value correctly - assumeOrExecuteConcretely?
322+
assumeOrExecuteConcretely(maxSize <= Integer.MAX_VALUE);
323+
317324
int newSize = (int) maxSize;
318325
int curSize = elementData.end;
319326

@@ -346,7 +353,7 @@ public Stream<E> skip(long n) {
346353
return new UtStream<>();
347354
}
348355

349-
// TODO how to process long value correctly - assumeOrExecuteConcretely?
356+
// n is 1...Integer.MAX_VALUE here
350357
int newSize = (int) (curSize - n);
351358

352359
return new UtStream<>((E[]) elementData.toArray((int) n, newSize), newSize);

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

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,6 @@ import soot.Scene
3333
import soot.SootClass
3434
import soot.SootField
3535
import soot.SootMethod
36-
import sun.reflect.generics.reflectiveObjects.GenericArrayTypeImpl
37-
import sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl
38-
import sun.reflect.generics.reflectiveObjects.TypeVariableImpl
39-
import sun.reflect.generics.reflectiveObjects.WildcardTypeImpl
4036

4137
val rangeModifiableArrayId: ClassId = RangeModifiableUnlimitedArray::class.id
4238

@@ -250,8 +246,7 @@ class RangeModifiableUnlimitedArrayWrapper : WrapperInterface {
250246

251247
// try to retrieve type storage for the single type parameter
252248
val typeStorage =
253-
resolver.typeRegistry.getObjectParameterTypeStorages(wrapper.addr)?.singleOrNull() ?: TypeStorage(OBJECT_TYPE)
254-
249+
resolver.typeRegistry.getTypeStoragesForObjectTypeParameters(wrapper.addr)?.singleOrNull() ?: TypeRegistry.objectTypeStorage
255250

256251
(0 until sizeValue).associateWithTo(resultModel.stores) { i ->
257252
val addr = UtAddrExpression(arrayExpression.select(mkInt(i + firstValue)))

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

Lines changed: 34 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,15 @@
11
package org.utbot.engine
22

3-
import kotlinx.collections.immutable.persistentListOf
4-
import kotlinx.collections.immutable.persistentSetOf
53
import org.utbot.common.unreachableBranch
6-
import org.utbot.engine.CommonStreamWrapper.Companion.isClosedStreamFieldId
7-
import org.utbot.engine.CommonStreamWrapper.Companion.isParallelStreamFieldId
8-
import org.utbot.engine.CommonStreamWrapper.Companion.utStreamType
94
import org.utbot.engine.overrides.collections.AssociativeArray
10-
import org.utbot.engine.overrides.collections.RangeModifiableUnlimitedArray
115
import org.utbot.engine.overrides.collections.UtArrayList
126
import org.utbot.engine.overrides.collections.UtGenericAssociative
137
import org.utbot.engine.overrides.collections.UtGenericStorage
148
import org.utbot.engine.overrides.collections.UtHashMap
159
import org.utbot.engine.overrides.collections.UtHashSet
1610
import org.utbot.engine.overrides.collections.UtLinkedList
17-
import org.utbot.engine.overrides.stream.UtStream
1811
import org.utbot.engine.pc.UtAddrExpression
1912
import org.utbot.engine.pc.UtExpression
20-
import org.utbot.engine.pc.mkEq
21-
import org.utbot.engine.pc.mkFalse
2213
import org.utbot.engine.pc.select
2314
import org.utbot.engine.symbolic.asHardConstraint
2415
import org.utbot.engine.z3.intValue
@@ -58,8 +49,7 @@ abstract class BaseOverriddenWrapper(protected val overriddenClassName: String)
5849
*
5950
* @see invoke
6051
*/
61-
protected abstract fun overrideInvoke(
62-
engine: UtBotSymbolicEngine,
52+
protected abstract fun UtBotSymbolicEngine.overrideInvoke(
6353
wrapper: ObjectValue,
6454
method: SootMethod,
6555
parameters: List<SymbolicValue>
@@ -83,7 +73,7 @@ abstract class BaseOverriddenWrapper(protected val overriddenClassName: String)
8373
method: SootMethod,
8474
parameters: List<SymbolicValue>
8575
): List<InvokeResult> {
86-
val methodResults = overrideInvoke(this, wrapper, method, parameters)
76+
val methodResults = overrideInvoke(wrapper, method, parameters)
8777
if (methodResults != null) {
8878
return methodResults
8979
}
@@ -159,28 +149,25 @@ abstract class BaseContainerWrapper(containerClassName: String) : BaseOverridden
159149
}
160150

161151
abstract class BaseGenericStorageBasedContainerWrapper(containerClassName: String) : BaseContainerWrapper(containerClassName) {
162-
override fun overrideInvoke(
163-
engine: UtBotSymbolicEngine,
152+
override fun UtBotSymbolicEngine.overrideInvoke(
164153
wrapper: ObjectValue,
165154
method: SootMethod,
166155
parameters: List<SymbolicValue>
167156
): List<InvokeResult>? =
168-
with(engine) {
169-
when (method.signature) {
170-
UT_GENERIC_STORAGE_SET_EQUAL_GENERIC_TYPE_SIGNATURE -> {
171-
val equalGenericTypeConstraint = typeRegistry
172-
.eqGenericSingleTypeParameterConstraint(parameters[0].addr, wrapper.addr)
173-
.asHardConstraint()
174-
175-
val methodResult = MethodResult(
176-
SymbolicSuccess(voidValue),
177-
equalGenericTypeConstraint
178-
)
157+
when (method.signature) {
158+
UT_GENERIC_STORAGE_SET_EQUAL_GENERIC_TYPE_SIGNATURE -> {
159+
val equalGenericTypeConstraint = typeRegistry
160+
.eqGenericSingleTypeParameterConstraint(parameters[0].addr, wrapper.addr)
161+
.asHardConstraint()
162+
163+
val methodResult = MethodResult(
164+
SymbolicSuccess(voidValue),
165+
equalGenericTypeConstraint
166+
)
179167

180-
listOf(methodResult)
181-
}
182-
else -> null
168+
listOf(methodResult)
183169
}
170+
else -> null
184171
}
185172

186173
override fun Resolver.resolveValueModels(wrapper: ObjectValue): List<List<UtModel>> {
@@ -283,34 +270,32 @@ class SetWrapper : BaseGenericStorageBasedContainerWrapper(UtHashSet::class.qual
283270
* entries, then real behavior of generated test can differ from expected and undefined.
284271
*/
285272
class MapWrapper : BaseContainerWrapper(UtHashMap::class.qualifiedName!!) {
286-
override fun overrideInvoke(
287-
engine: UtBotSymbolicEngine,
273+
override fun UtBotSymbolicEngine.overrideInvoke(
288274
wrapper: ObjectValue,
289275
method: SootMethod,
290276
parameters: List<SymbolicValue>
291277
): List<InvokeResult>? =
292-
with(engine) {
293-
when (method.signature) {
294-
UT_GENERIC_STORAGE_SET_EQUAL_GENERIC_TYPE_SIGNATURE -> listOf(
295-
MethodResult(
296-
SymbolicSuccess(voidValue),
297-
typeRegistry.eqGenericSingleTypeParameterConstraint(parameters[0].addr, wrapper.addr)
298-
.asHardConstraint()
299-
)
278+
when (method.signature) {
279+
UT_GENERIC_STORAGE_SET_EQUAL_GENERIC_TYPE_SIGNATURE -> listOf(
280+
MethodResult(
281+
SymbolicSuccess(voidValue),
282+
typeRegistry.eqGenericSingleTypeParameterConstraint(parameters[0].addr, wrapper.addr)
283+
.asHardConstraint()
300284
)
301-
UT_GENERIC_ASSOCIATIVE_SET_EQUAL_GENERIC_TYPE_SIGNATURE -> listOf(
302-
MethodResult(
303-
SymbolicSuccess(voidValue),
304-
typeRegistry.eqGenericTypeParametersConstraint(
305-
parameters[0].addr,
306-
wrapper.addr,
307-
parameterSize = 2
308-
).asHardConstraint()
309-
)
285+
)
286+
UT_GENERIC_ASSOCIATIVE_SET_EQUAL_GENERIC_TYPE_SIGNATURE -> listOf(
287+
MethodResult(
288+
SymbolicSuccess(voidValue),
289+
typeRegistry.eqGenericTypeParametersConstraint(
290+
parameters[0].addr,
291+
wrapper.addr,
292+
parameterSize = 2
293+
).asHardConstraint()
310294
)
311-
else -> null
312-
}
295+
)
296+
else -> null
313297
}
298+
314299
override fun Resolver.resolveValueModels(wrapper: ObjectValue): List<List<UtModel>> {
315300
val fieldModels = collectFieldModels(wrapper.addr, overriddenClass.type)
316301
val keyModels = fieldModels[overriddenClass.getFieldByName("keys").fieldId] as? UtArrayModel
@@ -402,12 +387,6 @@ private val UT_GENERIC_ASSOCIATIVE_CLASS
402387
private val UT_GENERIC_ASSOCIATIVE_SET_EQUAL_GENERIC_TYPE_SIGNATURE =
403388
UT_GENERIC_ASSOCIATIVE_CLASS.getMethodByName(UtGenericAssociative<*, *>::setEqualGenericType.name).signature
404389

405-
private val COLLECTION_CLASS: SootClass
406-
get() = Scene.v().getSootClass(java.util.Collection::class.java.canonicalName)
407-
408-
private val UT_COLLECTION_STREAM_SIGNATURE: String =
409-
COLLECTION_CLASS.getMethodByName("stream").signature
410-
411390
val ARRAY_LIST_TYPE: RefType
412391
get() = Scene.v().getSootClass(java.util.ArrayList::class.java.canonicalName).type
413392
val LINKED_LIST_TYPE: RefType

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

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -722,7 +722,7 @@ class TypeRegistry {
722722
secondAddr: UtAddrExpression,
723723
parameterSize: Int
724724
) : UtEqGenericTypeParametersExpression {
725-
val injections = (0 until parameterSize).associateWith { it }.toList().toTypedArray()
725+
val injections = Array(parameterSize) { it to it }
726726

727727
return eqGenericTypeParametersConstraint(firstAddr, secondAddr, *injections)
728728
}
@@ -745,7 +745,7 @@ class TypeRegistry {
745745
/**
746746
* Retrieves parameter type storages of an object with the given [addr] if present, or null otherwise.
747747
*/
748-
fun getObjectParameterTypeStorages(addr: UtAddrExpression): List<TypeStorage>? = genericTypeStorageByAddr[addr]
748+
fun getTypeStoragesForObjectTypeParameters(addr: UtAddrExpression): List<TypeStorage>? = genericTypeStorageByAddr[addr]
749749

750750
/**
751751
* Set types storages for [firstAddr]'s type parameters equal to type storages for [secondAddr]'s type parameters
@@ -756,22 +756,22 @@ class TypeRegistry {
756756
secondAddr: UtAddrExpression,
757757
indexInjection: Array<out Pair<Int, Int>>
758758
) {
759-
genericTypeStorageByAddr[secondAddr]?.let { existingGenericTypes ->
760-
val currentGenericTypes = mutableMapOf<Int, TypeStorage>()
759+
val existingGenericTypes = genericTypeStorageByAddr[secondAddr] ?: return
761760

762-
indexInjection.forEach { (from, to) ->
763-
require(from >= 0 && from < existingGenericTypes.size) {
764-
"Type injection is out of bounds: should be in [0; ${existingGenericTypes.size}) but is $from"
765-
}
761+
val currentGenericTypes = mutableMapOf<Int, TypeStorage>()
766762

767-
currentGenericTypes[to] = existingGenericTypes[from]
763+
indexInjection.forEach { (from, to) ->
764+
require(from >= 0 && from < existingGenericTypes.size) {
765+
"Type injection is out of bounds: should be in [0; ${existingGenericTypes.size}) but is $from"
768766
}
769767

770-
genericTypeStorageByAddr[firstAddr] = currentGenericTypes
771-
.entries
772-
.sortedBy { it.key }
773-
.mapTo(mutableListOf()) { it.value }
768+
currentGenericTypes[to] = existingGenericTypes[from]
774769
}
770+
771+
genericTypeStorageByAddr[firstAddr] = currentGenericTypes
772+
.entries
773+
.sortedBy { it.key }
774+
.mapTo(mutableListOf()) { it.value }
775775
}
776776

777777
/**

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,7 @@ class OptionalWrapper(private val utOptionalClass: UtOptionalClass) : BaseOverri
5858
private val AS_OPTIONAL_METHOD_SIGNATURE =
5959
overriddenClass.getMethodByName(UtOptional<*>::asOptional.name).signature
6060

61-
override fun overrideInvoke(
62-
engine: UtBotSymbolicEngine,
61+
override fun UtBotSymbolicEngine.overrideInvoke(
6362
wrapper: ObjectValue,
6463
method: SootMethod,
6564
parameters: List<SymbolicValue>
@@ -72,7 +71,7 @@ class OptionalWrapper(private val utOptionalClass: UtOptionalClass) : BaseOverri
7271
return listOf(
7372
MethodResult(
7473
parameters.first(),
75-
engine.typeRegistry.typeConstraintToGenericTypeParameter(
74+
typeRegistry.typeConstraintToGenericTypeParameter(
7675
parameters.first().addr,
7776
wrapper.addr,
7877
i = 0
@@ -82,6 +81,7 @@ class OptionalWrapper(private val utOptionalClass: UtOptionalClass) : BaseOverri
8281
}
8382

8483
}
84+
8585
return null
8686
}
8787

0 commit comments

Comments
 (0)