https://github.com/toolisticon/kotlin-code-generation
Opinionated setup for kotlin-poet code generator projects
https://github.com/toolisticon/kotlin-code-generation
Last synced: 8 months ago
JSON representation
Opinionated setup for kotlin-poet code generator projects
- Host: GitHub
- URL: https://github.com/toolisticon/kotlin-code-generation
- Owner: toolisticon
- License: apache-2.0
- Created: 2024-05-22T00:28:50.000Z (about 2 years ago)
- Default Branch: develop
- Last Pushed: 2025-08-26T09:07:24.000Z (10 months ago)
- Last Synced: 2025-08-26T11:37:43.554Z (10 months ago)
- Language: Kotlin
- Homepage:
- Size: 543 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# kotlin-code-generation
The one-stop lib for code generation for kotlin (jvm) and code generation testing. Based on [kotlin-poet](https://square.github.io/kotlinpoet/).
[](https://github.com/holisticon#open-source-lifecycle)
[](https://central.sonatype.com/namespace/io.toolisticon.kotlin.generation)
[](https://github.com/toolisticon/kotlin-code-generation/actions)
[](https://app.codacy.com/gh/toolisticon/kotlin-code-generation/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_grade)
[](https://codecov.io/gh/toolisticon/kotlin-code-generation)
[](http://kotlinlang.org)
[](https://holisticon.de/)
[](https://javadoc.io/doc/io.toolisticon.kotlin.generation/kotlin-code-generation)
**Usage:**
```xml
io.toolisticon.kotlin.generation
kotlin-code-generation-bom
LATEST_VERSION
import
pom
```
## Documentation
This code generation lib wraps the fantastic [kotlin-poet](https://square.github.io/kotlinpoet/) framework. The documentation is based on the [kotlin-poet documentation](https://square.github.io/kotlinpoet/).
## Getting started
Core concept are [Strategies](./kotlin-code-generation/src/main/kotlin/spi/KotlinCodeGenerationStrategy.kt) and [Processors](./kotlin-code-generation/src/main/kotlin/spi/KotlinCodeGenerationProcessor.kt).
### Load SPI
* Implement and list your strategies and processors in the `META-INF/services/io.toolisticon.kotlin.generation.spi.KotlinCodeGenerationSpi`. Both interfaces are loaded via the same ServiceLoader mechanism,
and later filtered for the specific type of strategy or processor.
* Load the services via `val spi = KotlinCodeGeneration.spi.load()`
* Define your context by extending the `KotlinCodeGenerationContext` class. This context is passed to the strategies and processors, so they can use more data than just the input item in the loop.
* You probably want to filter the loaded list you provide to your specific context.
*
## Features
* KotlinAnnotationSpec
* KotlinAnnotationSpecBuilder
* KotlinFileSpec
* KotlinFileSpecBuilder
* KotlinFunSpec
* KotlinFunSpecBuilder
* KotlinParameterSpec
* KotlinParameterSpecBuilder
* KotlinPropertySpec
* KotlinPropertySpecBuilder
## Roadmap
### Specs to support
* com/squareup/kotlinpoet/TypeAliasSpec
* com/squareup/kotlinpoet/TypeSpec
### Builders to implement
* com/squareup/kotlinpoet/AnnotationSpec$Builder
* Taggable.Builder
* com/squareup/kotlinpoet/CodeBlock$Builder
* None
* com/squareup/kotlinpoet/FileSpec$Builder
* Annotatable.Builder
* Taggable.Builder
* TypeSpecHolder.Builder
* com/squareup/kotlinpoet/FunSpec$Builder
* Annotatable.Builder
* ContextReceivable.Builder
* Documentable.Builder
* Taggable.Builder
* OriginatingElementsHolder.Builder
* com/squareup/kotlinpoet/ParameterSpec$Builder
* Annotatable.Builder
* Documentable.Builder
* Taggable.Builder
* com/squareup/kotlinpoet/PropertySpec$Builder
* Annotatable.Builder
* ContextReceivable.Builder
* Documentable.Builder
* OriginatingElementsHolder.Builder
* Taggable.Builder
* com/squareup/kotlinpoet/TypeAliasSpec$Builder
* Annotatable.Builder
* Documentable.Builder
* Taggable.Builder