Skip to content

A Kotlin Compiler Plugin that enforces execution conditions for functions through annotations, enhancing code reliability and safety.

License

Notifications You must be signed in to change notification settings

kitakkun/Kondition

Repository files navigation

Kondition

Maven Central Kotlin License Platform

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?) {
        // TODO: check the value
    }
}

About

A Kotlin Compiler Plugin that enforces execution conditions for functions through annotations, enhancing code reliability and safety.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages