in elitzur-core/src/main/scala/com/spotify/elitzur/validators/ValidatorMacros.scala [29:73]
def wrappedValidator[T: c.WeakTypeTag](c: whitebox.Context): c.Tree = {
import c.universe._
val magTree = magnolia1.Magnolia.gen[T](c)
def getLazyVal =
magTree match {
case q"lazy val $_ = $body; $_" =>
body
case q"val $_ = $body; $_" =>
body
}
// Remove annotations from magnolia since they are
// not serializable and we don't use them anyway
// scalastyle:off line.size.limit
val removeAnnotations =
new Transformer {
override def transform(tree: Tree): c.universe.Tree = {
tree match {
case Apply(AppliedTypeTree(Select(pack, TypeName("CaseClass")), ps),
List(typeName, isObject, isValueClass, params, _)) =>
Apply(AppliedTypeTree(Select(pack, TypeName("CaseClass")), ps),
List(typeName, isObject, isValueClass, params, q"""Array()"""))
case q"""new magnolia1.CaseClass[$tc, $t]($typeName, $isObject, $isValueClass, $params,$_){ $body }""" =>
q"""_root_.magnolia1.CaseClass[$tc, $t]($typeName, $isObject, $isValueClass, $params, Array()){ $body }"""
case q"com.spotify.elitzur.Validator.split(new magnolia1.SealedTrait($name, $subtypes, $_))" =>
q"_root_.com.spotify.elitzur.Validator.split(new magnolia1.SealedTrait($name, $subtypes, Array()))"
case q"""magnolia1.Magnolia.param[$tc, $t, $p]($name, $idx, $repeated, $tcParam, $defaultVal, $_)""" =>
q"""_root_.magnolia1.Magnolia.param[$tc, $t, $p]($name, $idx, $repeated, $tcParam, $defaultVal, Array())"""
case _ =>
super.transform(tree)
}
}
}
// scalastyle:on line.size.limit
val validator = removeAnnotations.transform(getLazyVal)
validator
}