Permalink
Browse files

simplistic implementation of `toMap`

  • Loading branch information...
mpollmeier committed Nov 29, 2016
1 parent 141b544 commit 9d06bc326e43f813916a7e2fa4cfb7f5c0c2a86d
@@ -12,7 +12,7 @@ class MappableTest extends WordSpec with Matchers {
"simple case class" should {
"deserialise to map" in {
val testInstance = SimpleCaseClass(i = 42, s = "something")
testInstance.toMap shouldBe 'empty
testInstance.toMap shouldBe Map("i" -> 42, "s" -> "something")
}
}
@@ -8,9 +8,14 @@ class mappable extends StaticAnnotation {
inline def apply(defn: Any): Any = meta {
val q"..$mods class $tName (..$params) extends $template" = defn
val keyValues: Seq[Term] = params.map { param =>
val memberName = Term.Name(param.name.value)
q"${param.name.value} -> $memberName"
}
val res = q"""
..$mods class $tName(..$params) {
def toMap(): Map[String, Any] = Map.empty[String, Any]
def toMap(): Map[String, Any] = Map[String, Any](..$keyValues)
}
"""

0 comments on commit 9d06bc3

Please sign in to comment.