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.
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.
Make sure you are using Kotlin 2.0.0 or above.
repositories {
mavenCentral()
}
plugins {
id("com.kitakkun.kondition") version "<version>"
}
See Predefined Annotations for details.
You can create a new Kondition by combine existent annotations.
@Combine(with = CombineRule.AND)
@Ranged(0, 10)
@Ranged(5, 10)
annotation class MyAnnotation
@CustomKondition(implementationClass = MyCustomConditionImpl::class)
annotation class MyCustomCondition
class MyCustomConditionImpl : Kondition {
override fun check(type: KClass<*>, value: Any?) {
// TODO: check the value
}
}