blob: 9858a122392a125a0d669716825fa370c1b9b115 [file] [log] [blame]
<!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="s1.2.4.html" rel="prev">&lt;&lt;&nbsp;&sect;1.2.4&nbsp;Type tests and casts</a></td>
<td class="top"><a href="index.html" rel="contents">&uarr;&nbsp;Table of Contents&nbsp;&uarr;</a></td>
<td class="next"></td>
</tr>
</table>
<div class="breadcrumb"><a class="nav" href="s1.html" rel="section">&sect;1&nbsp;Teams and Roles</a>&nbsp;&gt;&nbsp;<a class="nav" href="s1.2.html" rel="section">&sect;1.2&nbsp;Role classes and objects</a></div>
<div class="sect depth3" id="s1.2.5">
<h3 class="sect">&sect;1.2.5&nbsp;File structure<a class="img" href="s1.2.5.html"
title="PermaLink to &sect;1.2.5&nbsp;File structure"><img style="vertical-align:text-top;margin-left:5px;" src="../images/permalink.png"
alt="" /></a></h3>
<p>Just like regular inner classes, role classes may be inlined in the
source code of the enclosing team. As an alternative style it is possible
to store role classes in separate <strong>role files</strong> according to the following rules:
</p>
<div class="subsect depth4" id="s1.2.5.a">
<h4 class="subsect">(a)&nbsp;<span class="title">Role directory</span><a class="img" href="s1.2.5.a.html" title="PermaLink to (a)&nbsp;Role directory"><img style="vertical-align:text-top;margin-left:5px;" src="../images/permalink.png"
alt="" /></a></h4>
<p>In the directory of the team class a new directory is created
which has the same name as the team without the <tt>.java</tt> suffix.
</p>
</div>
<div class="subsect depth4" id="s1.2.5.b">
<h4 class="subsect">(b)&nbsp;<span class="title">Role files</span><a class="img" href="s1.2.5.b.html" title="PermaLink to (b)&nbsp;Role files"><img style="vertical-align:text-top;margin-left:5px;" src="../images/permalink.png"
alt="" /></a></h4>
<p>Role classes are stored in this directory (a). The file names are
derived from the role class name extended by <tt>.java</tt>.<br />
A role file must contain exactly one top-level type.
</p>
</div>
<div class="subsect depth4" id="s1.2.5.c">
<h4 class="subsect">(c)&nbsp;<span class="title">package statement</span><a class="img" href="s1.2.5.c.html"
title="PermaLink to (c)&nbsp;package statement"><img style="vertical-align:text-top;margin-left:5px;" src="../images/permalink.png"
alt="" /></a></h4>
<p>A role class in a role file declares as its package the fully qualified
name of the enclosing team class. The package statement of a role file
must use the <code>team</code> modifier as its first token.
</p>
</div>
<div class="subsect depth4" id="s1.2.5.d">
<h4 class="subsect">(d)&nbsp;<span class="title">Reference to role file</span><a class="img" href="s1.2.5.d.html"
title="PermaLink to (d)&nbsp;Reference to role file"><img style="vertical-align:text-top;margin-left:5px;" src="../images/permalink.png"
alt="" /></a></h4>
<p>A team should mention in its javadoc comment each role class which
is stored externally using a <tt>@role</tt> tag.
</p>
</div>
<div class="subsect depth4" id="s1.2.5.e">
<h4 class="subsect">(e)&nbsp;<span class="title">Legal types in role files</span><a class="img" href="s1.2.5.e.html"
title="PermaLink to (e)&nbsp;Legal types in role files"><img style="vertical-align:text-top;margin-left:5px;" src="../images/permalink.png"
alt="" /></a></h4>
<p>The type in a role file must not be an <code>enum</code>.
</p>
</div>
<div class="subsect depth4" id="s1.2.5.f">
<h4 class="subsect">(f)&nbsp;<span class="title">Imports in role files</span><a class="img" href="s1.2.5.f.html"
title="PermaLink to (f)&nbsp;Imports in role files"><img style="vertical-align:text-top;margin-left:5px;" src="../images/permalink.png"
alt="" /></a></h4>
<p>A role file may have imports of its own.
Within the role definition these imports are visible <em>in addition</em> to all imports of the enclosing team.
Only <code>base</code> imports (see <a href="s2.1.2.d.html" title="&sect;2.1.2.(d)&nbsp;Base imports" class="sect">&sect;2.1.2.(d)</a>)
<em>must</em> be defined in the team.
</p>
</div>
<p>Semantically, there is no difference between inlined role classes and those
stored in separate role files.
</p>
<div class="note">
<h5>Note:</h5>
Current Java compilers disallow a type to have the same fully qualified
name as a package. However, the JLS does not seem to make a statement in this respect.
In OT/J, a package and a type are interpreted as being the same team, if both have the
same fully qualified name and both have the <code>team</code> modifier.
</div>
<h5 class="listing">Role file example:</h5>
<div class="listing example frame" id="l1.2.5-1">
<table class="listing">
<tr class="lhead">
<td colspan="2">in file <code>org/objectteams/examples/MyTeamA.java</code> :
</td>
</tr>
<tr class="line odd">
<td class="ln">1</td>
<td><pre><b>package</b> org.objectteams.examples;</pre></td>
</tr>
<tr class="line even">
<td class="ln">2</td>
<td><pre><span class="comment">/**</span></pre></td>
</tr>
<tr class="line odd">
<td class="ln">3</td>
<td><pre> <span class="comment">* @author Stephan Herrmann</span></pre></td>
</tr>
<tr class="line even">
<td class="ln">4</td>
<td><pre> <span class="comment">* @date 20.02.2007</span></pre></td>
</tr>
<tr class="line odd">
<td class="ln">5</td>
<td><pre> <span class="comment">* @file MyTeamA.java</span></pre></td>
</tr>
<tr class="line even">
<td class="ln">6</td>
<td><pre> <span class="comment">* <em>@role MyRole</em></span></pre></td>
</tr>
<tr class="line odd">
<td class="ln">7</td>
<td><pre> <span class="comment">*/</span></pre></td>
</tr>
<tr class="line even">
<td class="ln">8</td>
<td><pre><b>public</b> <b>team</b> <b>class</b> MyTeamA {</pre></td>
</tr>
<tr class="line odd">
<td class="ln">9</td>
<td><pre> ...</pre></td>
</tr>
<tr class="line even">
<td class="ln">10</td>
<td><pre>}</pre></td>
</tr>
</table>
</div>
<div class="listing example frame" id="l1.2.5-2">
<table class="listing">
<tr class="lhead">
<td colspan="2">in file <code>org/objectteams/examples<strong class="blue">/MyTeamA/MyRole.java</strong></code>:
</td>
</tr>
<tr class="line odd">
<td class="ln">1</td>
<td><pre><em><b>team</b> <b>package</b> org.objectteams.examples.MyTeamA;</em></pre></td>
</tr>
<tr class="line even">
<td class="ln">2</td>
<td><pre><b>public</b> <b>class</b> MyRole {</pre></td>
</tr>
<tr class="line odd">
<td class="ln">3</td>
<td><pre> ...</pre></td>
</tr>
<tr class="line even">
<td class="ln">4</td>
<td><pre>}</pre></td>
</tr>
</table>
</div>
</div>
<table class="nav">
<tr>
<td class="back"><a href="s1.2.4.html" rel="prev">&lt;&lt;&nbsp;&sect;1.2.4&nbsp;Type tests and casts</a></td>
<td class="top"><a href="index.html" rel="contents">&uarr;&nbsp;Table of Contents&nbsp;&uarr;</a></td>
<td class="next"></td>
</tr>
</table>
<div class="breadcrumb"><a class="nav" href="s1.html" rel="section">&sect;1&nbsp;Teams and Roles</a>&nbsp;&gt;&nbsp;<a class="nav" href="s1.2.html" rel="section">&sect;1.2&nbsp;Role classes and objects</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>&copy; Stephan Herrmann, Christine Hundt, Marco Mosconi</address>
OT/J version 1.3 &mdash; last modified: 2011-05-15
</div>
</body>
</html>