Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/stashymane/ksp-symbol-collector
Allows you to collect symbols (classes, etc.) into a list or map.
https://github.com/stashymane/ksp-symbol-collector
codegen kotlin kotlin-ksp
Last synced: 4 days ago
JSON representation
Allows you to collect symbols (classes, etc.) into a list or map.
- Host: GitHub
- URL: https://github.com/stashymane/ksp-symbol-collector
- Owner: stashymane
- License: apache-2.0
- Created: 2024-08-26T21:48:27.000Z (3 months ago)
- Default Branch: master
- Last Pushed: 2024-08-26T23:01:10.000Z (3 months ago)
- Last Synced: 2024-08-28T01:02:12.071Z (3 months ago)
- Topics: codegen, kotlin, kotlin-ksp
- Language: Kotlin
- Homepage:
- Size: 77.1 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# KSP Symbol Collector
Allows you to define an annotation which collects symbols into a list or map.
Originally made for helping with serialization without reflection.
## Current issues
* KSP2 does not work.
[not](https://github.com/google/ksp/issues/2001) [my](https://github.com/google/ksp/issues/1823) [fault](https://github.com/google/ksp/issues/1941)
* Multiplatform projects work like the example **only** if there is more than one target.
Needs fix from either KMP gradle or KSP.## Setup
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.## Examples
**Note** - these examples are abbreviated to look good, generated code looks a bit less appealing
Input
Output```kotlin
@CollectSymbols("allClasses")
annotation class CollectToList@CollectToList
class Foo@CollectToList
class Bar
````symbols/Symbols.kt`
```kotlin
val allClasses: Collection> =
listOf(Foo::class, Bar::class)
```Input
Output```kotlin
@CollectSymbols(
"symbolMap",
type = Type.MapByProperty,
property = "name"
)
annotation class ToMap(val name: String)@ToMap("foo-class")
class Foo@ToMap("bar-class")
class Bar
````symbols/Symbols.kt`
```kotlin
val symbolMap: Map> =
mapOf(
"foo-class" to Foo::class,
"bar-class" to Bar::class
)
```