A basic KSP example inspired by CaseDetectionMacro.swift, which creates case detection for each kotlin enum entry using kotlin extensions
fun main() {
val coffeeList = buildList {
for (i in 0 until 100) {
add(makeRandomCoffee())
}
}
val mediumStrongEspressos = coffeeList.filter {
it.type.isCappuccino() && it.strength.isStrong() && it.size.isMedium()
}
println(mediumStrongEspressos)
}
// each enum should be annotated with @CaseDetection
fun makeRandomCoffee(): Coffee {
return Coffee(
type = CoffeeType.entries.random(),
strength = CoffeeStrength.entries.random(),
size = CoffeeSize.entries.random()
)
}
There are a few points to be improved such as code generation template, string case parsing, and others that were overlooked for the sake of simplicity for this proof of concept (for now).