Here is a checklist of changes you'll need to make to a Groovy classic codebase to ensure compatibility with the new Groovy JSR syntax
- optional gpath argument operator has changed
- parameter seperator in the closure syntax has changed
Safe navigation
In Classic Groovy we used to use this syntax
Instead of using the arrow operator for safe navigation to avoid NullPointerException, we're now using the ?. operator
Now in the JSR we use this syntax
Parameter separator in the closure syntax
This allows us to use one single token for the separator between the closure in Classic Groovy we used to use this syntax
Now in the JSR we use this syntax
This allows us to use one single token for the separator between the closure parameters and the code in in the closure which works with arbitrarily complex parameter list expressions and default values. e.g.
Property keyword
- property keyword has been replaced with an annotation
Introduction of a def keyword
- local variable declarations and fields currently need to be specified with 'def' or a type. e.g.
Array creation
- no special array syntax. To make the language much cleaner, we now have a single syntax to work with lists and arrays in the JSR. Also note that we can now easily coerce from any collection or array to any array type
float and double notation
- float and double literals cannot start with dot. So
This is to avoid ambiguity with things like ranges (1..2) and so forth
'No Dumb Expression' rule
- no dumb expression rule, so we will catch dumb expressions (where a carriage return has broken the script). e.g.
Markup and builders
NOT YET IMPLEMENTED
- markup / builders will change a little. Not sure of the syntax, but we'll have some kinda start/stop syntax to denote a markup block. Maybe a keyword, like
Strings and GStrings
- single and double quote strings can only span one line; for multiple lines use treble quotes
- heredocs removal - they are kinda ugly anyway
. If you want to use them, just use treble quote instead
- escaping of $ inside GStrings must use \$
Assertions
- assert uses comma instead of colon to delimit the two parameter form of assertion statement
return/break/continue semantics in closures
NOT YET IMPLEMENTED
- return/break/continue to behave inside closures like these statements work in other blocks (such as the block on a for() or while() loop. More details here