Creating a method definition tree from a method symbol and a body

To the best of my knowledge, there’s no standard way to go from a symbol to a defining tree.

Your best bet would probably be to iterate through c.enclosingRun.units, recursing into each of the unit.body trees as you go. If you see a DefDef, which has a symbol equal to your symbol, then you’ve reached your destination. upd. Don’t forget to duplicate the defining tree before reusing it!

This technique is far from being the most convenient thing in the world, but it should work.

Leave a Comment