Allows you to define an annotation which collects symbols into a list or map.
Originally made for helping with serialization without reflection.
- KSP2 does not work. not my fault
- Multiplatform projects work like the example only if there is more than one target. Needs fix from either KMP gradle or KSP.
Check out the test-proj
module for a Kotlin Multiplatform example on how to set everything up.
Setup for Kotlin JVM is just like any other KSP project.
Note - these examples are abbreviated to look good, generated code looks a bit less appealing
Input | Output |
---|---|
@CollectSymbols("allClasses")
annotation class CollectToList
@CollectToList
class Foo
@CollectToList
class Bar |
val allClasses: Collection<KClass<*>> =
listOf(Foo::class, Bar::class) |
Input | Output |
---|---|
@CollectSymbols(
"symbolMap",
type = Type.MapByProperty,
property = "name"
)
annotation class ToMap(val name: String)
@ToMap("foo-class")
class Foo
@ToMap("bar-class")
class Bar |
val symbolMap: Map<String, KClass<*>> =
mapOf(
"foo-class" to Foo::class,
"bar-class" to Bar::class
) |