Posts Tagged ‘groovy’

New in 10.5: Create and open tests for Groovy classes faster

Tuesday, April 26th, 2011

We’ve added a couple of new productivity features in IntelliJ IDEA 10.5 to make working with Groovy tests two bits more pleasant:

1. Now you can create tests for Groovy classes the same way you do in Java. You just need to invoke Create Test intention on the header of the class.

2. To navigate to an existing test from a class you can invoke Go to Test action (Ctrl+Shift+T by default).

Make sure to try it in the latest IntelliJ IDEA 10.5 EAP build.

Quick prototyping in Groovy with “Convert Map to Class” intention

Tuesday, April 19th, 2011

Sometimes it is helpful to use a Map for fast prototyping of classes with some properties but without any logic. But in the end it would be nice to have a real class. In IntelliJ IDEA you can get it by invoking “Convert Map to Class” intention on a map.

You only need to type a name and a package for a new class:

And you’ll get something like this…

and a UserInfo class:

Quick and easy, right?

It is not something new, it’s been in IntelliJ IDEA for a while already. We just felt you might not be aware of it.

New in 10.5: Introduce Refactorings for Groovy

Wednesday, April 13th, 2011

In the upcoming IntelliJ IDEA 10.5 some new Groovy refactorings will appear.

The first of them is Introduce Parameter. It allows you to select any expression inside a method and make from it a new method parameter. All the usages of the method in both Groovy and Java will be auto-updated.
Introduce parameter dialog

The second one is Introduce Field which provides you with an ability to quickly create a new field from any expression inside a class.

No doubt these 2 introduce refactorings will be a good addition to the existing Introduce Constant and Introduce Variable. You are using them, right?

Download the latest EAP build of IntelliJ IDEA 10.5 to try these and other new features and to let us know what you think.

Grails: extracting text from GSP to resource bundle

Wednesday, October 27th, 2010

By user requests we have added functionality for easy extraction of GSP text to resource bundles. To do this you can select a text fragment, press Alt+Enter and choose the intention “Extract selected text to messages.properties”:

I18nize String dialog will open:

This feature is available in IntelliJ IDEA X #98.231

Grails: debugging GSP

Friday, October 22nd, 2010

Now IntelliJ IDEA X is able to debug GSPs. You can set breakpoints and view variable values or evaluate expressions.

Grails: GSP aware of model returned from controller

Wednesday, September 22nd, 2010

As you already know, we are working on GSP editing improvements in IntelliJ IDEA X. In particular, now the editor knows about the variables that the controller supplies to the view.

Example:

Consider an action returning a bookList variable:

And the corresponding GSP file has access to this variable:

Rename, completion and find usages work as they should.

Grails: completion of controller and action names

Wednesday, September 15th, 2010

We have added more Grails-specific completion in IntelliJ Idea X. In particular, IntelliJ IDEA now knows about action and controller names in most places where they can appear.

In the ‘controller’ and ‘action’ attributes of some GSP tags:

In some method calls (e.g. redirect(…), render(…), chain(…)):

In the URL mappings configuration:

Needless to say, find usages and rename work for such references as well.

Grails: Quick navigation between actions and views

Tuesday, September 14th, 2010

IntelliJ Idea X adds quick navigation for Grails actions and GSP pages. Whenever an action has a same-named view, IDEA creates a gutter icon opposite to the action name. Click that icon and the corresponding page is opened:

As for going back, the GSP editor has a link to the appropriate action at the top:

Groovy/Groovy++ object creation

Thursday, August 5th, 2010

Groovy’s as keyword allows for some interesting features. In particular, it provides a convenient syntactic sugar for object creation:

Point point = [4, 2] as Point
KeyAdapter listener = [
        keyTyped: { e -> … },
        keyReleased: { e -> … }
] as KeyAdapter

Still in development, but already quite usable, there is Groovy++: a library which adds static typing, performance and much more to Groovy language. One thing you get addicted to quite soon is that you don’t have to write as in the cases above anymore. If the compiler can statically figure out the expected type, it will insert all the necessary casts for you. This works, for example, for variable declarations, method return types and even method calls. So, if you have

JComponent comp = …

you can then write

if (comp.contains([x:2, y:4])) { … }

Cool, isn’t it? But why am I writing about all this in IntelliJ IDEA blog? Well, just to boast. Unusual syntax is not a reason for not helping you in coding, right? So, now the converted list/map literals will be shown if you search for the constructor usages in IntelliJ IDEA:

And the syntax highlighting on the brackets will help you distinguish between plain list/map literals and the ones that serve for object creation:

Finally, you can easily navigate to the constructor called via a literal. Just place your caret before the opening bracket and go to the declaration (e.g. press Ctrl+B)!

All this will be available in the next IntelliJ IDEA X EAP.

Groovy stacktrace folding

Wednesday, March 17th, 2010

When you look at a typical Groovy stack trace, you usually see something like this:

This is not terribly helpful, since there are only three lines from the actual source code. Everything else refers to Groovy’s internals. From now on, though, reading Groovy stack traces will be much easier: