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

commonMain.Klippable.kt Maven / Gradle / Ivy

There is a newer version: 0.4.1
Show newest version
package dev.petuska.klip.core

import dev.petuska.klip.core.int.KlipContext
import kotlin.contracts.contract

/**
 * Annotation to mark functions to be picked up by the compiler plugin.
 * Function signature must contain optional nullable [KlipContext] argument as shown bellow:
 *
 * ```
 *   @Klippable
 *   fun klippable(..., _context: KlipContext? = null)
 * ```
 * @param _context [KlipContext] injected by the compiler with details about the klip file
 * @see [KlipContext.validate]
 */
public annotation class Klippable

/**
 * Utility function to verify compiler-injected arguments
 * @throws IllegalArgumentException if the validation fails
 */
public fun KlipContext?.validate() {
  contract {
    returns() implies (this@validate != null)
  }
  requireNotNull(this) { "KlipContext should not be null and set by the compiler plugin. Did compiler plugin run?" }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy