How does it work?
Groovy++ compiler is extension of standard Groovy compiler. Thanks to open architecture of Groovy both work together and no special build tools or directives are required. The only requirement is to have groovypp.jar in your classpath and use mature enough version of Groovy
As of now (Groovy++ v0.0.4.150) Groovy 1.7.6 is minimally required version of Groovy. Anyway, the version of Groovy distributed with Groovy++ always should work fine both for normal Groovy and Groovy++.
The minimal unit of statically typed compilation is one method. You can also instruct compiler that whole class (including inner classes) or whole source file.
To make piece of code(method, class or whole file) statically typed we just need to add @Typed annotation. In the code above we just annotate the package declaration, which means whole script is statically typed. All code out of the scope of @Typed annotation is compiled dynamically as in standard Groovy.
There is alternative experimental way to make full source file statically compilable. To achieve that you just need to change extension of your file from .groovy to .gpp
You can easily combine statically typed and dynamic methods inside one and the same class. For example, you can have dynamic (as in regular Groovy) method inside statically compiled class class. Annotation @Typed(TypePolicy.DYNAMIC) or @Typed(TypePolicy.MIXED) will do the job
Mixed mode is special mode of compilation when compiler does not report bugs for properties or methods which it is not able to resolve but instead generate dynamic calls or property access (in other words compiler assume that any unresolved method or property access is dynamic). While being not type safe this approach allows easy combination in one method of efficient calculations with for example building of markup
@Typed
class StaticallyTyped {
def staticMethod () {
// all code will be statically compiled
}
@Typed(TypePolicy.DYNAMIC)
def dynamicMethod () {
// all code will be dynamically compiled
}
@Typed(TypePolicy.MIXED)
def mixedMethod () {
// will be called statically
staticMethod ()
// will be called dynamically
unexistingMethod ()
}
}