I have the next code, and i would like to extract the default parametr from value.
//
def extractor[T] = macro extractorImpl[T]
def extractorImpl[T: c.WeakTypeTag](c: Context) = {
//first i got a type contructor
???
}
i try with attachments but attachments.all return a Set[Any] with (for example) SymbolSourceAttachment(val name: String = "new name")
SymbolSourceAttachment contain ValDef but i do not know how to extract from SymbolSourceAttachment ValDef.
By the way i should to get a Map[String, String]("name" -> "new name")
Example:
case class Person(name: String = "new name")
object Macro {
def extractor[T] = macro extractorImpl[T]
def extractorImpl[T: c.WeakTypeTag](c: Context) = {
import c.universe._
c.weakTypeOf[T].declarations.collect {
case a: MethodSymbol if a.isConstructor =>
a.paramss.collect {
case b => b.collect {
case c =>
c.attachments.all {
case d => println(showRaw(d)) // => SymbolSourceAttachment(val name: String = "new name")
}
}
}
}
}
}
And macro should return Map("name" -> "new name")