title: Runtime reflection: getting variables and/or scopes from an AST
body: <p>Consider the following function declaration (pretty trivial in this case, but the question of course applies to the general case):</p>
  
  <pre><code>def f( x : Int ) = { val y = 1; val z = 2; x * y * z }
  </code></pre>
  
  <p>Given the Tree obtained for f by runtime reflection, is there any built-in support for </p>
  
  <p>a) getting the variable declarations? </p>
  
  <p>b) their associated scopes?</p>
  
  <p>I can see that one can obtain a) by writing a custom tree traverser, and then b) by performing further traversals from the point of declaration.</p>
  
  <p>However, this is clearly a nontrivial and error-prone undertaking.</p>
  
  <p>In particular, I see that the reflection API contains a Scope class, but am unable to determine whether this plays any role in providing for b).</p>