io.github.virelion:buildata-runtime-metadata

Buildata runtime for generated builders.

License

License

Categories

Categories

Data
GroupId

GroupId

io.github.virelion
ArtifactId

ArtifactId

buildata-runtime-metadata
Last Version

Last Version

0.5.0
Release Date

Release Date

Type

Type

pom.sha512
Description

Description

io.github.virelion:buildata-runtime-metadata
Buildata runtime for generated builders.
Project URL

Project URL

https://github.com/Virelion/buildata
Source Code Management

Source Code Management

https://github.com/Virelion/buildata/tree/master

Download buildata-runtime-metadata

Dependencies

compile (1)

Group / Artifact Type Version
org.jetbrains.kotlin : kotlin-stdlib-common jar 1.4.21

Project Modules

There are no modules declared in this project.

logo

badge badge badge badge badge badge badge

verification version last-commit

Kotlin multiplatform builder generator.

How to use?

  1. Have open source repositories connected to project:
buildscript {
    repositories {
        gradlePluginPortal()
        // ...
    }
}

repositories {
    mavenCentral()
    // ...
}
  1. Add buildata plugin to your build
plugins {
    kotlin("multiplatform") version "1.4.21"
    kotlin("jvm") version "1.4.21" // alternatively
    // ...
    id("io.github.virelion.buildata") version <LIBRARY_VERSION>
}
  1. Add buildata runtime to your dependencies
kotlin {
    // ...
    sourceSets {
        val commonMain by getting {
            dependencies {
                implementation("io.github.virelion.buildata:buildata-runtime:<LIBRARY_VERSION>")
            }
        }

        // ...
    }
}
  1. Add annotation to your data class
import io.github.virelion.buildata.Buildable
// ...

@Buildable
data class MyDataClass(
    val property: String
)
  1. Codegen will generate a builder you can use:
val myDataClass = MyDataClass::class.build {
    property = "Example"
}
val builder = MyDataClass::class.builder()
val myDataClass = builder {
    property = "Example"
}.build()

Features

Default values support

Builders will honor default values during the building.

@Buildable 
data class MyDataClass(
    val propertyWithDefault: String = "DEFAULT",
    val property: String
)
val myDataClass = MyDataClass::class.build {
    property = "Example"
}

myDataClass.property // returns "Example"
myDataClass.propertyWithDefault // returns "DEFAULT"

Composite builders support

You can mark item as @Buildable to allow accessing inner builders.

@Buildable
data class InnerItem(
    val property: String    
) 

@Buildable 
data class ParentDataClass(
    val innerItem: @Buildable InnerItem
)
val parentDataClassBuilder = ParentDataClass::class.builder()

parentDataClassBuilder {
    innerItem {
        property = "Example"
    }
}

val parentDataClass = parentDataClassBuilder.build()
parentDataClass.innerItem.property // returns "Example"

This feature allows for creating complex builder structures for tree like data class and make mutation easy during tree building process.

Versions

Version
0.5.0