Filter UML parameters

Create a new MQL script named returnType on the type uml21.Operation, and change the contents of the created uml21_Operation.mqs file to:

package tutorial.java;

import com.sodius.mdw.metamodel.uml21.ParameterDirectionKind;

metatype uml21.Operation;

public script returnType() {
    return self.ownedParameter.detect("direction",
        com.sodius.mdw.metamodel.uml21.ParameterDirectionKind.RETURN_LITERAL).type;
}

Here is the behavior of this returnType script:

  1. Retrieves the parameters of the operation on which the script is evaluated (answers an MDWList).
  2. Uses the detect() method to evaluate the attribute direction on each parameter of this list. This method will return the first parameter of the list whose direction is equal to ParameterDirectionKind.RETURN_LITERAL.
  3. Returns the type of the return parameter, or null if there is no return parameter (due to MDWorkbench's null management).

Create a second MQL script named inParameters:

package tutorial.java;

import com.sodius.mdw.metamodel.uml21.ParameterDirectionKind;

metatype uml21.Operation;

public script returnType() {
    return self.ownedParameter.detect("direction",
        com.sodius.mdw.metamodel.uml21.ParameterDirectionKind.RETURN_LITERAL).type;
}

public script inParameters() {
    return self.ownedParameter.reject("direction",
        com.sodius.mdw.metamodel.uml21.ParameterDirectionKind.RETURN_LITERAL);
}

This inParameters script does the opposite job of the returnType script: it uses the reject method to keep only the parameters whose direction is not ParameterDirectionKind.RETURN_LITERAL.

You can navigate these scripts using the Scripts view.

Related tasks
Scripts view

Related reference
MDWList