Java Syntactic Extender

There’s an interesting project at sourceforge called the Java Syntactic Extender. If you always thought that some control structures were missing in Java, like a proper foreach loop or built-in property support, this is your chance to add them.

“The Java Syntactic Extender”: allows you to add your own keywords and control structures to Java. Some “examples”:

  • unless(expression) { … }, which executes the piece of code unless the expression is true (so it’s like if(!(expression)) { … })
  • property, for example:
  • class Bean implements Serializable {
     public property String firstName = “Tom”;
  • which will generate a setFirstName(…) and getFirstName() method for this field.
  • foreach, for example:
  • List l = …
    foreach (String s in l) {
  • which is nice way of writing:
  • List l = …
    for(Iterator i = l.iterator(); i.hasNext(); ) {
     String s = (String);
  • enum, for example
  • public enum Colours red, blue, green, yellow;
  • Which will create a class called Colours that has the enumerated constants red, blue, green and yellow each of type Colours. All generated enumerated type classes are Serializable and Comparable. These last two, of course, are only useful if you use a version of Java which is older than 1.5, as 1.5 has support for enumerated types and has a kind of for-each statement (slightly different syntax).

I doubt how useful this really is as code is harder to distribute with other people. They would need the same Java language extentions. But still it’s fun to play with on a rainy sunday morning.

You can find more information on “The Java Syntactic Extender”: website.