Skip to content

Commit bf0bbc5

Browse files
committed
Apply several fixes
1 parent 08928ee commit bf0bbc5

File tree

4 files changed

+27
-22
lines changed

4 files changed

+27
-22
lines changed

utbot-framework/src/main/kotlin/org/utbot/framework/assemble/AssemblePrimitiveWrapper.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import org.utbot.framework.plugin.api.UtAssembleModel
44
import org.utbot.framework.plugin.api.UtExecutableCallModel
55
import org.utbot.framework.plugin.api.UtPrimitiveModel
66
import org.utbot.framework.plugin.api.util.booleanClassId
7+
import org.utbot.framework.plugin.api.util.byteClassId
78
import org.utbot.framework.plugin.api.util.charClassId
89
import org.utbot.framework.plugin.api.util.doubleClassId
910
import org.utbot.framework.plugin.api.util.executableId
@@ -25,6 +26,7 @@ fun assemble(model: UtPrimitiveModel): UtAssembleModel {
2526
intClassId -> java.lang.Integer::class.java.getConstructor(Int::class.java)
2627
longClassId -> java.lang.Long::class.java.getConstructor(Long::class.java)
2728
charClassId -> java.lang.Character::class.java.getConstructor(Char::class.java)
29+
byteClassId -> java.lang.Byte::class.java.getConstructor(Byte::class.java)
2830
booleanClassId -> java.lang.Boolean::class.java.getConstructor(Boolean::class.java)
2931
floatClassId -> java.lang.Float::class.java.getConstructor(Float::class.java)
3032
doubleClassId -> java.lang.Double::class.java.getConstructor(Double::class.java)

utbot-framework/src/main/kotlin/org/utbot/framework/codegen/model/constructor/context/CgContext.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ import kotlinx.collections.immutable.persistentListOf
5454
import kotlinx.collections.immutable.persistentMapOf
5555
import kotlinx.collections.immutable.persistentSetOf
5656
import org.utbot.framework.codegen.model.constructor.builtin.streamsDeepEqualsMethodId
57-
import org.utbot.framework.codegen.model.tree.CgParameterType
57+
import org.utbot.framework.codegen.model.tree.CgParameterKind
5858
import org.utbot.framework.plugin.api.util.executableId
5959
import org.utbot.framework.plugin.api.util.id
6060
import org.utbot.framework.plugin.api.util.isCheckedException
@@ -189,7 +189,7 @@ internal interface CgContextOwner {
189189
var valueByModelId: MutableMap<Int?, CgValue>
190190

191191
// parameters of the method currently being generated
192-
val currentMethodParameters: MutableMap<CgParameterType, CgVariable>
192+
val currentMethodParameters: MutableMap<CgParameterKind, CgVariable>
193193

194194
val testClassCustomName: String?
195195

@@ -451,7 +451,7 @@ internal data class CgContext(
451451

452452
override var valueByModelId: MutableMap<Int?, CgValue> = mutableMapOf()
453453

454-
override val currentMethodParameters: MutableMap<CgParameterType, CgVariable> = mutableMapOf()
454+
override val currentMethodParameters: MutableMap<CgParameterKind, CgVariable> = mutableMapOf()
455455

456456
override val testClassThisInstance: CgThisInstance = CgThisInstance(currentTestClass)
457457
}

utbot-framework/src/main/kotlin/org/utbot/framework/codegen/model/constructor/tree/CgMethodConstructor.kt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ import org.utbot.framework.codegen.model.tree.CgMethodCall
5252
import org.utbot.framework.codegen.model.tree.CgMultilineComment
5353
import org.utbot.framework.codegen.model.tree.CgNotNullAssertion
5454
import org.utbot.framework.codegen.model.tree.CgParameterDeclaration
55-
import org.utbot.framework.codegen.model.tree.CgParameterType
55+
import org.utbot.framework.codegen.model.tree.CgParameterKind
5656
import org.utbot.framework.codegen.model.tree.CgParameterizedTestDataProviderMethod
5757
import org.utbot.framework.codegen.model.tree.CgRegion
5858
import org.utbot.framework.codegen.model.tree.CgReturnStatement
@@ -448,7 +448,7 @@ internal class CgMethodConstructor(val context: CgContext) : CgContextOwner by c
448448
//actual result is primitive to support cases with exceptions.
449449
resultModel = if (result is UtPrimitiveModel) assemble(result) else result
450450

451-
val expectedVariable = currentMethodParameters[CgParameterType.ExpectedResult]!!
451+
val expectedVariable = currentMethodParameters[CgParameterKind.ExpectedResult]!!
452452
val expectedExpression = CgNotNullAssertion(expectedVariable)
453453

454454
assertEquality(expectedExpression, actual)
@@ -1234,11 +1234,11 @@ internal class CgMethodConstructor(val context: CgContext) : CgContextOwner by c
12341234
val testParameterDeclarations = createParameterDeclarations(testSet, genericExecution)
12351235
val mainBody = {
12361236
// build this instance
1237-
thisInstance = genericExecution.stateBefore.thisInstance?.let { currentMethodParameters[CgParameterType.ThisInstance] }
1237+
thisInstance = genericExecution.stateBefore.thisInstance?.let { currentMethodParameters[CgParameterKind.ThisInstance] }
12381238

12391239
// build arguments for method under test and parameterized test
12401240
for (index in genericExecution.stateBefore.parameters.indices) {
1241-
methodArguments += currentMethodParameters[CgParameterType.Argument(index)]!!
1241+
methodArguments += currentMethodParameters[CgParameterKind.Argument(index)]!!
12421242
}
12431243

12441244
//record result and generate result assertions
@@ -1292,7 +1292,7 @@ internal class CgMethodConstructor(val context: CgContext) : CgContextOwner by c
12921292
isReferenceType = true
12931293
)
12941294
this += thisInstance
1295-
currentMethodParameters[CgParameterType.ThisInstance] = thisInstance.parameter
1295+
currentMethodParameters[CgParameterKind.ThisInstance] = thisInstance.parameter
12961296
}
12971297
// arguments
12981298
for (index in genericExecution.stateBefore.parameters.indices) {
@@ -1314,7 +1314,7 @@ internal class CgMethodConstructor(val context: CgContext) : CgContextOwner by c
13141314
isReferenceType = argumentType.isRefType
13151315
)
13161316
this += argument
1317-
currentMethodParameters[CgParameterType.Argument(index)] = argument.parameter
1317+
currentMethodParameters[CgParameterKind.Argument(index)] = argument.parameter
13181318
}
13191319

13201320
val method = currentExecutable as MethodId
@@ -1334,7 +1334,7 @@ internal class CgMethodConstructor(val context: CgContext) : CgContextOwner by c
13341334
isReferenceType = wrappedType.isRefType
13351335
)
13361336
this += expectedResult
1337-
currentMethodParameters[CgParameterType.ExpectedResult] = expectedResult.parameter
1337+
currentMethodParameters[CgParameterKind.ExpectedResult] = expectedResult.parameter
13381338
}
13391339

13401340
if (containsFailureExecution) {
@@ -1347,7 +1347,7 @@ internal class CgMethodConstructor(val context: CgContext) : CgContextOwner by c
13471347
isReferenceType = true
13481348
)
13491349
this += expectedException
1350-
currentMethodParameters[CgParameterType.ExpectedException] = expectedException.parameter
1350+
currentMethodParameters[CgParameterKind.ExpectedException] = expectedException.parameter
13511351
}
13521352
}
13531353
}

utbot-framework/src/main/kotlin/org/utbot/framework/codegen/model/tree/CgElement.kt

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ import org.utbot.common.WorkaroundReason
44
import org.utbot.common.workaround
55
import org.utbot.framework.codegen.Import
66
import org.utbot.framework.codegen.model.constructor.tree.TestsGenerationReport
7-
import org.utbot.framework.codegen.model.constructor.util.CgStatementConstructor
87
import org.utbot.framework.codegen.model.util.CgExceptionHandler
98
import org.utbot.framework.codegen.model.visitor.CgVisitor
9+
import org.utbot.framework.plugin.api.BuiltinClassId
1010
import org.utbot.framework.plugin.api.ClassId
1111
import org.utbot.framework.plugin.api.ConstructorId
1212
import org.utbot.framework.plugin.api.DocClassLinkStmt
@@ -26,7 +26,6 @@ import org.utbot.framework.plugin.api.util.intClassId
2626
import org.utbot.framework.plugin.api.util.objectArrayClassId
2727
import org.utbot.framework.plugin.api.util.objectClassId
2828
import org.utbot.framework.plugin.api.util.voidClassId
29-
import kotlin.math.exp
3029

3130
interface CgElement {
3231
// TODO: order of cases is important here due to inheritance between some of the element types
@@ -584,9 +583,13 @@ open class CgVariable(
584583
*/
585584
class CgNotNullAssertion(val expression: CgExpression) : CgValue {
586585
override val type: ClassId
587-
get() {
588-
val expressionType = expression.type
589-
return ClassId(
586+
get() = when (val expressionType = expression.type) {
587+
is BuiltinClassId -> BuiltinClassId(
588+
name = expressionType.name,
589+
canonicalName = expressionType.canonicalName,
590+
simpleName = expressionType.simpleName,
591+
)
592+
else -> ClassId(
590593
expressionType.name,
591594
expressionType.elementClassId,
592595
isNullable = false
@@ -617,17 +620,17 @@ data class CgParameterDeclaration(
617620
}
618621

619622
/**
620-
* Test methd parameter can be one of the following types:
623+
* Test method parameter can be one of the following types:
621624
* - this instance for method under test (MUT)
622625
* - argument of MUT with a certain index
623626
* - result expected from MUT with the given arguments
624627
* - exception expected from MUT with the given arguments
625628
*/
626-
sealed class CgParameterType {
627-
object ThisInstance : CgParameterType()
628-
data class Argument(val index: Int) : CgParameterType()
629-
object ExpectedResult : CgParameterType()
630-
object ExpectedException : CgParameterType()
629+
sealed class CgParameterKind {
630+
object ThisInstance : CgParameterKind()
631+
data class Argument(val index: Int) : CgParameterKind()
632+
object ExpectedResult : CgParameterKind()
633+
object ExpectedException : CgParameterKind()
631634
}
632635

633636

0 commit comments

Comments
 (0)