def myMacro():Any = macro impl
def impl(c: Context)(): c.Expr[Any] = {
import c.universe._
def generateHelloMethod():Tree = {
val name = TermName("sayHello")
val tpe = TypeName("String")
val hello = "hello world"
q"protected def $name():$tpe = { return $hello }"
}
return c.Expr[Unit](Block(generateHelloMethod()))
}
And i call it in my class :
class Test {
macros.myMacro()
}
The problem is that when i look at the generated bytecode i see my new method declared as 'private final', why ? Should i added a modifier ? Moreover, why '$1' is added to the end of the generated method name ?
private final String sayHello$1() {
return "hello world";
}
I guess that there's something that i don't understand because this result seems very strange to me.
Thx
--
You received this message because you are subscribed to the Google Groups "scala-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scala-user+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
To unsubscribe from this group and stop receiving emails from it, send an email to scala-user+unsubscribe@googlegroups.com.
def style:String = return getProperty(Properties.style, "default value").asInstanceOf[String];
def getStyle:String = style;
def style_=(style:String) = setProperty(Properties.style, style)
def setStyle(style:String) = style_=(style);
I could have used the java get/set method directly but, even if the framework is built on top of a pure java library, i want the user to feel coding in scala, not in java. So the best solution would be to have a macro that automatically writes all of this code, simply by annotating a var like this :
@FrameworkProperty(Properties.style, "default value") var style
And to let the user override one or more of the generated method if he wants to : the macro have to check for an existing def before inserting a new one.
The other use case is a little more complicated : i want to remove reflection from my framework to improve performance. The idea is to annotate a method in order to register it for future serialization (during the rendering phase). The macro would look into the enclosing class for an existing def "serializeAllAnnottees()" : if exists it appends a new line to the body of the def "serializeIntoJSON(myDefOrVar)", if not it creates it.
By the way, i'm really interested in scala and macros. I don't know if i can help but if you need something let me know.