Generate UML parameters

Create a Text script named declaration on the type uml21.Parameter, and change the contents of the created uml21_Parameter.mqs to:

[#package tutorial.java]

[#metatype uml21.Parameter]

[#script public declaration]
${self.type.name} ${self.name}[#rtrim]
[/#script]

This text script output is designed to be inserted between the parenthesis of the Java method declaration. The rtrim directive is used to ignore the line feed.

Now re-open the script declaration defined on uml21.Operation and change its implementation to:

[#package tutorial.java]

[#metatype uml21.Operation]

[#script public declaration]
    [#set parameters = self.inParameters.concat("declaration", ", ")]
    public ${self.returnType.name} ${self.name}(${parameters}) {
        return null; // TODO insert your code here
    }
    
[/#script]

Now this script calls the script inParameters, which returns an MDWList, and uses the concat method to:

  1. call the script declaration on each parameter of the list,
  2. concatenate each parameter declaration into a String, using ", " as separator.

The result of the concatenation is assigned to a local variable parameters.

Relaunch the generation and open the file Order.java:

public abstract class Order {

    private String date;
    private LineItem items;
    private Customer customer;

    public LineItem findLineItem(String productName) {
        return null; // TODO insert your code here
    }
    
}

Related reference
MDWList
set directive