| <!DOCTYPE html |
| PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "../xhtml1-strict.dtd"> |
| <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> |
| <head> |
| <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> |
| <link rel="stylesheet" type="text/css" href="../css/ot.css" /> |
| <link rel="stylesheet" type="text/css" href="../css/otjld.css" /> |
| <title>OT/J Language Definition v1.3</title> |
| </head> |
| <body class="otdt"> |
| <div id="content"> |
| <table class="nav"> |
| <tr> |
| <td class="back"><a id="top"></a><a href="s4.2.html" rel="prev"><< §4.2 Callin modifiers (before, after, replace)</a></td> |
| <td class="top"><a href="index.html" rel="contents">↑ Table of Contents ↑</a></td> |
| <td class="next"><a href="s4.4.html" rel="next">§4.4 Callin parameter mapping >></a></td> |
| </tr> |
| </table> |
| <div class="breadcrumb"><a class="nav" href="s4.html" rel="section">§4 Callin Binding</a></div> |
| <div class="sect depth2" id="s4.3"> |
| <h2 class="sect">§4.3 Base calls<a class="img" href="s4.3.html" title="PermaLink to §4.3 Base calls"><img style="vertical-align:text-top;margin-left:5px;" src="../images/permalink.png" |
| alt="" /></a></h2> |
| <div class="syntaxlink"><a href="sA.html#sA.5.3" title="§A.5.3 BaseCall" class="syntax">→ Syntax §A.5.3</a></div> |
| <p>Role methods with a <code>callin</code> modifier should contain |
| a <em>base call</em> which uses the special name <code>base</code> |
| in order to invoke the original base method (original means: before replacement). |
| |
| </p> |
| <div class="subsect depth3" id="s4.3.a"> |
| <h4 class="subsect">(a) <span class="title">Syntax</span><a class="img" href="s4.3.a.html" title="PermaLink to (a) Syntax"><img style="vertical-align:text-top;margin-left:5px;" src="../images/permalink.png" |
| alt="" /></a></h4> |
| <p>The syntax for base calls is <code>base.m()</code>, |
| which is in analogy to super calls. |
| A <code>base.m()</code> call must use the same name and signature |
| as the enclosing method. This again follows the rule, that roles |
| should never explicitly use base names, except in binding declarations. |
| |
| </p> |
| </div> |
| <div class="subsect depth3" id="s4.3.b"> |
| <h4 class="subsect">(b) <span class="title">Missing base call</span><a class="img" href="s4.3.b.html" |
| title="PermaLink to (b) Missing base call"><img style="vertical-align:text-top;margin-left:5px;" src="../images/permalink.png" |
| alt="" /></a></h4> |
| <p>For each callin method, the compiler uses some flow analysis to check whether |
| a base call will be invoked on each path of execution (analysis is very similar |
| to the analysis for definite assignment regarding final variables - |
| <a href="http://java.sun.com/docs/books/jls/third_edition/html/defAssign.html" |
| class="ext">JLS §16</a>). |
| The compiler will issue a warning if a base call is missing either |
| on each path (definitely missing) or on some paths (potentially missing). |
| Instead of directly invoking a base call, a callin method may also call |
| its explicit or implicit super version using <code>super.m()</code> or <code>tsuper.m()</code> (see <a href="s1.3.1.f.html" title="§1.3.1.(f) tsuper" class="sect">§1.3.1.(f)</a>). |
| In this case the flow analysis will transitively include the called super/tsuper version. |
| |
| </p> |
| </div> |
| <div class="subsect depth3" id="s4.3.c"> |
| <h4 class="subsect">(c) <span class="title">Duplicate base call</span><a class="img" href="s4.3.c.html" |
| title="PermaLink to (c) Duplicate base call"><img style="vertical-align:text-top;margin-left:5px;" src="../images/permalink.png" |
| alt="" /></a></h4> |
| <p>If a callin method contains several base calls, the compiler gives |
| a warning if this will result in duplicate base call invocations on all |
| paths (definitely duplicate) or on some paths (potentially duplicate). |
| Again super/tsuper calls are included in the flow analysis (see 4.3(b)). |
| |
| </p> |
| </div> |
| <div class="subsect depth3" id="s4.3.d"> |
| <h4 class="subsect">(d) <span class="title">Parameter tunneling</span><a class="img" href="s4.3.d.html" |
| title="PermaLink to (d) Parameter tunneling"><img style="vertical-align:text-top;margin-left:5px;" src="../images/permalink.png" |
| alt="" /></a></h4> |
| <p>If a base method has more parameters |
| than a callin method to which it is composed, additional |
| parameters are implicitly passed unchanged from the original |
| call to the base call (original means: before interception). |
| I.e., a call <code>base.m()</code> may invisibly pass additional |
| parameters that were provided by the caller, but are hidden from the |
| role method. |
| |
| </p> |
| </div> |
| <div class="subsect depth3" id="s4.3.e"> |
| <h4 class="subsect">(e) <span class="title">Fragile callin binding</span><a class="img" href="s4.3.e.html" |
| title="PermaLink to (e) Fragile callin binding"><img style="vertical-align:text-top;margin-left:5px;" src="../images/permalink.png" |
| alt="" /></a></h4> |
| <p>If a role method returns void, but the bound base method declares a |
| non-void result, this is reported as a <em>fragile callin binding</em>: |
| The result can still be provided by the base call, but omitting the |
| base call may cause problems depending on the return type: |
| |
| </p> |
| <ul> |
| <li>For reference return types <code>null</code> will be returned |
| in this case. |
| </li> |
| <li>In the case of primitive return types this will cause a |
| <code>ResultNotProvidedException</code> at run-time. |
| </li> |
| </ul> |
| <p>It is an error if a callin method involved in a fragile callin binding |
| has definitely no base call. |
| |
| </p> |
| </div> |
| <div class="subsect depth3" id="s4.3.f"> |
| <h4 class="subsect">(f) <span class="title">Base super calls</span><a class="img" href="s4.3.f.html" title="PermaLink to (f) Base super calls"><img style="vertical-align:text-top;margin-left:5px;" src="../images/permalink.png" |
| alt="" /></a></h4> |
| <p>If a callin method <code>rm</code> is bound to a base method <code>B1.m</code> |
| that in turn overrides an inherited method <code>B0.m</code> |
| (<code>B0</code> is a super class of <code>B1</code>), |
| the callin method may use a special form of a base call denoted as |
| |
| </p> |
| <div class="listing plain"><pre><strong>base.super</strong>.rm();</pre></div> |
| <p>Such base super call invokes the super method of the bound base method, |
| here <code>B0.m</code>. This invocation is not affected by any further callin binding. |
| |
| </p> |
| <p>A base super call bypasses both the original method <code>B1.m</code> and |
| also other callin bindings that would be triggered by a regular base call. |
| For this reason any application of this construct is flagged by a decapsulation warning |
| (see <a href="s3.4.html" title="§3.4 Overriding access restrictions" |
| class="sect">§3.4</a>). |
| |
| </p> |
| </div> |
| <div class="note"> |
| <h5>Comment:</h5> |
| Base calls can occur in callin methods that are not |
| yet bound. These methods have no idea of the names of base methods that |
| a sub-role will bind to them. Also multiple base methods may be bound |
| to the same callin method. |
| Hence the use of the role method's own name and signature. |
| The language implementation translates the method name and signature |
| back to the base method that has originally been invoked. |
| |
| </div> |
| <h5 class="listing">Example code (Base Call):</h5> |
| <div class="listing example frame"> |
| <table class="listing"> |
| <tr class="line odd"> |
| <td class="ln">1</td> |
| <td><pre><b>public</b> <b>class</b> ValidatorRole <b>playedBy</b> Po<b>int</b> {</pre></td> |
| </tr> |
| <tr class="line even"> |
| <td class="ln">2</td> |
| <td><pre> <em>callin</em> <b>void</b> checkCoordinate(<b>int</b> value) {</pre></td> |
| </tr> |
| <tr class="line odd"> |
| <td class="ln">3</td> |
| <td><pre> <b>if</b> (value < 0)</pre></td> |
| </tr> |
| <tr class="line even"> |
| <td class="ln">4</td> |
| <td><pre> <em>base</em>.checkCoordinate(-value);</pre></td> |
| </tr> |
| <tr class="line odd"> |
| <td class="ln">5</td> |
| <td><pre> else</pre></td> |
| </tr> |
| <tr class="line even"> |
| <td class="ln">6</td> |
| <td><pre> <em>base</em>.checkCoordinate(value);</pre></td> |
| </tr> |
| <tr class="line odd"> |
| <td class="ln">7</td> |
| <td><pre> }</pre></td> |
| </tr> |
| <tr class="line even"> |
| <td class="ln">8</td> |
| <td><pre> checkCoordinate <b><-</b> <b>replace</b> setX, setY;</pre></td> |
| </tr> |
| <tr class="line odd"> |
| <td class="ln">9</td> |
| <td><pre>}</pre></td> |
| </tr> |
| </table> |
| </div> |
| <div class="codecomment"> |
| <h5>Effects:</h5> |
| <ul> |
| <li>Line 2 defines a callin method which is bound to two methods |
| of the base class <code>Point</code> (see line 8). |
| </li> |
| <li>The value passed to either setX or setY is checked if it is |
| positive (line 3). |
| </li> |
| <li>Lines 4 and 6 show calls of the original method (base calls). |
| While line 6 passes the original value, in the negative case (line 4) |
| the passed value is made positive. |
| </li> |
| </ul> |
| </div> |
| </div> |
| <table class="nav"> |
| <tr> |
| <td class="back"><a href="s4.2.html" rel="prev"><< §4.2 Callin modifiers (before, after, replace)</a></td> |
| <td class="top"><a href="index.html" rel="contents">↑ Table of Contents ↑</a></td> |
| <td class="next"><a href="s4.4.html" rel="next">§4.4 Callin parameter mapping >></a></td> |
| </tr> |
| </table> |
| <div class="breadcrumb"><a class="nav" href="s4.html" rel="section">§4 Callin Binding</a></div> |
| </div> |
| <div id="footer"> |
| <hr /><a class="w3c img" href="http://jigsaw.w3.org/css-validator/check/referer" |
| shape="rect"><img src="../images/valid-css2-blue.png" alt="Valid CSS!" height="31" width="88" /></a><a class="w3c img" href="http://validator.w3.org/check?uri=referer" shape="rect"><img src="../images/valid-xhtml10-blue.png" alt="Valid XHTML 1.0 Strict" height="31" |
| width="88" /></a><address>© Stephan Herrmann, Christine Hundt, Marco Mosconi</address> |
| OT/J version 1.3 — last modified: 2010-06-08 |
| </div> |
| </body> |
| </html> |