I've learned (from here) to use extractors to obtain Scala metadata. I've also noticed Universe.MethodTypeExtractor
:
An extractor class to create and pattern match with syntax
MethodType(params, respte)
Here, params is a potentially empty list of parameter symbols of the method, and restpe is the result type of the method.
Great! Sounds like what I want!(?)
But how to get a MethodType
? (And why is this an extractor for a method "type" (are methods "types"?) as opposed to say, a method "Def" or "Ref"??)
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 up the wrong tree", so to speak?