https://github.com/materiiapps/enumutil-kt
A Kotlin KSP plugin for generating repetitive functions for enums.
https://github.com/materiiapps/enumutil-kt
codegen kotlin kotlin-ksp ksp
Last synced: 7 months ago
JSON representation
A Kotlin KSP plugin for generating repetitive functions for enums.
- Host: GitHub
- URL: https://github.com/materiiapps/enumutil-kt
- Owner: MateriiApps
- License: apache-2.0
- Created: 2022-12-03T20:02:42.000Z (almost 3 years ago)
- Default Branch: master
- Last Pushed: 2023-11-10T01:04:26.000Z (almost 2 years ago)
- Last Synced: 2025-02-20T00:14:06.707Z (8 months ago)
- Topics: codegen, kotlin, kotlin-ksp, ksp
- Language: Kotlin
- Homepage:
- Size: 144 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# enumutil-kt 
A Kotlin KSP plugin for generating repetitive functions for enums.
## Installation
```kt
plugins {
id("com.google.devtools.ksp") version "1.9.20-1.0.14"
}repositories {
mavenCentral()
}dependencies {
implementation("io.github.materiiapps:enumutil:1.1.1")
ksp("io.github.materiiapps:enumutil-ksp:1.1.1")
}kotlin {
sourceSets {
getByName("main") {
kotlin.srcDir("build/generated/ksp/main/kotlin")
}
}
}
```## Usages
### @FromValue
Generate `fromValue(...)` extension methods for the target class.
This matches the first enum parameter unless the field name is specified explicitly.```kt
@FromValue
enum class OpCodes(val code: Int) {
READY(1),
DELETE(2),
CREATE(3),
DISCONNECT(4);// This is needed in order to have static extensions
companion object
}fun main() {
val opCode = OpCodes.fromValue(1)
}
```