Could I Have Some SugarJ in my Java?

One of the most interesting demos I saw was for SugarJ, a tool that allows DSLs and syntactic sugaring in Java source code in eclipse. One demo was for adding closures to Java, another for allowing XML document literals with introspection.

How it works is that you can define a transformation of the sugared syntax (which is not legal java) to java, which is then compiled normally. (The closures, for example, were implemented using an anonymous inner class, but the syntax was much cleaner). It even provided warnings if the sugared source was invalid, although it can’t be as robust as java in this regard. Tab completion may be out of the question too. And the compilation cycle was slow, sometimes the editor would slow down for 30 seconds at a time re-building the source to check for errors. Nevertheless, this approach has huge potential for cleaning up Java syntax without needing changes to the JDK itself.

http://www.uni-marburg.de/fb12/ps/research/…

It's only fair to share...
Share on FacebookGoogle+Tweet about this on TwitterShare on LinkedIn

Leave a Reply