§1.2.5 File structure

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 role files according to the following rules:

(a) Role directory

In the directory of the team class a new directory is created which has the same name as the team without the .java suffix.

(b) Role files

Role classes are stored in this directory (a). The file names are derived from the role class name extended by .java.
A role file must contain exactly one top-level type.

(c) package statement

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 team modifier as its first token.

(d) Reference to role file

A team should mention in its javadoc comment each role class which is stored externally using a @role tag.

(e) Legal types in role files

The type in a role file must not be an enum.

(f) Imports in role files

A role file may have imports of its own. Within the role definition these imports are visible in addition to all imports of the enclosing team. Only base imports (see §2.1.2.(d)) must be defined in the team.

Semantically, there is no difference between inlined role classes and those stored in separate role files.

Note:
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 team modifier.
Role file example:
in file org/objectteams/examples/MyTeamA.java :
1
package org.objectteams.examples;
2
/**
3
 * @author Stephan Herrmann
4
 * @date 20.02.2007
5
 * @file MyTeamA.java
6
 * @role MyRole
7
 */
8
public team class MyTeamA {
9
  ...
10
}
in file org/objectteams/examples/MyTeamA/MyRole.java:
1
team package org.objectteams.examples.MyTeamA;
2
public class MyRole {
3
  ...
4
}