Evaluate OCL Constraints for Model Instances

Aus SDQ-Wiki

Tutorial / HowTo

For this tutorial we use the example "Interactive OCL" console provided by the Eclipse OCL project. The "Interactive OCL" console is especially useful for debugging OCL constraints.

  • There are two options to get the OCL SDK
    1. Use the Update Site http://download.eclipse.org/modeling/mdt/updates/releases/ or
    2. Manually download the latest version of the OCL SDK (Runtime, Source); for example this one and the latest version of the OCL example (the OCL example contains the console!).
      • Copy the plugins and features folder to a Eclipse installation (for example Eclipse 3.5 for the above linked files). This Eclipse installation should include all "Build Dependencies" from the OCL download site.
  • After starting Eclipse, switch on the Console:


  • Then switch on the "Interactive OCL" console:


  • The Interactive OCL console should look like this:


  • To check a constraint, open a EMF model (or a GMF diagram), select a model element ("Interf1" in the example), enter a OCL constraint ("self.signatures__Interface.serviceName = Bag{'ServiceName1'}" in the example), and evaluate by pressing ENTER. The OCL engine will return a boolean value, the queried sets, or error messages:


Using the PCM Base Package

If you use the PCM Eclipse Base Package you simply need to install the OCL example download (this one includes the interactive OCL console).

Tips and Tricks

Examples for OCL usage can be found in the source code of the test cases, here for example for defining operations and attributes.

Instalation: ModelTool (MDT) update needed, check OCL_SDK and OCL Examples

See also

Keywords: OCL, oclocl, object constraint language, EMF, model, expression, expressions, auto completion, auto-completion, tab-completion, debug, debugging, tool, plugin, eclipse