/KMap

A Kotlin generator for mapping code

Primary LanguageKotlin

KMap

KMap is a generator. It generates mappers based on annotations found on the classes that need these mappings. Take for example these two classes:

<style> tr, th, td { border: none!important; } </style>
@MapPartner
class Size {
    @KMap var w: Int = 0
    @KMap var h: Int = 0
}
class Dimension {
    var w: Int = 0
    var h: Int = 0
}

This will generate these files (they won't look exactly like this):

fun Size.toDimension() = 
    Dimension().also {
        it.w = w
        it.h = h
    }
fun Dimension.toSize() =
    Size().also {
        it.w = w
        it.h = h
    }

Which is very convenient to call:

Size(w = 15, h = 284).toDimension() // => Dimension(w = 15, h = 284)