How Does It Work?

How Does It Work?

OCL is a programming language, so you will want to edit it, execute it and debug 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

Eclipse UML supports entry of unchecked OCL

  • embedded within UML OpaqueExpressions using the UML Model Editor properties view

Papyrus supports entry of semantically checked OCL expressions

  • embedded within UML OpaqueExpressions using the Essential OCL editor

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 normally 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.

Altenatively the direct Java code generator may be used as 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 OCL debugger provides a variety of launch mechanisms that enable re-use of model element and/or constraint selections.

Alternatively the following approaches may be useful within other toosl

  • 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 Xtext OCL console to practice a problematic expression on a model

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 Xtext 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.xtext.tests plugin for further details.