blob: 6adf3c3f3fdc90eb9063a7b465f4e5a38730bc5b [file] [log] [blame]
<html>
<head>
<META http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Content Assist Support</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="ProgrammersGuide.html" title="Classic Ecore/UML Programmers Guide">
<link rel="prev" href="TargetMetamodels.html" title="OCL Relationship to Metamodels">
<link rel="next" href="AbstractSyntax.html" title="OCL Abstract Syntax Model">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<h1 xmlns:l="http://docbook.sourceforge.net/xmlns/l10n/1.0">Content Assist Support</h1>
<div class="section" title="Content Assist Support">
<div class="titlepage">
<div>
<div>
<h2 class="title" style="clear: both">
<a name="ContentAssistSupport"></a>Content Assist Support</h2>
</div>
</div>
</div>
<div class="blockquote">
<blockquote class="blockquote">
<p>
The Content Assist facilities described here are used by the Interactive OCL Console. They are not used by the new Xtext-based Editors or the Interactive Xtext OCL Console.</p>
</blockquote>
</div>
<p>
The
<a class="ulink" href="http://download.eclipse.org/ocl/javadoc/6.4.0/org/eclipse/ocl/helper/OCLHelper.html" target="_new">
<code class="code">OCLHelper</code>
</a> API provides support for content-assist in rich editors, by parsing partial OCL
expressions and supplying completion suggestions. The
<code class="code">List&lt;Choice&gt; getSyntaxHelp(ConstraintKind, String)</code> operation
returns a list of suggestions for the next token to follow the end of the
expression fragment.
</p>
<p>
</p>
<div class="mediaobject">
<img src="images/5140-contentassist.png"></div>
<p>
</p>
<p>The
<a class="ulink" href="http://download.eclipse.org/ocl/javadoc/6.4.0/org/eclipse/ocl/helper/Choice.html" target="_new">
<code class="code">Choice</code>
</a> objects returned by the helper include some convenient text strings (name and
description) to formulate basic JFace content-assist proposals. Each choice
also carries a reference to the element that it represents, the kind of element
indicated by the
<code class="code">ChoiceKind</code> enumeration, for a more
sophisticated content assist that might inlude context information, documentation,
etc. as in Eclipse JDT. The list of choices depends in part on the kind of
constraint expression that is to be completed, as for example, the
<code class="code">oclIsNew()</code> operation is only permitted in operation
post-conditions.
</p>
<div class="literallayout">
<p>
<code class="code">helper.setContext(EXTLibraryPackage.Literals.BOOK);<br>
<br>
List&lt;Choice&gt;&nbsp;choices&nbsp;=&nbsp;helper.getSyntaxHelp(ConstraintKind.INVARIANT,<br>
&nbsp;&nbsp;&nbsp;&nbsp;"Book.allInstances()-&gt;collect(author)-&gt;");<br>
<br>
for&nbsp;(Choice&nbsp;next&nbsp;:&nbsp;choices)&nbsp;{<br>
&nbsp;&nbsp;&nbsp;&nbsp;switch&nbsp;(next.getKind())&nbsp;{<br>
&nbsp;&nbsp;&nbsp;&nbsp;case&nbsp;OPERATION:<br>
&nbsp;&nbsp;&nbsp;&nbsp;case&nbsp;SIGNAL:<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;the&nbsp;description&nbsp;is&nbsp;already&nbsp;complete<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(next.getDescription());<br>
&nbsp;&nbsp;&nbsp;&nbsp;case&nbsp;PROPERTY:<br>
&nbsp;&nbsp;&nbsp;&nbsp;case&nbsp;ENUMERATION_LITERAL:<br>
&nbsp;&nbsp;&nbsp;&nbsp;case&nbsp;VARIABLE:<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(next.getName()&nbsp;+&nbsp;"&nbsp;:&nbsp;"&nbsp;+&nbsp;next.getDescription();<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;<br>
&nbsp;&nbsp;&nbsp;&nbsp;default:<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(next.getName());<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;<br>
&nbsp;&nbsp;&nbsp;&nbsp;}<br>
}<br>
</code>
</p>
</div>
<p></p>
<div class="section" title="Syntax Completion Choices">
<div class="titlepage">
<div>
<div>
<h3 class="title">
<a name="SyntaxCompletionChoices"></a>Syntax Completion Choices</h3>
</div>
</div>
</div>
<p>The computation of
<code class="code">Choice</code> s is supported for the
following tokens, which may be used by a client as auto-assist triggers:
</p>
<table id="N14DF1">
<tr>
<th>Token</th>
<th>Completion choices</th>
</tr>
<tr>
<td>
<code class="code">.</code>
</td>
<td>Features applicable to the type of the expression to the left of the dot, or its element type if it is a collection. association classes (in the UML environment only)</td>
</tr>
<tr>
<td>
<code class="code">-&gt;</code>
</td>
<td>Collection operations and iterators</td>
</tr>
<tr>
<td>
<code class="code">::</code>
</td>
<td>Packages, types, enumeration literals, and states (in the UML environment only)</td>
</tr>
<tr>
<td>
<code class="code">^</code>
</td>
<td>Operations and signals (in the UML environment only)</td>
</tr>
<tr>
<td>
<code class="code">^^</code>
</td>
<td></td>
</tr>
<tr>
<td></td>
<td>In other situations, the choices the current context variables and implicit references to features of the
<code class="code">self</code> variable. For example, if the input is something like
<code class="code">""</code> or
<code class="code">"self.isOrdered and "</code>
</td>
</tr>
</table>
<p>
<span class="bold"><strong>Content-assist triggers</strong></span>
</p>
<p>The completion of partially specified identifiers is also supported, by
backtracking to look for one of these triggering tokens. This supports
interactively narrowing the choices while the content-assist window is active.</p>
<div class="literallayout">
<p>
<code class="code">choices&nbsp;=&nbsp;helper.getSyntaxHelp(ConstraintKind.POSTCONDITION,<br>
&nbsp;&nbsp;&nbsp;&nbsp;"self.author.oclIs");<br>
</code>
</p>
</div>
<p></p>
</div>
</div>
</body>
</html>