Kotlin Symbol Processor library for creating Mutable , Immutable , Builders , DSL Builders from interfaces & abstract classes with properties.
@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
// 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 */ }
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
}