I assume that you need this information, given the type, not the tree (which is pretty simple, but less general). The trick is to use baseTypeto get an instance of a type Athat is a supertype of yours B, and then pull out its type parameters, matching TypeRef:
import scala.language.experimental.macros
import scala.reflect.macros.whitebox
def whateverImpl[X: c.WeakTypeTag, Y: c.WeakTypeTag](c: whitebox.Context) = {
import c.universe._
val xSymbol = weakTypeOf[X].typeSymbol
val ySymbol = weakTypeOf[Y].typeSymbol
ySymbol.typeSignature.baseType(xSymbol) match {
case TypeRef(_, _, List(arg)) => println(arg)
case _ => c.abort(c.enclosingPosition, "Types don't work.")
}
q"()"
}
def whatever[X, Y]: Unit = macro whateverImpl[X, Y]
trait A[T]
class B[T] extends A[Option[T]]
And then:
scala> whatever[A[_], B[_]]
Option[T]
2.10, whitebox.