support.GeneratedAnnotation.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of kotlin-code-generation Show documentation
Show all versions of kotlin-code-generation Show documentation
Wrapping core components for kotlin code generation with kotlin-poet.
package io.toolisticon.kotlin.generation.support
import com.squareup.kotlinpoet.ExperimentalKotlinPoetApi
import com.squareup.kotlinpoet.asTypeName
import io.toolisticon.kotlin.generation.KotlinCodeGeneration
import io.toolisticon.kotlin.generation.KotlinCodeGeneration.buildAnnotation
import io.toolisticon.kotlin.generation.spec.KotlinAnnotationSpec
import io.toolisticon.kotlin.generation.spec.KotlinAnnotationSpecSupplier
import jakarta.annotation.Generated
import java.time.Instant
import kotlin.reflect.KClass
/**
* Builder to create a `@Generated` annotation.
*/
@ExperimentalKotlinPoetApi
@Suppress(SUPPRESS_UNUSED)
data class GeneratedAnnotation(
val value: String = KotlinCodeGeneration::class.asTypeName().toString(),
val date: Instant = Instant.now(),
val comments: List = emptyList()
) : KotlinAnnotationSpecSupplier {
fun generator(type: KClass<*>) = copy(value = type.asTypeName().toString())
fun date(instant: Instant) = copy(date = instant)
fun comment(comment: Pair) = copy(comments = this.comments + "${comment.first} = ${comment.second}")
override fun spec(): KotlinAnnotationSpec = buildAnnotation(Generated::class) {
addStringMembers("value", value)
addStringMember("date", date.toString())
if (comments.isNotEmpty()) {
addStringMember("comments", comments.joinToString(separator = "; "))
}
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy