Skip to content

A kotlin compiler plugin to generate toString like data class.

License

Notifications You must be signed in to change notification settings

anatawa12/auto-tostring

Repository files navigation

Auto ToString Kotlin Compiler Plugin

a12 maintenance: Slowly

A kotlin compiler plugin to generate toString like data class.

How to use

First, you need to apply this gradle plugin

plugins {
 id("org.jetbrains.kotlin.jvm") version "<kotlin version>"
 id("com.anatawa12.auto-tostring") version "<version>"
}

To add compile-time library, add code below:

autoToString {
 // for compileOnly configuration
 addLib()
 // for <source-set>CompileOnly configuration
 addLib "sourceSet"
 addLib sourceSet: "sourceSet"
 // for your configuration
 addLib configuration: "yourConfiguration"
}

To generate toString function, add @AutoToString annotation to class.

Extra features

For kotlin.String or string it typed fields, This plugin surrounded the value with " like SomeClass(value="string body") and also surrounded with ' for kotlin.Chars.

You can customize wrapping with @SurroundedWith(begin=, end=). see KDoc for more details.