GContracts 1.2.11 Sneak Peak - Improved IDE Support

GContracts [0] is a "Design-by-Contract" implementation for Groovy. It adds the concept of programming by contract to the Groovy programming language by adding a single JAR file without third-party dependencies to the class-path. Here is a short preview for the upcoming 1.2.11 release. In the very beginning, GContracts was based on a "hidden" feature in Groovy 1.7: closure annotation parameters. As this was kind of a hidden trick, there was only accidental support for this feature in IDEs. This changed with the release of Groovy 1.8, which officially released the feature of closure annotation parameters. Another missing piece besides supporting closure annotation parameters was the possibility to let the IDE know about implicit variables added by GContracts during compile-time. This was especially needed for the @Ensures annotation's result and old variables. With the ongoing support for custom DSLs, I am happy to announce improved support in this area for the Eclipse Groovy/Grails Toolsuite (GGTS) and Intellij 12.1 [1] and upwards.

Unresolved Variables EVERYWHERE

As of today, GContracts provides only a small - yet powerful - set of annotations: @Requires, @Ensures and @Invariant @Ensures - the annotation to define postconditions - is a special case. It adds two implicit variables to the closure code block: old and result. result is available in the case the target method is a non-void instance method and resembles the method's return value. old is a map and resembles all parameter and property values before a method call. The problem with implicitly introduced variable names in DSLs is their support in IDEs. Up to now, neither IntelliJ nor Eclipse did recognize the old and result variables. With the upcoming 1.2.11 release, GContracts comes with bundled GDSL and DSDL files, to extend the IDE inference mechanisms: Note, the inferred result variable is typed with the declared return type of the corresponding method. In the case of a void method, the variable is not available in the auto-completion dialog.

At time of writing, the old variable is simply typed as being of type java.util.Map. I will try to add some more logic to provide this variable only when it makes sense in the current context.

And now?

I am looking forward to release 1.2.11 until the next couple of days. There is "only" one bug pending being a class-loading issue, d'oh ;-)

[0] GContracts - Programming by Contract for Groovy
[1] IntelliJ YouTrack - IDEA 98773