title: How to use reflection at compile time
body: <p>I have this situation:</p>
  
  <pre><code>class Column {
  }
  
  trait Table {
      lazy val columns: List[Column] = ....
  }
  
  class MyTable extends Table {
     val column1 = new Column()
     val column2 = new Column()
  }
  </code></pre>
  
  <p>I would like to get the list of columns defined in derived classes at compile time.</p>
  
  <p>I've already been able to do by using runtime reflection, but I've heard that it can be problematic in Android and ProGuard.  So, I'd like to do it at compile time if possible.</p>
  
  <p><a href="https://groups.google.com/forum/#!topic/scala-on-android/Q0E_OMYqE0A" rel="nofollow">https://groups.google.com/forum/#!topic/scala-on-android/Q0E_OMYqE0A</a></p>
  
  <p>Here is my implementation with runtime reflection:</p>
  
  <pre><code>trait Table {
      lazy val columns: List[Column] = {
          import scala.reflect.runtime.universe._
          val rm = scala.reflect.runtime.currentMirror
          val columns = rm.classSymbol(this.getClass).toType.members.collect {
              case m: MethodSymbol if m.isGetter &amp;&amp; m.returnType &lt;:&lt; typeOf[Column] =&gt; m
          }
          val espejo = rm.reflect(this)
          (for (col &lt;- columns) yield
              espejo.reflectMethod(col).apply().asInstanceOf[Column]).toList
      }    
  }
  </code></pre>