<< April 3, 2007 | Home | April 5, 2007 >>

Dynamic GroovyEclipse

Extending the IDE for dynamic methods and properties

Before I begin it is important to say:
This is just a demo!

GroovyEclipse can be made aware of dynamic methods and properties by extending the extension point org.codehaus.groovy.eclipse.types. Documentation for the extension point is available in the soon to be released GroovyEclipse 1.0.1.

By implementing this extension point, the types of these dynamic features are integrated into GroovyEclipse. This is important for various reasons:

  1. Large projects will likely inject dynamic types into certain objects. A developer will want code completion for these objects.
  2. Frameworks will likely do the same, Grails being a prime example where dynamic types are injected in many ways. A developer will want completion for say domain object 'find' methods.
  3. Completion is just a side effect of having access to the actual types of methods and properties, whether explicitly defined or dynamic. Types are at the top of the pyramid. Just below is type inference. These two layers are the enablers for completion, code browsing, refactoring, and who knows what other kinds of features.

For a quick demo I implemented basic completion for findBy* and findAll* methods for Grails domain objects. Here are two domain classes:

The sample domain classes

Now in a controller class we get completion for findBy* and one domain class property:

The findBy* method completions

Yes it is only a demo - findByHasMany is incorrect.

Since it is all about the types and not completion specific, the type inference engine resolves the domain object type needed to create a completion list:

Inferred completions on a domain object

Completion is a little enthusiastic showing both the field and the property - another thing to do ...

This next example shows a trick - the findAll* methods return a java.util.List but if we fake it and claim an array is returned, then completions work on the array elements:

Grails findAll* method completion

Array element completions

Being a trick is breaks the default Groovy method completions for java.util.List. In the future when parameterized type signatures are supported, no tricks will be needed.

The code for the above can be found in the GrailsEclipse repository. And remember - it's only a demo! Perhaps someone wants to flesh it out?

The next step in my code completion quest is completion inside of builders. I have just started thinking about it, but in essence a builder describes a tree of nodes. So given a way to describe this tree for the various Groovy builders, we suddenly have completions inside custom builders. Personally, I would love to have SwingBuilder and AntBuilder completions. And then there are the various builders within Grails - what fun!