Cédric Brun bio photo

Cédric Brun

Building kick-ass products in Eclipse and on Eclipse.

Email Twitter
Eclipse is the best modeling platform around there, even god knows that. What people tend to ignore is that fact that the Eclipse Modeling components are focused on providing framework and tools to actually get some work done, to write better code quicker, and not necessarily model just because it's fun and you can then print huge posters in your office.

What does that mean ? That means if you're writing code you can be pretty sure Eclipse Modeling might help you, do not wait to long to have a look or you'll waste your time and you'll regret that sooner or later. All those gems are available through the Eclipse Modeling bundle and might help for your daily development tasks. I submitted a standard talk for EclipseCon to demonstrate how the Eclipse Modeling Projets might boost your productivity when you integrate them in your development process just like the JDT, PDE or Mylyn, if you want more info, ask for it through the comments! I have no doubt Oisin is wrapping up a great event renewing its spirit; I'm looking forward to it !

To make this post worthy for you, I'll briefly take a spin to one of those gems focusing on pragmatism : Acceleo. Acceleo is all about helping you to generate code in a consistent way, within Eclipse, in a glimpse. To do so you usually use a template language and use some kind of expression substitution. Here the template language is quite powerful, templates might call others and a template might inherit another one. The dispatch to the templates is dynamic depending on the instance type (more specific first) and on the evaluation of any precondition on the templates (That helps you design your templates in a maintainable way).

Enough said about the language, lets focus on the tooling to see how easy it is to leverage it for your coding. Let say you've got a specific pattern you reproduce quite a lot in your code and you don't want to bother writing that code again even if you need it, then let's generate it !

What we've seen is that most of the time you start with an example, and here the example would be the code you write all the day. Acceleo provides a specific tooling to help you starting a template from an example :

In this video you'll see the new template wizard with the option to initialize it with an existing file content, then I'm leveraging the search & replace smart completion to quickly transform the example to a real template I can apply on a model (notice how the "for" closing brace completion auto-magically find a coherent place, it's using the text structure to do so).

In a few minutes you get a first working generation tailored to your specific needs. Of course here it's Java but it might be any language using any framework !
As a sidenote the generation engine allows you to define protected areas in your template allowing you to generate code you can then update by hand and then re-generate without loosing anything.

Stay tuned for more gems.