Skip to content

atsushi130/BuilderKit

Repository files navigation

BuilderKit

apache licensed builderkit kotlin travis Issues Version

Usage

Implement Generator class to /generate/src/.

class Generator {
    companion object {
        @JvmStatic fun main(vararg args: String) {
            BuilderGenerator.generates(ModelClass::class)
        }
    }
}

Builder class is automatically generated to generate/src/ by default.

Output Builder class

Sample model class

data class ModelClass(val arg1: Int, val arg2: List<String>, val arg3: MyClass)

Output builder class

class ModelClassBuilder(
        private var arg1: Int,
        private var arg2: List<String>,
        private var arg3: MyClass
) {
    fun build() = ModelClass(this.arg1, this.arg2, this.arg3)

    fun withArg1(arg1: Int): ModelClassBuilder {
        this.arg1 = arg1
        return this
    }

    fun withArg2(arg2: List<String>): ModelClassBuilder {
        this.arg2 = arg2
        return this
    }

    fun withArg3(arg3: MyClass): ModelClassBuilder {
        this.arg3 = arg3
        return this
    }
}

Other Usage

Specify indent and output file path

import java.io.File

class Generator {
    companion object {
        @JvmStatic fun main(vararg args: String) {
            val builder = BuilderGenerator(indent = "\t", path = File("generate/src/"))
            builder.generates(ModelClass::class)
        }
    }
}

Dependency

Maven

<dependency>
    <groupId>com.github.atsushi130</groupId>
    <artifactId>builderkit</artifactId>
    <version>0.6.0</version>
</dependency>

Gradle

compile 'com.github.atsushi130:builderkit:0.6.0'