How Does It Work?

How Does It Work?

OCL is a programming language, so you will want to edit it and execute it.

Editing

Eclipse OCL supports entry of semantically checked OCL expressions

  • embedded within Ecore using the OCLinEcore editor

  • as complementary documents using the Complete OCL editor

  • interactive entry and evaluation using the Interactive OCL console.

  • programmatic entry and evaluation using the Java API

EMF supports entry of unchecked OCL

  • embedded within Ecore using the Sample Ecore Editor properties view

Papyrus supports entry of semantically checked OCL expressions

Execution

Eclipse OCL supports OCL execution

  • interactive entry and evaluation using the Interactive OCL console.

  • programmatic entry and evaluation using the Java API

EMF support for generated models enables OCL execution of

  • constraints, operation bodies and property initializers using the Java API

EMF support for dynamic models enables OCL execution of

All OCL execution is currently interpreted and starts from the OCL source text (Concrete Syntax). There is therefore a first time parsing overhead to create the compiled form (Abstract Syntax). The compiled form is cached to avoid repeated parsing costs.

The preliminary direct Java code generator is described in the Code Generator Tutorial.

Debugging

Since OCL is used embedded in a larger environment, debugging is not easy to provide for OCL in isolation. The following approaches may be useful.

  • use the hover-text in the semantic editor to understand the expression types

  • use the quick-fixes in the semantic editor for possible corrections

    • if the same fix is suggested more than once, try restarting the editor

  • use the completion assist in the semantic editor for possible syntaxes

  • use intermediate invariants to check partial results

  • use the optional explanation messages for an invariant to provide a 'printf'

  • use the Interactive OCL console to practice a problematic expression on a model

  • use the Java debugger to follow the execution flow

A more OCL-oriented debugger is under consideration to accompany the direct Java code generator.

Testing

Once again, since OCL is used embedded in a larger environment, testing is not easy to provide for OCL in isolation. The following approaches may be useful.

  • use the Interactive OCL console to practice sub-expressions of a problematic expression on a model

The Eclipse OCL development uses an extended JUnit framework that allows the Eclipse OCL code to be tested by assertions such as:

assertQueryInvalid(null, "let b : Boolean = null in true and b");
assertQueryResults(null, "Set{'b'}", "Set{'a', 'b', 'c'} - Set{'c', 'a'}");

(The null first argument may be a context object.)

See the org.eclipse.ocl.examples.xtext.tests plugin for further details.