Wednesday, February 4, 2009

Groovy Dynamic Method Support in IDEA

When IDEA 8 was announced, the press release simply said "Dynamic properties and methods". Uh, okay. I never understood what that meant until I stumbled upon a discussion board post for them.

Here's the explanation:

The JetGroovy plugin underlines expressions in Groovy code that it doesn't recognize. So misspelling a variable or referencing a missing class gives you a visual cue:

Notice how "mystring" is underlined (it is mis-capitalized). But frequently these are valid expressions that will resolve at runtime... for instance, Grails GORM methods. You know these methods will exist so the underlining is annoying. Accepting the Alt+Enter quick-fix on these properties and methods for "Add dynamic property" will add the expression to your list of dynamic expressions. You can view this dynamic expressions in the Dynamic properties panel.

Notice how the "".greetings is not underlined, whereas before it would have been. Also, the expression is now available for code completion:

To remove an expression just select it in the list and press delete on the keyboard.

That's not such a bad feature.

February 10, 2009 is the Groovy IDEA shootout at Groovy.MN... please stop by. And, of course, check out the IDEA Refcardz if you haven't yet.

No comments: