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

Perl - how to grep a block of text from a file -

delphi - How to remove all the grips on a coolbar if I have several coolbands? -

javascript - Animating array of divs; only the final element is modified -