As an alternative to what Goktug proposed about macros, we would have an
equivalent to Scala macros (sorry for insisting with Scala :-) )
@Macro(SumGenerator.class)
Integer sum(Integer arg0, Integer arg1) {
// We will never be here
return null;
}
// rebind space
class SumGenerator {
Expr<Integer> sum(GeneratorContext ctx, TreeLogger logger, Arg<Integer>
arg0, Arg<Integer> arg1) {
if(arg0.isLiteral() && arg1.isLiteral()) {
// If both arguments are literals, we sum they at compile time
Integer result = arg0.getValue() + arg1.getValue();
return ctx.compile("return {};", result);
}
// We return a runtime sum
return ctx.compile("return {} + {};", arg0, arg1);
}
}
- Andrés
--
http://groups.google.com/group/Google-Web-Toolkit-Contributors
---
You received this message because you are subscribed to the Google Groups "GWT
Contributors" 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/groups/opt_out.