All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.ancientlightstudios.quarkus.kotlin.openapi.models.kotlin.KotlinComment.kt Maven / Gradle / Ivy

There is a newer version: 0.4.14
Show newest version
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)
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy