11package org.utbot.engine
22
3- import org.utbot.common.WorkaroundReason
4- import org.utbot.common.workaround
5- import org.utbot.engine.TypeRegistry.Companion.objectTypeStorage
3+ import org.utbot.api.mock.UtMock
4+ import org.utbot.engine.overrides.UtOverrideMock
5+ import org.utbot.engine.types. TypeRegistry.Companion.objectTypeStorage
66import org.utbot.engine.pc.UtAddrExpression
77import org.utbot.engine.pc.UtBoolExpression
8+ import org.utbot.engine.pc.UtFalse
89import org.utbot.engine.pc.UtInstanceOfExpression
910import org.utbot.engine.pc.UtIsExpression
1011import org.utbot.engine.pc.UtTrue
1112import org.utbot.engine.pc.mkAnd
1213import org.utbot.engine.pc.mkOr
1314import org.utbot.engine.symbolic.*
15+ import org.utbot.engine.types.TypeResolver
1416import org.utbot.framework.plugin.api.FieldId
1517import org.utbot.framework.plugin.api.UtInstrumentation
1618import soot.RefType
@@ -125,6 +127,9 @@ class TypeStorage private constructor(val leastCommonType: Type, val possibleCon
125127 " (leastCommonType=$leastCommonType , ${possibleConcreteTypes.size} possibleTypes=${possibleConcreteTypes.take(10 )} )"
126128 }
127129
130+ operator fun component1 (): Type = leastCommonType
131+ operator fun component2 (): Set <Type > = possibleConcreteTypes
132+
128133 companion object {
129134 /* *
130135 * Constructs a type storage with particular leastCommonType and set of possibleConcreteTypes.
@@ -307,7 +312,16 @@ data class TypeConstraint(
307312 /* *
308313 * Returns a conjunction of the [isConstraint] and [correctnessConstraint]. Suitable for an object creation.
309314 */
310- fun all (): UtBoolExpression = mkAnd(isOrNullConstraint(), correctnessConstraint)
315+ fun all (): UtBoolExpression {
316+ // There is no need in constraint for UtMock and UtOverrideMock instances
317+ val sootClass = (isConstraint.type as ? RefType )?.sootClass
318+
319+ if (sootClass == utMockClass || sootClass == utOverrideMockClass) {
320+ return UtTrue
321+ }
322+
323+ return mkAnd(isOrNullConstraint(), correctnessConstraint)
324+ }
311325
312326 /* *
313327 * Returns a condition that either the object is an instance of the types in [isConstraint], or it is null.
@@ -319,7 +333,13 @@ data class TypeConstraint(
319333 * For example, it is suitable for instanceof checks or negation of equality with some types.
320334 * NOTE: for Object we always return UtTrue.
321335 */
322- fun isConstraint (): UtBoolExpression = if (isConstraint.typeStorage.isObjectTypeStorage()) UtTrue else isConstraint
336+ fun isConstraint (): UtBoolExpression {
337+ if (isConstraint.typeStorage.possibleConcreteTypes.isEmpty()) {
338+ return UtFalse
339+ }
340+
341+ return if (isConstraint.typeStorage.isObjectTypeStorage()) UtTrue else isConstraint
342+ }
323343
324344 override fun hashCode (): Int = this .hashcode
325345
@@ -344,3 +364,6 @@ data class TypeConstraint(
344364 * should be initialized. We don't need to initialize fields that are not accessed in the method being tested.
345365 */
346366data class InstanceFieldReadOperation (val addr : UtAddrExpression , val fieldId : FieldId )
367+
368+ private val utMockClassName: String = UtMock ::class .java.name
369+ private val utOverrideMockClassName: String = UtOverrideMock ::class .java.name
0 commit comments