Given a wrapper case class which has a set of values of which the types will be typedefs with annotations on them. I want to inspect the types to see whether the annotation is present and what the value is. This is so that I can create a macro that will construct an instance of my case class.
This should be enough code to see how far I've gotten:
class MyAnnotation(val value: String)
@MyAnnotation("some value")
type MyType = String
case class MyWrapper(myType: MyType)
// macro impl
def impl[T: c.WeakTypeTag](c: blackbox.Context): c.Expr[T] = {
import c.universe._
val tpe = weakTypeOf[T]
val sym = tpe.typeSymbol.asClass
val cSym = sym.companion
val cTpe = cSym.typeSignature
val apply = cTpe.member(TermName("apply")).asMethod
val applyParamTypes = apply.paramLists.flatten.map(p => p.typeSignature)
// now I have the types of the parameters to the case class companion object apply method, I want to look at the types (of which they will be typedefs), see if the MyAnnotation annotation is present, and pull out the MyAnnotation.value
}
I am using Scala 2.12