Text not verified for kermeta 2 | |
---|---|
Kermeta provides package to structure models. So you can define packages and sub-package as deep as you want. There are two main ways to do this, as shown in examples 2 and 3 (below). If you want to define some classes in a package you may define them in a specific file and start this file with a package naming directive (followed by a semi-colon) like in the following example [2] .
Example 1 : 1 file.kmt == 1 package naming directive
// My file package MyNewPackage; class A { // ... }
class B { // ... }
Here, classes A and B are defined in a package called "MyNewPackage". All classes defined in this file are under the scope of this package.
You can also define explicitly sub-packages using braces (see the following example):
Example 2 : Defining subpackages using braces
// file : MyPackage-part1.kmt package MyPackage; package subPackage1 { class A { // ... } } package subPackage2 { class B { // ... } }
In this example, we define a main package called "MyPackage" which contains 2 sub-packages "subPackage1" and "subPackage2". The first one contains the A class and the second one the B class.
If you want, you can declare the same package in several files. You can also directly define subpackages in the package naming directive of your file (see example 1 above). In the following example, we define a new sub-package of "MyPackage" called "subPackage3" directly in the file. All features defined in this file will belong to this sub-package.
Example 3
: Defining
subpackage using
::
syntactic sugar
// file : subPackage3.kmt package MyPackage::subPackage3; class C { // ... }