I think you’ll get help much faster if you ask this at the *scala-user*mailing 
list (tip: put the word “macro” in the topic to summon Eugene 
Burmako). Anyway, the code should be something like this:

trait Table {
  def columns: List[Column] = macro TableMacros.columnsImpl
}

object TableMacros {
  import scala.reflect.macros.Context // on 2.11, see blackbox/whitebox in 
the docs

  def columnsImpl(c: scala.reflect.macros.Context): c.Expr[List[Column]] = {
    import c.universe._

    // 1.
    // use c.prefix to get the exact class
    // try doing println(showRaw(c.prefix)) to see the tree and where the 
class goes there

    // 2.
    // find the column declarations — should be similar to what you have now

    // 3.
    // return c.Expr[List[Column]](x), where x is your List[Tree], each 
Tree corresponds to a column identifier
  }
}

HTH,
N


On Friday, May 23, 2014 11:58:25 AM UTC+1, David Pérez wrote:
>
> Thanks Andrzej (it looks like a Poland name).
> I'll take a look at it carefully later.
> This is my exact use case:
>
> http://stackoverflow.com/questions/23752885/how-to-use-reflection-at-compile-time
>
> I'm creating a DSL for simplifying access to SQLite.
> When finished, I'll share via github.
>
>
> Am Freitag, 23. Mai 2014 12:28:11 UTC+2 schrieb Andrzej Giniewicz:
>>
>> It might be not exactly what you need, but we use macros on Android in 
>> SpecGine ( game engine my group works on - 
>> https://bitbucket.org/specdevs/specgine ). While it isn't maybe the 
>> best example, it works good enough for our use case, i.e. we heavily 
>> use macro 
>>
>> def withManager[T <: ComponentsSpec]: T with ComponentsManager 
>>
>> which inspects how T is constructed and mixes in manager instance to 
>> use it within our Entity system. It works quite well with macros in 
>> 2.10 (SpecGine 0.1) and we still use it with 2.11 after simple porting 
>> (current master branch), without macro paradise. 
>>
>> What is the problem you are trying to solve? Because reflection can 
>> solve many problems, optimal solutions might be different. 
>>
>> On Wed, May 21, 2014 at 12:28 PM, David Pérez 
>> <[email protected]> wrote: 
>> > Does anyone know if reflection at compile time through macros has this 
>> kind 
>> > of problems? 
>>
>>

-- 
You received this message because you are subscribed to the Google Groups 
"scala-on-android" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to