Add return type declaration
We will now change the return type of the generated method so that the return type is not set to always be Object. We will create a new MQL script on Operation called returnType to return void if the operation does not have a return type, or the name of the classifier being returned. In order to facilitate the creation of this script we will first create a script called hasReturnType which will check if the operation returns a value.
The hasReturnType is an MQL script which is implemented as follows.
public script hasReturnType() : boolean { return self.returns != null; }
The hasReturnType script is now called from a new returnType MQL script created as shown below.
Set the contents of this script to be :
public script returnType() : String { if (self.hasReturnType()) { return self.returns.name; } else { return "Object"; } }
The returnType script is now called from the declaration script on Operation.
[#package tutorial.java] [#metatype rhapsody.Operation] [#script public declaration] public ${self.returnType} ${self.name}() { return null; } [/#script]