This will work as it is when called from a regular instance of the class, so I assume that you are trying to do it from within the object, in which case you will need to map to ModuleDef as well as ClassDef :
case ModuleDef(mods, name, impl) => c.universe.reify( printf( "\n mods %s\n name %s\n impl %s\n", c.literal(mods.toString).splice, c.literal(name.toString).splice, c.literal(impl.toString).splice ) )
Please note: one easy way to debug something like this is to print out the raw idea that the unexpected is what you get:
case x => c.abort(c.enclosingPosition, "NoEnclosingClass: " + showRaw(x))
When called inside a singleton object, the following will be displayed:
<console>:7: error: NoEnclosingClass: ModuleDef(Modifiers(), ...
This gives us a pretty good idea of โโwhere we need to start.
source share