Skip to content

Commit 6f01a61

Browse files
committed
Fixed review issues
1 parent 00061a7 commit 6f01a61

File tree

3 files changed

+8
-6
lines changed

3 files changed

+8
-6
lines changed

utbot-framework/src/main/kotlin/org/utbot/framework/codegen/domain/models/CgElement.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -888,7 +888,8 @@ class CgIfStatement(
888888

889889
data class CgSwitchCaseLabel(
890890
val label: CgLiteral? = null, // have to be compile time constant (null for default label)
891-
val statements: List<CgStatement>
891+
val statements: List<CgStatement>,
892+
val addBreakStatementToEnd: Boolean = true // do not set this field to "true" value if you manually added "break" to statements
892893
) : CgStatement
893894

894895
data class CgSwitchCase(

utbot-framework/src/main/kotlin/org/utbot/framework/codegen/renderer/CgJavaRenderer.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,10 @@ internal class CgJavaRenderer(context: CgRendererContext, printer: CgPrinter = C
314314
for (statement in element.statements) {
315315
statement.accept(this)
316316
}
317+
318+
if (element.addBreakStatementToEnd) {
319+
CgBreakStatement.accept(this)
320+
}
317321
}
318322
}
319323

utbot-framework/src/main/kotlin/org/utbot/framework/codegen/services/framework/MockFrameworkManager.kt

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -355,17 +355,14 @@ private class MockitoStaticMocker(context: CgContext, private val mocker: Object
355355
}
356356
}
357357

358-
// Always add "break" statement to prevent fall-through.
359-
statements += CgBreakStatement
360-
361358
caseLabels += CgSwitchCaseLabel(CgLiteral(intClassId, index), statements)
362359
}
363360

364361
val switchCase = CgSwitchCase(mockClassCounter[atomicIntegerGet](), caseLabels)
365362

366-
// If all switch-case labels contain only break statements,
363+
// If all switch-case labels are empty,
367364
// it means we do not need this switch and mock counter itself at all.
368-
val mockConstructionBody = if (caseLabels.map { it.statements }.all { it.singleOrNull() is CgBreakStatement }) {
365+
val mockConstructionBody = if (caseLabels.map { it.statements }.all { it.isEmpty() }) {
369366
emptyList()
370367
} else {
371368
listOf(switchCase, CgStatementExecutableCall(mockClassCounter[atomicIntegerGetAndIncrement]()))

0 commit comments

Comments
 (0)