scala - Get `Symbol`s of method parameters via reflection -


i want call method on object via reflection, each parameter of method should set value specified type. more specific: have map[reflect.runtime.universe.symbol,any] symbol type e.g. list, double, string , any instance use.

now, each parameter of method want query map , set parameter accordingly.

i used typeof[t].members.collect ... obtain method scala.reflect.methodsymbol, don't know how obtain correct symbol. elements in method.paramss example val a not symbol of type of a.

method.paramss gives list of lists (one each parameter list) contain termsymbol each argument. each termsymbol has typesignature method returns type, has typesymbol method should give symbol you're looking for.

for example:

scala> import scala.reflect.runtime.universe._ import scala.reflect.runtime.universe._  scala> class foo { def foo(s: string, i: int) = s * } defined class foo  scala> val params = typeof[foo].member(newtermname("foo")).asmethod.paramss.head params: list[reflect.runtime.universe.symbol] = list(value s, value i)  scala> params.map(_.typesignature.typesymbol) res0: list[reflect.runtime.universe.symbol] = list(class string, class int) 

which think want.


Comments

Popular posts from this blog

c++ - Function signature as a function template parameter -

algorithm - What are some ways to combine a number of (potentially incompatible) sorted sub-sets of a total set into a (partial) ordering of the total set? -

How to call a javascript function after the page loads with a chrome extension? -