Skip to content

Commit a6e1c83

Browse files
authored
Fix broken summary indention #1667 (#1676)
1 parent cb723b5 commit a6e1c83

File tree

5 files changed

+23
-7
lines changed

5 files changed

+23
-7
lines changed

utbot-framework-api/src/main/kotlin/org/utbot/framework/plugin/api/Api.kt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1428,3 +1428,12 @@ class DocRegularStmt(val stmt: String) : DocStatement() {
14281428

14291429
override fun hashCode(): Int = stmt.hashCode()
14301430
}
1431+
1432+
class DocRegularLineStmt(val stmt: String) : DocStatement() {
1433+
override fun toString(): String = stmt
1434+
1435+
override fun equals(other: Any?): Boolean =
1436+
if (other is DocRegularLineStmt) this.hashCode() == other.hashCode() else false
1437+
1438+
override fun hashCode(): Int = stmt.hashCode()
1439+
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import org.utbot.framework.plugin.api.DocCodeStmt
1515
import org.utbot.framework.plugin.api.DocCustomTagStatement
1616
import org.utbot.framework.plugin.api.DocMethodLinkStmt
1717
import org.utbot.framework.plugin.api.DocPreTagStatement
18+
import org.utbot.framework.plugin.api.DocRegularLineStmt
1819
import org.utbot.framework.plugin.api.DocRegularStmt
1920
import org.utbot.framework.plugin.api.DocStatement
2021
import org.utbot.framework.plugin.api.ExecutableId
@@ -473,6 +474,7 @@ fun convertDocToCg(stmt: DocStatement): CgDocStatement {
473474
CgCustomTagStatement(statements = stmts)
474475
}
475476
is DocRegularStmt -> CgDocRegularStmt(stmt = stmt.stmt)
477+
is DocRegularLineStmt -> CgDocRegularLineStmt(stmt = stmt.stmt)
476478
is DocClassLinkStmt -> CgDocClassLinkStmt(className = stmt.className)
477479
is DocMethodLinkStmt -> CgDocMethodLinkStmt(methodName = stmt.methodName, stmt = stmt.className)
478480
is DocCodeStmt -> CgDocCodeStmt(stmt = stmt.stmt)

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ abstract class CgAbstractRenderer(
330330
if (element.lines.all { it.isEmpty() }) return
331331

332332
println("/**")
333-
for (line in element.lines) line.accept(this)
333+
element.lines.forEach { it.accept(this) }
334334
println(" */")
335335
}
336336
override fun visit(element: CgDocPreTagStatement) {
@@ -343,9 +343,7 @@ abstract class CgAbstractRenderer(
343343
override fun visit(element: CgCustomTagStatement) {
344344
if (element.statements.all { it.isEmpty() }) return
345345

346-
for (stmt in element.statements) {
347-
stmt.accept(this)
348-
}
346+
element.statements.forEach { it.accept(this) }
349347
}
350348

351349
override fun visit(element: CgDocCodeStmt) {
@@ -366,7 +364,10 @@ abstract class CgAbstractRenderer(
366364
override fun visit(element: CgDocRegularLineStmt){
367365
if (element.isEmpty()) return
368366

369-
print(" * " + element.stmt + "\n")
367+
// It is better to avoid using \n in print, using println is preferred.
368+
// Mixing println's and print's with '\n' BREAKS indention.
369+
// See [https://stackoverflow.com/questions/6685665/system-out-println-vs-n-in-java].
370+
println(" * " + element.stmt)
370371
}
371372
override fun visit(element: CgDocClassLinkStmt) {
372373
if (element.isEmpty()) return

utbot-summary/src/main/kotlin/org/utbot/summary/comment/customtags/CustomJavaDocTagProvider.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package org.utbot.summary.comment.customtags.symbolic
22

3+
import org.utbot.framework.plugin.api.DocRegularLineStmt
34
import org.utbot.framework.plugin.api.DocRegularStmt
5+
import org.utbot.framework.plugin.api.DocStatement
46
import org.utbot.summary.comment.customtags.fuzzer.CommentWithCustomTagForTestProducedByFuzzer
57

68
/**
@@ -85,11 +87,11 @@ sealed class CustomJavaDocTag(
8587
}
8688

8789
// TODO: could be universal with the function above after creation of hierarchy data classes related to the comments
88-
fun generateDocStatementForTestProducedByFuzzer(comment: CommentWithCustomTagForTestProducedByFuzzer): DocRegularStmt? {
90+
fun generateDocStatementForTestProducedByFuzzer(comment: CommentWithCustomTagForTestProducedByFuzzer): DocStatement? {
8991
if (valueRetrieverFuzzer != null) { //TODO: it required only when we have two different retrievers
9092
return when (val value = valueRetrieverFuzzer!!.invoke(comment)) { // TODO: unsafe !! - resolve
9193
is String -> value.takeIf { it.isNotEmpty() }?.let {
92-
DocRegularStmt("@$name $value\n")
94+
DocRegularLineStmt("@$name $value")
9395
}
9496

9597
is List<*> -> value.takeIf { it.isNotEmpty() }?.let {

utbot-testing/src/main/kotlin/org/utbot/testing/UtValueTestCaseChecker.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import org.utbot.framework.plugin.api.DocCodeStmt
2424
import org.utbot.framework.plugin.api.DocCustomTagStatement
2525
import org.utbot.framework.plugin.api.DocMethodLinkStmt
2626
import org.utbot.framework.plugin.api.DocPreTagStatement
27+
import org.utbot.framework.plugin.api.DocRegularLineStmt
2728
import org.utbot.framework.plugin.api.DocRegularStmt
2829
import org.utbot.framework.plugin.api.DocStatement
2930
import org.utbot.framework.plugin.api.ExecutableId
@@ -2827,6 +2828,7 @@ private fun flattenDocStatements(summary: List<DocStatement>): List<DocStatement
28272828
is DocMethodLinkStmt -> flatten.add(s)
28282829
is DocCodeStmt -> flatten.add(s)
28292830
is DocRegularStmt -> flatten.add(s)
2831+
is DocRegularLineStmt -> flatten.add(s)
28302832
is DocCustomTagStatement -> flatten.add(s)
28312833
}
28322834
}

0 commit comments

Comments
 (0)