Is there a way to get parameter names of a given constructor using scala-macros?
Thanks
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Note that the
:powerapproach in Paul Butcher’s answer gives you access to internal APIs, which probably isn’t either necessary or desired if you’re trying to do this in a macro (or in runtime reflection outside of the REPL, for that matter).So for example calling
isConstructoron a plain oldSymbolprovided bymembersin the public Reflection API won’t work—you first need to make sure that you have aMethodSymbol. Similarly withtpe. You could of course cast to the internal APIs in non-REPL code, but this is dangerous and unnecessary. The following is a better solution:Or just:
Both of these will give you the following:
As desired. I’ve used runtime reflection here to simplify the example, but this will work exactly the same way with the
Universeyou get from yourContextin a macro.