Kondition

Kondition is a multiplatform compiler plugin which ensures that your Kotlin code runs under certain
conditions.
You can provide requirements to parameters simply by annotating them.
Example
For instance:
fun myFunction(@Ranged(0, 10) value: Int) {
println(value)
}
will be transformed to:
fun myFunction(@Ranged(0, 10) value: Int) {
require(value in 0..10) { "\"value\" in playWithInt must be in range 0..10" }
println(value)
}
[!IMPORTANT]
🚧 THIS PROJECT IS STILL A WORK IN PROGRESS. 🚧
API IS UNSTABLE AND MAY CHANGE IN THE FUTURE.
Installation
Make sure you are using Kotlin 2.0.0 or above.
repositories {
mavenCentral()
}
plugins {
id("com.kitakkun.kondition") version "<version>"
}
Available Annotations
See Predefined Annotations for details.
Define Custom Konditions (Planned)
Combine predefined annotations
You can create a new Kondition by combine existent annotations.
@Combine(with = CombineRule.AND)
@Ranged(0, 10)
@Ranged(5, 10)
annotation class MyAnnotation
Define custom kondition
@CustomKondition(implementationClass = MyCustomConditionImpl::class)
annotation class MyCustomCondition
class MyCustomConditionImpl : Kondition {
override fun check(type: KClass<*>, value: Any?) {
}
}