Skip to content

Kotlin Symbol Processor library for creating Mutable, Immutable, Builders, DSL Builders from interfaces & abstract classes with properties.

Notifications You must be signed in to change notification settings

y9vad9/implier

Repository files navigation

Maven metadata URL

implier

Kotlin Symbol Processor library for creating Mutable , Immutable , Builders , DSL Builders from interfaces & abstract classes with properties.

Examples

Immutable & Mutable

@ImmutableImpl
@MutableImpl
interface Sample {
    val sample: String
}

Will generate next classes and functions:

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

// 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:

 // 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:

repositories {
    maven("https://maven.y9vad9.com")
}

And then we need to add dependency:

dependencies {
    implementation("com.y9vad9.implier:implier:$version") // annotations
    ksp("com.y9vad9.implier:ksp:$version") // ksp implementation of annotations
}

About

Kotlin Symbol Processor library for creating Mutable, Immutable, Builders, DSL Builders from interfaces & abstract classes with properties.

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages