Skip to content

Fix broken summary indention #1676

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1428,3 +1428,12 @@ class DocRegularStmt(val stmt: String) : DocStatement() {

override fun hashCode(): Int = stmt.hashCode()
}

class DocRegularLineStmt(val stmt: String) : DocStatement() {
override fun toString(): String = stmt

override fun equals(other: Any?): Boolean =
if (other is DocRegularLineStmt) this.hashCode() == other.hashCode() else false

override fun hashCode(): Int = stmt.hashCode()
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import org.utbot.framework.plugin.api.DocCodeStmt
import org.utbot.framework.plugin.api.DocCustomTagStatement
import org.utbot.framework.plugin.api.DocMethodLinkStmt
import org.utbot.framework.plugin.api.DocPreTagStatement
import org.utbot.framework.plugin.api.DocRegularLineStmt
import org.utbot.framework.plugin.api.DocRegularStmt
import org.utbot.framework.plugin.api.DocStatement
import org.utbot.framework.plugin.api.ExecutableId
Expand Down Expand Up @@ -473,6 +474,7 @@ fun convertDocToCg(stmt: DocStatement): CgDocStatement {
CgCustomTagStatement(statements = stmts)
}
is DocRegularStmt -> CgDocRegularStmt(stmt = stmt.stmt)
is DocRegularLineStmt -> CgDocRegularLineStmt(stmt = stmt.stmt)
is DocClassLinkStmt -> CgDocClassLinkStmt(className = stmt.className)
is DocMethodLinkStmt -> CgDocMethodLinkStmt(methodName = stmt.methodName, stmt = stmt.className)
is DocCodeStmt -> CgDocCodeStmt(stmt = stmt.stmt)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ abstract class CgAbstractRenderer(
if (element.lines.all { it.isEmpty() }) return

println("/**")
for (line in element.lines) line.accept(this)
element.lines.forEach { it.accept(this) }
println(" */")
}
override fun visit(element: CgDocPreTagStatement) {
Expand All @@ -343,9 +343,7 @@ abstract class CgAbstractRenderer(
override fun visit(element: CgCustomTagStatement) {
if (element.statements.all { it.isEmpty() }) return

for (stmt in element.statements) {
stmt.accept(this)
}
element.statements.forEach { it.accept(this) }
}

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

print(" * " + element.stmt + "\n")
// It is better to avoid using \n in print, using println is preferred.
// Mixing println's and print's with '\n' BREAKS indention.
// See [https://stackoverflow.com/questions/6685665/system-out-println-vs-n-in-java].
println(" * " + element.stmt)
}
override fun visit(element: CgDocClassLinkStmt) {
if (element.isEmpty()) return
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package org.utbot.summary.comment.customtags.symbolic

import org.utbot.framework.plugin.api.DocRegularLineStmt
import org.utbot.framework.plugin.api.DocRegularStmt
import org.utbot.framework.plugin.api.DocStatement
import org.utbot.summary.comment.customtags.fuzzer.CommentWithCustomTagForTestProducedByFuzzer

/**
Expand Down Expand Up @@ -85,11 +87,11 @@ sealed class CustomJavaDocTag(
}

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

is List<*> -> value.takeIf { it.isNotEmpty() }?.let {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import org.utbot.framework.plugin.api.DocCodeStmt
import org.utbot.framework.plugin.api.DocCustomTagStatement
import org.utbot.framework.plugin.api.DocMethodLinkStmt
import org.utbot.framework.plugin.api.DocPreTagStatement
import org.utbot.framework.plugin.api.DocRegularLineStmt
import org.utbot.framework.plugin.api.DocRegularStmt
import org.utbot.framework.plugin.api.DocStatement
import org.utbot.framework.plugin.api.ExecutableId
Expand Down Expand Up @@ -2827,6 +2828,7 @@ private fun flattenDocStatements(summary: List<DocStatement>): List<DocStatement
is DocMethodLinkStmt -> flatten.add(s)
is DocCodeStmt -> flatten.add(s)
is DocRegularStmt -> flatten.add(s)
is DocRegularLineStmt -> flatten.add(s)
is DocCustomTagStatement -> flatten.add(s)
}
}
Expand Down