Annotations
View MarkdownAnnotate a declaration
Section titled “Annotate a declaration”Set annotations in a class, function, or property block to a list of annotation names. Use fully qualified names to let Prosa.kt add the imports. These declaration annotations are emitted without arguments.
import com.alexstyl.prosakt.ktFile
val source = ktFile { ktClass("User") { annotations = listOf("kotlinx.serialization.Serializable") }}Generated Kotlin:
import kotlinx.serialization.Serializable
@Serializableclass UserAnnotate the file
Section titled “Annotate the file”Use ktFileAnnotation() inside ktFile {} to add a file annotation. Use argument {} in its block to supply an annotation argument.
import com.alexstyl.prosakt.ktFile
val source = ktFile { ktFileAnnotation("kotlin.jvm.JvmName") { argument { literal("Greetings") } } packageName("com.example.greetings")}Generated Kotlin:
@file:JvmName("Greetings")
package com.example.greetings
import kotlin.jvm.JvmNameFile annotations appear before the package declaration. The @file: prefix is generated for you.