Tuesday, May 25, 2010

Acceleo Pre-Conditions to improve adaptability

Imagine you want to implement different behavior for a code generation template depending on certain conditions.

One way to do that would be to use if blocks to distinguish between those cases.
Another, more elegant, way is to use pre-conditions. Let's say that you want to generate different code for associations whether or not they are declared ordered.


The above example shows the ? (condition) syntax that tells Acceleo that the template must only be run if the pre-condition is satisfied.

No comments: