Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/Jintin/KBuilder
KBuilder help you to generate builder pattern related class in Kotlin
https://github.com/Jintin/KBuilder
Last synced: about 2 months ago
JSON representation
KBuilder help you to generate builder pattern related class in Kotlin
- Host: GitHub
- URL: https://github.com/Jintin/KBuilder
- Owner: Jintin
- License: mit
- Created: 2022-05-22T16:11:22.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2022-05-23T14:06:09.000Z (over 2 years ago)
- Last Synced: 2024-07-11T13:55:51.462Z (3 months ago)
- Language: Kotlin
- Size: 112 KB
- Stars: 13
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-list - Jintin/KBuilder - KBuilder help you to generate builder pattern related class in Kotlin (Kotlin)
README
# KBuilder
[![CircleCI](https://circleci.com/gh/Jintin/KBuilder.svg?style=shield)](https://app.circleci.com/pipelines/github/Jintin/KBuilder)
KBuilder is a library to generate Builder pattern automatically via ksp(Kotlin Symbol Processing)
## Usage
Any classes that store values via primary constructor like data class does are eligible to enable
this feature. Just simply add `@KBuilder` to the class and after successfully compile the Builder
class and the extension function to generate the builder will create for you.### Make IDE aware of ksp classes
Currently your IDE might not able to reason about the generated code under ksp folder, add this
block in your module level's build.gradle or any other way to include `build/generated/ksp/` path.```groovy
sourceSets {
main {
java {
srcDir "${buildDir.absolutePath}/generated/ksp/"
}
}
}
```More info here : https://kotlinlang.org/docs/ksp-quickstart.html#make-ide-aware-of-generated-code
### Example
If you have a `MyObj` class like below:
```kotlin
@KBuilder
data class MyObj(
val value1: String
)
```Then you can use the builder pattern with auto-generated class `MyObjBuilder` without any extra
effort after compile:```kotlin
val obj = MyObj("init value")
val newObj = obj.toBuilder().apply {
this.value1 = "updated value"
}.build()
println(newObj.value1) // "updated value"val builder = MyObjBuilder()
builder.value1 = "dynamic value"
val newObj2 = builder.build()
println(newObj2.value1) // "dynamic value"
```## Contributing
Bug reports and pull requests are welcome on GitHub at .
## License
The module is available as open source under the terms of
the [MIT License](http://opensource.org/licenses/MIT).