Evaluating OCL statements

You can evaluate a single Object Constraint Language (OCL) statement to query the characteristics of your metamodel. For example, you can evaluate an OCL statement that returns a simple type, such as a Boolean value, or you can evaluate an OCL statement that returns a list of metamodel objects. If the OCL resource contains multiple OCL statements, the Console view reports that the OCL statements are syntactically incorrect. However, if the OCL resource contains multiple OCL statements, you can evaluate a single selected OCL statement.

Before you begin

To evaluate an OCL statement, you must set the target model to Meta Model. Also, to evaluate an OCL statement, you must have a model or profile open, and have an OCL resource in your workspace.

If any of the following conditions are true when you evaluate an OCL statement, the Console view reports that the OCL statement is syntactically incorrect:
  • An OCL statement refers to an element by its name or fully qualified name, and the element name or fully qualified name contains spaces
  • An OCL statement uses fields whose names are OCL keywords
  • An OCL statement uses enumerations that are defined by a profile

Procedure

  1. In the Project Explorer view, double-click an OCL resource that contains an OCL statement.
  2. At the top of the editor, from the Target Model list, select Meta Model.
  3. In the Context Element field, specify a context element.
  4. Complete one of the following steps:
    • If the OCL resource contains only one OCL statement, click OCL > Evaluate.
    • If the OCL resource contains several OCL statements, right-click one statement; then click Evaluate selected.

Results

If the evaluation is successful, the results from the OCL statement are displayed in the Console view. If the evaluation fails, the first encountered syntax error is displayed in the Console view, and additional information is displayed in the Problems view.

What to do next


Feedback