TPL - OptimalJ's templating language

As i mentioned yesterday, one of the issues people have with MDA is, how easy it is to modify generated code, and if these changes are maintained when regenerating code from the models.

The code editor in OptimalJ clearly shows you which parts you can modify (white background) and which parts you can’t touch as showed in this screenshot.

optimalj\_code\_free\_block.png

Whenever you regenerate the code, the added parts in the free blocks will be untouched.

Optimalj has it’s own templating language TPL. Within the template you can specify which parts are guarded, i.e., generated from the models, and which parts are free code, and should be restored after a regeneration. Free parts have an id so they can be identified when regenerating the code. The resulting code looks like this:

/**
 * Converts IssueUpdateObject into a IssueDataObject.
 */
public IssueDataObject(IssueUpdateObject updateObject) { 
    this.setId(updateObject.getId());
    this.setSummary(updateObject.getSummary());
    this.setPriority(updateObject.getPriority());
    this.setIssueType(updateObject.getIssueType());
    this.setDateCreated(updateObject.getDateCreated());
    this.setDescription(updateObject.getDescription());
//GEN-FREE-GEN:toDataObject$$DATAOBJECT$pidf6aef9ffd57bc7d
    // your code here
//GEN-GUARD:1$$DATAOBJECT$pidf6aef9ffd57bc7d
}
blog comments powered by Disqus