|
[Previous] [Overview] [Next]
Protecting your Developers' Code
Generated code usually isn't perfect. Not all information is contained in model and templates, some needs to be added manually. With simple code generators the manual changes are lost during re-generation. iQgen solves this problem with usercode blocks.
During each generation the output directory is checked for files from earlier runs. If these files exist, the contents of protected sections of these files are inserted into the newly generated files. These special sections are marked as usercode blocks. Here is an example for adding custom imports to a Java file:
[...]
<%@ taglib uri="iqgen" prefix="iqgen" %>
<iqgen:usercode id="imports">
// your own imports
</iqgen:usercode>
<iqgen:import prefix="<%=getPrefix()%>" collectiontype="java.util.Collection"/>
[...]
|
To use the usercode tag you have to register the iqgen taglib. Once this is done, you may mark a section of the template with the tag. Make sure that you specify a unique id attribute in the opening tag. This ensures that the right piece of code is merged into this section.
In the generated code the section will look like this:
[...]
//==> Begin Protected Area imports
// your own imports
//==> End Protected Area imports
[...]
|
Never modify the //==> [...] Protected Area [...] lines!
Alternatively to the id attribute you can also set a modelelement as attribute element:
[...]
<%@ taglib uri="iqgen" prefix="iqgen" %>
<iqgen:usercode element="<%=getElement()%>">
// your own code for the current modelelement
</iqgen:usercode>
[...]
|
Please note that id and element are mutually exclusive.
Next section.
|