blob: d85aa30f290bda00e95c59f085005ab312ea1782 [file] [log] [blame]
<html>
<head>
<META http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>How Does It Work?</title>
<link href="book.css" rel="stylesheet" type="text/css">
<meta content="DocBook XSL Stylesheets V1.75.1" name="generator">
<link rel="home" href="index.html" title="OCL Documentation">
<link rel="up" href="OverviewandGettingStarted.html" title="Overview and Getting Started">
<link rel="prev" href="OverviewandGettingStarted.html" title="Overview and Getting Started">
<link rel="next" href="EclipseOCLisExtensible.html" title="Eclipse OCL is Extensible">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<h1 xmlns:l="http://docbook.sourceforge.net/xmlns/l10n/1.0">How Does It Work?</h1>
<div class="section" title="How Does It Work?">
<div class="titlepage">
<div>
<div>
<h2 class="title" style="clear: both">
<a name="HowDoesItWork"></a>How Does It Work?</h2>
</div>
</div>
</div>
<p>OCL is a programming language, so you will want to edit it, execute it and debug it.</p>
<div class="section" title="Editing">
<div class="titlepage">
<div>
<div>
<h3 class="title">
<a name="Editing"></a>Editing</h3>
</div>
</div>
</div>
<p>Eclipse OCL supports entry of semantically checked OCL expressions</p>
<div class="itemizedlist">
<ul class="itemizedlist" type="disc">
<li class="listitem">
<p>embedded within Ecore using the
<a class="link" href="OCLinEcore.html" title="The OCLinEcore Language">OCLinEcore</a> editor
</p>
</li>
<li class="listitem">
<p>as complementary documents using the
<a class="link" href="CompleteOCL.html" title="The Complete OCL Language">Complete OCL</a> editor
</p>
</li>
<li class="listitem">
<p>interactive entry and evaluation using the
<a class="link" href="InteractiveOCL.html" title="Console">Interactive OCL</a> console.
</p>
</li>
<li class="listitem">
<p>programmatic entry and evaluation using the
<a class="link" href="ProgrammersGuide.html" title="Classic Ecore/UML Programmers Guide">Java API</a>
</p>
</li>
</ul>
</div>
<p>EMF supports entry of unchecked OCL</p>
<div class="itemizedlist">
<ul class="itemizedlist" type="disc">
<li class="listitem">
<p>embedded within Ecore using the Sample Ecore Editor properties view</p>
</li>
</ul>
</div>
<p>Eclipse UML supports entry of unchecked OCL</p>
<div class="itemizedlist">
<ul class="itemizedlist" type="disc">
<li class="listitem">
<p>embedded within UML OpaqueExpressions using the UML Model Editor properties view</p>
</li>
</ul>
</div>
<p>
<a class="link" href="OCLinPapyrus.html" title="OCL in UML (using Papyrus)">Papyrus</a> supports entry of semantically checked OCL expressions
</p>
<div class="itemizedlist">
<ul class="itemizedlist" type="disc">
<li class="listitem">
<p>embedded within UML OpaqueExpressions using the
<a class="link" href="EssentialOCL.html" title="The Essential OCL Language">Essential OCL</a> editor
</p>
</li>
</ul>
</div>
</div>
<div class="section" title="Execution">
<div class="titlepage">
<div>
<div>
<h3 class="title">
<a name="Execution"></a>Execution</h3>
</div>
</div>
</div>
<p>Eclipse OCL supports OCL execution</p>
<div class="itemizedlist">
<ul class="itemizedlist" type="disc">
<li class="listitem">
<p>interactive entry and evaluation using the
<a class="link" href="InteractiveOCL.html" title="Console">Interactive OCL</a> console.
</p>
</li>
<li class="listitem">
<p>programmatic entry and evaluation using the
<a class="link" href="ProgrammersGuide.html" title="Classic Ecore/UML Programmers Guide">Java API</a>
</p>
</li>
</ul>
</div>
<p>EMF support for generated models enables OCL execution of</p>
<div class="itemizedlist">
<ul class="itemizedlist" type="disc">
<li class="listitem">
<p>constraints, operation bodies and property initializers using the
<a class="link" href="ProgrammersGuide.html" title="Classic Ecore/UML Programmers Guide">Java API</a>
</p>
</li>
</ul>
</div>
<p>EMF support for dynamic models enables OCL execution of</p>
<div class="itemizedlist">
<ul class="itemizedlist" type="disc">
<li class="listitem">
<p>constraints using the
<a class="link" href="Delegates.html#ValidationDelegate" title="Validation Delegates">Validation Delegate</a> API
</p>
</li>
<li class="listitem">
<p>operation bodies using the
<a class="link" href="Delegates.html#InvocationDelegate" title="Invocation Delegates">Invocation Delegate</a> API
</p>
</li>
<li class="listitem">
<p>property initializers using the
<a class="link" href="Delegates.html#SettingDelegate" title="Setting Delegates">Setting Delegate</a> API
</p>
</li>
<li class="listitem">
<p>queries using the
<a class="link" href="Delegates.html#QueryDelegate" title="Query Delegates">Query Delegate</a> API
</p>
</li>
</ul>
</div>
<p>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. </p>
<p>Altenatively the direct Java code generator may be used as described in the
<a class="link" href="CodeGenerationTutorial.html" title="Code Generation tutorial">Code Generator Tutorial</a>.
</p>
</div>
<div class="section" title="Debugging">
<div class="titlepage">
<div>
<div>
<h3 class="title">
<a name="Debugging"></a>Debugging</h3>
</div>
</div>
</div>
<p>Since OCL is used embedded in a larger environment, debugging is not easy to provide for OCL in isolation. The
<a class="link" href="Debugger.html" title="Debugger (new in Luna)">OCL debugger</a> provides a variety of launch mechanisms that enable re-use of model element and/or constraint selections.
</p>
<p>Alternatively the following approaches may be useful within other toosl</p>
<div class="itemizedlist">
<ul class="itemizedlist" type="disc">
<li class="listitem">
<p>use the hover-text in the semantic editor to understand the expression types</p>
</li>
<li class="listitem">
<p>use the quick-fixes in the semantic editor for possible corrections</p>
<div class="itemizedlist">
<ul class="itemizedlist" type="circle">
<li class="listitem">
<p>if the same fix is suggested more than once, try restarting the editor</p>
</li>
</ul>
</div>
</li>
<li class="listitem">
<p>use the completion assist in the semantic editor for possible syntaxes</p>
</li>
<li class="listitem">
<p>use intermediate invariants to check partial results</p>
</li>
<li class="listitem">
<p>use the optional explanation messages for an invariant to provide a 'printf'</p>
</li>
<li class="listitem">
<p>use the
<a class="link" href="InteractiveOCL.html" title="Console">Interactive Xtext OCL</a> console to practice a problematic expression on a model
</p>
</li>
</ul>
</div>
</div>
<div class="section" title="Testing">
<div class="titlepage">
<div>
<div>
<h3 class="title">
<a name="Testing"></a>Testing</h3>
</div>
</div>
</div>
<p>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.</p>
<div class="itemizedlist">
<ul class="itemizedlist" type="disc">
<li class="listitem">
<p>use the
<a class="link" href="InteractiveOCL.html" title="Console">Interactive Xtext OCL</a> console to practice sub-expressions of a problematic expression on a model
</p>
</li>
</ul>
</div>
<p>The Eclipse OCL development uses an extended JUnit framework that allows the Eclipse OCL code to be tested by assertions such as:</p>
<div class="literallayout">
<p>
<code class="code">assertQueryInvalid(null,&nbsp;"let&nbsp;b&nbsp;:&nbsp;Boolean&nbsp;=&nbsp;null&nbsp;in&nbsp;true&nbsp;and&nbsp;b");<br>
assertQueryResults(null,&nbsp;"Set{'b'}",&nbsp;"Set{'a',&nbsp;'b',&nbsp;'c'}&nbsp;-&nbsp;Set{'c',&nbsp;'a'}");<br>
</code>
</p>
</div>
<p>(The null first argument may be a context object.)</p>
<p>See the org.eclipse.ocl.examples.xtext.tests plugin for further details.</p>
</div>
</div>
</body>
</html>