Creating J operations

 

Creating an operation

J operations are created on metaclass references defined in a J profile implementation (that is, a subset of metaclass references that can be defined in a J MDA component) by clicking on the  icon.

 

Steps:

1.      Select a metaclass reference defined in a J profile implementation.

2.      Click on the  icon. The “Operation” window then appears.

3.      Enter a name for your new operation.

4.      Confirm by clicking on “OK”.

 

Figure 94. The “J operation” dialog box (“Declaration” tab)

 

Key for “Declaration” tab:

·         Name”: This field is used to enter the name of the operation you are about to create.

·         Input / output parameters”: This list is used to enter the parameters of the operation.

·         Return parameter”: This field is used to enter the type returned by the operation.

·          

Input / output parameters

The icons appearing in the “Input / output parameters” zone can be used to run the following commands:

 

Icon

Description

This icon is used to add a new parameter.

This icon is used to remove the selected parameter.

This icon is used to move the selected parameter up.

This icon is used to move the selected parameter down.

 

The declaration of the parameters must have the following syntax:

<passingmode> <type>[] <parameterName>

 

Key:

·         <passingmode>: “in”, “inout” or “out”. The passing mode is optional. If it is omitted, then the passing mode is “in”. The “out” and “inout” passing mode is identical. The keywords can be in lowercase or uppercase.

·         <type>: Type of the parameter. This type can be a basic type (int, boolean, string, …), a metaclass name (Class, Attribute, Package, …), or a stereotype name (create, access, …). The type can be written in lowercase. The type is search for in the realized profile and in the metamodel.

·         []: designates that the parameter is a set of elements. These characters are optional.

·         <parameterName>: name of the parameter

·          

Examples:

in Class myClass

out Package myPackage

inout string[] elements

 

Return parameter

This field is used to define the type returned by the operation. This type can be a basic type (int, boolean, string, …), a metaclass name (Class, Attribute, Package, …), or a stereotype name (create, access, …).

To return a set of elements, add “[]” after the type.

Examples: Class[], string[], …

 

J code

In the “Code” tab, the J code of the operation can be defined.

 

Figure 95. The “J operation” dialog box (“Code” tab)

 

Toolbar

The icons appearing in the “MDA” tab of the auxiliary window can be used to run the following commands:

 

Icon

Description

This icon is used to edit the J code.

See “Editing J code” for further information.

This icon is used to check that the operation has been correctly modeled.