@@ -126,11 +126,13 @@ import org.utbot.framework.plugin.api.TypeReplacementMode.KnownImplementor
126
126
import org.utbot.framework.plugin.api.TypeReplacementMode.NoImplementors
127
127
import org.utbot.framework.plugin.api.classId
128
128
import org.utbot.framework.plugin.api.id
129
+ import org.utbot.framework.plugin.api.isAbstractType
129
130
import org.utbot.framework.plugin.api.util.executable
130
131
import org.utbot.framework.plugin.api.util.findFieldByIdOrNull
131
132
import org.utbot.framework.plugin.api.util.jField
132
133
import org.utbot.framework.plugin.api.util.jClass
133
134
import org.utbot.framework.plugin.api.util.id
135
+ import org.utbot.framework.plugin.api.util.isAbstract
134
136
import org.utbot.framework.plugin.api.util.isConstructor
135
137
import org.utbot.framework.plugin.api.util.utContext
136
138
import org.utbot.framework.util.executableId
@@ -1375,6 +1377,7 @@ class Traverser(
1375
1377
mockInfoGenerator : UtMockInfoGenerator ? = null
1376
1378
): ObjectValue {
1377
1379
touchAddress(addr)
1380
+ val nullEqualityConstraint = mkEq(addr, nullObjectAddr)
1378
1381
1379
1382
// Some types (e.g., interfaces) need to be mocked or replaced with the concrete implementor.
1380
1383
// Typically, this implementor is selected by SMT solver later.
@@ -1397,8 +1400,6 @@ class Traverser(
1397
1400
return ObjectValue (typeStorage, addr)
1398
1401
}
1399
1402
1400
- val nullEqualityConstraint = mkEq(addr, nullObjectAddr)
1401
-
1402
1403
if (mockInfoGenerator != null ) {
1403
1404
val mockInfo = mockInfoGenerator.generate(addr)
1404
1405
@@ -1499,21 +1500,16 @@ class Traverser(
1499
1500
" but there is no mock info generator provided to construct a mock value."
1500
1501
}
1501
1502
1502
- return createMockedObject(addr, type, mockInfoGenerator)
1503
+ return createMockedObject(addr, type, mockInfoGenerator, nullEqualityConstraint )
1503
1504
}
1504
1505
1505
1506
val concreteImplementation = when (applicationContext.typeReplacementMode) {
1506
- AnyImplementor -> {
1507
- val isMockConstraint = mkEq(typeRegistry.isMock(addr), UtFalse )
1508
-
1509
- queuedSymbolicStateUpdates + = typeHardConstraint
1510
- queuedSymbolicStateUpdates + = mkOr(isMockConstraint, nullEqualityConstraint).asHardConstraint()
1507
+ AnyImplementor -> findConcreteImplementation(addr, type, typeHardConstraint, nullEqualityConstraint)
1511
1508
1512
- // If we have this$0 with UtArrayList type, we have to create such instance.
1513
- // We should create an object with typeStorage of all possible real types and concrete implementation
1514
- // Otherwise we'd have either a wrong type in the resolver, or missing method like 'preconditionCheck'.
1515
- wrapperToClass[type]?.first()?.let { wrapper(it, addr) }?.concrete
1516
- }
1509
+ // If our type is not abstract, both in `KnownImplementors` and `NoImplementors` mode,
1510
+ // we should just still use concrete implementation that represents itself
1511
+ //
1512
+ // Otherwise:
1517
1513
// In case of `KnownImplementor` mode we should have already tried to replace type using `replaceTypeIfNeeded`.
1518
1514
// However, this replacement attempt might be unsuccessful even if some possible concrete types are present.
1519
1515
// For example, we may have two concrete implementors present in Spring bean definitions, so we do not know
@@ -1523,8 +1519,12 @@ class Traverser(
1523
1519
// Mocking can be impossible here as there are no guaranties that `mockInfoGenerator` is instantiated.
1524
1520
KnownImplementor ,
1525
1521
NoImplementors -> {
1522
+ if (! type.isAbstractType) {
1523
+ findConcreteImplementation(addr, type, typeHardConstraint, nullEqualityConstraint)
1524
+ }
1525
+
1526
1526
mockInfoGenerator?.let {
1527
- return createMockedObject(addr, type, it)
1527
+ return createMockedObject(addr, type, it, nullEqualityConstraint )
1528
1528
}
1529
1529
1530
1530
queuedSymbolicStateUpdates + = mkFalse().asHardConstraint()
@@ -1535,13 +1535,29 @@ class Traverser(
1535
1535
return ObjectValue (typeStorage, addr, concreteImplementation)
1536
1536
}
1537
1537
1538
+ private fun findConcreteImplementation (
1539
+ addr : UtAddrExpression ,
1540
+ type : RefType ,
1541
+ typeHardConstraint : HardConstraint ,
1542
+ nullEqualityConstraint : UtBoolExpression ,
1543
+ ): Concrete ? {
1544
+ val isMockConstraint = mkEq(typeRegistry.isMock(addr), UtFalse )
1545
+
1546
+ queuedSymbolicStateUpdates + = typeHardConstraint
1547
+ queuedSymbolicStateUpdates + = mkOr(isMockConstraint, nullEqualityConstraint).asHardConstraint()
1548
+
1549
+ // If we have this$0 with UtArrayList type, we have to create such instance.
1550
+ // We should create an object with typeStorage of all possible real types and concrete implementation
1551
+ // Otherwise we'd have either a wrong type in the resolver, or missing method like 'preconditionCheck'.
1552
+ return wrapperToClass[type]?.first()?.let { wrapper(it, addr) }?.concrete
1553
+ }
1554
+
1538
1555
private fun createMockedObject (
1539
1556
addr : UtAddrExpression ,
1540
1557
type : RefType ,
1541
1558
mockInfoGenerator : UtMockInfoGenerator ,
1559
+ nullEqualityConstraint : UtBoolExpression ,
1542
1560
): ObjectValue {
1543
- val nullEqualityConstraint = mkEq(addr, nullObjectAddr)
1544
-
1545
1561
val mockInfo = mockInfoGenerator.generate(addr)
1546
1562
val mockedObjectInfo = mocker.forceMock(type, mockInfoGenerator.generate(addr))
1547
1563
0 commit comments