Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

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.

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
)
```