Include a Javadoc template

In this step, we will add a javadoc to the generated Java file, introducing template inclusion.

First create a Javadoc template:

  1. Click File > New > Text Template.
  2. Type JavaGeneration/src in the Source folder field.
  3. Type tutorial.java in the Package field.
  4. Type Javadoc in the Name field.
  5. Click Finish.

Change the Javadoc.tgt contents to:

[#package tutorial.java]

[#template public Javadoc()]
/*
 * Generated by ${System.getProperty("user.name")}
 * on ${java.util.Calendar.getInstance().getTime()}
 */
[/#template]

Note that this template does not define a file directive: it means this template is not a generation entry-point, it's a fragment designed to be included in another template. This template does not expect any parameter.

This template uses the getProperty() method of the class java.lang.System to retrieve the name of the current user. It also uses the class java.util.Calendar to compute the current time.

We can include this Javadoc in the template JavaSource.tgt:

[#package tutorial.java]

[#template public JavaSource(class : rhapsody.Class)]
[#file]generated/${class.name}.java[/#file]
[#include Javadoc()]
public class ${class.name} {
...

Relaunch the generation and open the file Order.java:

/*
 * Generated by IBM
 * on Thu Mar 12 19:29:12 CEST 2009
 */
public class Order {
...

Related reference

include directive