Roundtripping

It will often be the case that as soon as an application is generated the user will want to modify the generated output in some way and will also want those changes preserved across subsequent regenerations of that application. The ability of the code generator to maintain changes to generated code is called "roundtripping" and is supported by DPTK.

To enable a pattern for roundtripping you need to establish those sections of a pattern template that can be changed by the user and not overwritten by later generations. Use the <roundtrip> and <initialCode> tags to identify those sections of a pattern template that can be modified by the user and which will not be overwritten on subsequent generates:

   public String getValue() {
<roundtrip>
           // Change code after this comment: 132
<initialCode>
      return null;
</initialCode>
           // Change code before this comment: 132
</roundtrip>
   }

In the example above, a Java method is generated with a default body containing two comments and a return statement. The text between the <roundtrip> tag and the <initialCode> tag is treated as a special string that identifies the start of the roundtrip section and the code between the </initialCode> and the </roundtrip> tags is treated as a special string that identifies the end of the roundtrip section. Before the resource (in this case a Java source file) is written to Eclipse, the generator checks to see if (1) the source file alreadys exists and (2) if there is a section of code that begins and ends with the special start and end strings as defined by the <roundtrip> and <initialCode> tags. If both conditions are true, the the existing section of code in the existing version of the resource is used instead of the code inside the <initialCode> tag.

If you want to place more than one <roundtrip> tag in a single template, you need to make the special roundtrip start and end strings unique either by hardcoding a different string (in the example above the number 132 might uniquely identify that section) or by using the <attr>, <content>, <unique> or <sum> tags to generate a unique section begin and end.


© Copyright IBM Corporation 2000, 2005. All Rights Reserved.