Skip to content

Latest commit

 

History

History
45 lines (28 loc) · 2.17 KB

README.md

File metadata and controls

45 lines (28 loc) · 2.17 KB

Kotlin Builder Generator

A plugin for IntelliJ IDEA that auto-generates builder classes for your domain data classes, and saves you a lot of typing.

General info

This plugin for IntelliJ IDEA provides a quick way to implement a (simplified) Builder pattern for a given Kotlin data class. It will automatically generate a boilerplate builder class with a build() method that creates a valid instance of the target data class, and withX() methods that allow to manually set all primary constructor properties of the constructed object.

screenshot of a "Person" Kotlin data class

screenshot of the "Generate" menu with "Builder Class" option

screenshot of the generated "PersonBuilder" builder class

Features:

  • Automatic boilerplate builder class generation
  • Pre-set default values for any primitive, nullable and collection properties
  • Generated withoutX() methods for nullable properties
  • Customizable builder class and method names via plugin configuration
  • Selectable placement of builder class in production or test sources
  • Automatic wrapping/unwrapping of "wrapped primitive"-type properties
  • Detection and usage of existing builders for property types

Work in progress:

  • Generated methods to add items to collection properties

Setup

Download the latest kotlin-builder-generator-plugin-<VERSION>.zip from the releases page.

Install in your IntelliJ instance via File -> Settings -> Plugins -> [...] -> Install Plugin from Disk.

Configure to your liking via File -> Settings -> Tools -> Kotlin Builder Generator.

Usage: position cursor on the name of a Kotlin data class, open the Generate menu and select Builder Class.

Technologies