https://github.com/y9vad9/implier
Kotlin Symbol Processor library for creating Mutable, Immutable, Builders, DSL Builders from interfaces & abstract classes with properties.
https://github.com/y9vad9/implier
annotation-processor kotlin kotlin-annotation-processor kotlin-builder kotlin-dsl kotlin-java kotlin-library ksp
Last synced: 6 months ago
JSON representation
Kotlin Symbol Processor library for creating Mutable, Immutable, Builders, DSL Builders from interfaces & abstract classes with properties.
- Host: GitHub
- URL: https://github.com/y9vad9/implier
- Owner: y9vad9
- Created: 2021-11-30T19:38:38.000Z (about 4 years ago)
- Default Branch: latest
- Last Pushed: 2022-08-28T23:06:16.000Z (over 3 years ago)
- Last Synced: 2025-06-28T11:39:26.913Z (7 months ago)
- Topics: annotation-processor, kotlin, kotlin-annotation-processor, kotlin-builder, kotlin-dsl, kotlin-java, kotlin-library, ksp
- Language: Kotlin
- Homepage:
- Size: 118 KB
- Stars: 17
- Watchers: 1
- Forks: 1
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README

# implier
Kotlin Symbol Processor library for creating **[
Mutable](https://github.com/y9vad9/implier/blob/fb5cba3c62defe23ce5773287fc9f37367d800fd/src/main/kotlin/com/y9vad9/implier/annotations.kt#L10)**
,
**[Immutable](https://github.com/y9vad9/implier/blob/fb5cba3c62defe23ce5773287fc9f37367d800fd/src/main/kotlin/com/y9vad9/implier/annotations.kt#L18)**
,
**[Builders](https://github.com/y9vad9/implier/blob/fb5cba3c62defe23ce5773287fc9f37367d800fd/src/main/kotlin/com/y9vad9/implier/annotations.kt#L35)**
, **[DSL Builders](https://github.com/y9vad9/implier/blob/1.0.1/src/main/kotlin/com/y9vad9/implier/annotations.kt#L50)**
from interfaces & abstract classes with properties.
## Examples
### Immutable & Mutable
```kotlin
@ImmutableImpl
@MutableImpl
interface Sample {
val sample: String
}
```
Will generate next classes and functions:
```kotlin
fun Sample.toImmutable(): ImmutableSample = ImmutableSample(sample)
class ImmutableSample(
override val sample: String
) : Sample
fun Sample.toMutable(): MutableSample = MutableSample(sample)
class MutableSample(
override var sample: String
) : Sample
```
### Builders
```kotlin
// required for annotations above. They can be used with either ImmutableImpl or MutableImpl
@ImmutableImpl(visibility = Visibility.INTERNAL)
@DSLBuilderImpl(functionName = "foo")
@BuilderImpl
@FactoryFunctionImpl
interface Foo {
val bar: Bar
}
```
Will generate:
```kotlin
// generated file: FooFactory
fun Foo(bar: Bar): Foo = ImmutableFoo(bar)
// generatedfile: FooBuilder
class FooBuilder {
fun bar(bar: Bar): FooBuilder { /* code */ }
fun build(): Foo { /* code */ }
}
// generated file: FooBuilderScope
class FooDSLBuilderScope {
var bar: Bar by Delegates.notNull()
}
fun foo(builder: FooDSLBuilderScope.() -> Unit): Foo { /* code */ }
```
## Implementation
For first, we need to add repository:
```kotlin
repositories {
maven("https://maven.y9vad9.com")
}
```
And then we need to add dependency:
```kotlin
dependencies {
implementation("com.y9vad9.implier:implier:$version") // annotations
ksp("com.y9vad9.implier:ksp:$version") // ksp implementation of annotations
}
```