I learned (from here ) to use extractors to get Scala metadata. I also noticed Universe.MethodTypeExtractor :
MethodType(params, respte) class for creating and matching templates with MethodType(params, respte) syntax MethodType(params, respte) Here the parameters are a potentially empty list Parametric symbols of the method, and restpe is the result type of the Method.
Excellent! Looks like I want to! (?)
But how to get MethodType ? (And why is it an extractor for the "type" method ("types" methods?), Unlike, for example, the "Def" or "Ref" method ??)
scala> typeOf[List[Int]].member(newTermName("head")) res2: reflect.runtime.universe.Symbol = method head scala> res2 match { case MethodType(a, b) => println((a, b)) } scala.MatchError: method head (of class scala.reflect.internal.Symbols$MethodSymbol) [...] scala> res2.asType match { case MethodType(a, b) => println((a, b)) } scala.ScalaReflectionException: method head is not a type [...] scala> res2.asTerm match { case MethodType(a, b) => println((a, b)) } scala.MatchError: method head (of class scala.reflect.internal.Symbols$MethodSymbol) [...] scala> res2.asMethod match { case MethodType(a, b) => println((a, b)) } scala.MatchError: method head (of class scala.reflect.internal.Symbols$MethodSymbol) [...]
Or am I completely barking the wrong tree, so to speak?
source share