com.ancientlightstudios.quarkus.kotlin.openapi.models.kotlin.KotlinComment.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of quarkus-kotlin-openapi-maven-plugin Show documentation
Show all versions of quarkus-kotlin-openapi-maven-plugin Show documentation
A Maven plugin to use the OpenAPI generator.
package com.ancientlightstudios.quarkus.kotlin.openapi.models.kotlin
import com.ancientlightstudios.quarkus.kotlin.openapi.emitter.CodeWriter
import com.ancientlightstudios.quarkus.kotlin.openapi.utils.forEachWithStats
class KotlinComment(private val blockComment: Boolean = false) : KotlinRenderable {
private val lines = mutableListOf()
fun addLine(line: String) {
lines.add(line)
}
override fun ImportCollector.registerImports() {}
override fun render(writer: CodeWriter) = with(writer) {
val prefix = when (blockComment) {
true -> " *"
else -> "//"
}
if (blockComment) {
writeln("/**")
}
lines.forEachWithStats { stats, item ->
write("$prefix $item")
if (!stats.last) {
writeln(forceNewLine = false)
}
}
if (blockComment) {
writeln(forceNewLine = false)
write(" */")
}
}
}
interface CommentAware {
fun setComment(comment: KotlinComment)
}
fun CommentAware.kotlinComment(blockComment: Boolean = false, block: KotlinComment.() -> Unit) {
val content = KotlinComment(blockComment).apply(block)
setComment(content)
}