Skip to content

Commit

Permalink
chore: added new examples
Browse files Browse the repository at this point in the history
  • Loading branch information
y9vad9 committed Mar 1, 2022
1 parent 4ee989d commit f2db4fa
Showing 1 changed file with 42 additions and 5 deletions.
47 changes: 42 additions & 5 deletions README.md
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,22 @@
# 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)**,
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
public interface Sample {
interface Sample {
val sample: String
}
```
Expand All @@ -25,16 +29,49 @@ Will generate next classes and functions:
fun Sample.toImmutable(): ImmutableSample = ImmutableSample(sample)

class ImmutableSample(
public override val sample: String
override val sample: String
) : Sample

fun Sample.toMutable(): MutableSample = MutableSample(sample)

class MutableSample(
public override var sample: String
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:
Expand Down

0 comments on commit f2db4fa

Please sign in to comment.