Given (Scala 2.10.3),
package models
@MyAnnotation
case class MyClass()
How do I get the package name in the impl of the macro?
I've tried:
1) A typeCheck
like was suggested here, but that results in a stack overflow (although I can see it spitting out the correct full name).
val result = {
annottees.map(_.tree).toList match {
case classDef @ q"$mods class $name[..$tparams](..$first)(...$rest) extends ..$parents { $self => ..$body }" :: Nil => {
val full = c.typeCheck(q"??? : $name").tpe.typeSymbol.fullName
...
2) Collecting the ClassDef
and calling .symbol
reveals that it has none.
I'd like to avoid:
3) Passing in the value as an argument to the annotation.
4) Annotating the package and storing the name for use when expanding the class.
5) Parsing the context's .enclosingPosition
with the hopes that package and directory structure corresponds.
Did I botch the typeCheck
? Should I settle for #3 or #4? Any suggestions how to accomplish my goal?
Thanks very much for any input,
-Julian