2.14.  using keyword syntactic sugar

[Note] Changed in Kermeta 2

While coding in Kermeta you regularly need to refer to class definitions. For example to indicate the type of a paramzeter or a variable or to initialize an instance of it (ie. call new).

If the definition you want to use isn't defined in the package where you need to use it, the normal way to acces it is to use the full qualified name.

Example 2.1. use of full qualified name

...
var s : kermeta::standard::Integer
var e : kermeta::exceptions::NotImplementedException init kermeta::exceptions::NotImplementedException.new
...

Like the import statement in Java, Kermeta allows to defines shorcuts which allow you to specify classes from other packages that can be referenced without qualifying them with their full qualified name. The keyword used for that is using . It supports various syntax option in order to haheve either a fine or coarse grain resolution.

Example 2.2. shorthand giving access to the full content of a package

using kermeta::standard::*	
		// direct access to all definitions in Package kermeta::standard
using kermeta::exceptions::*
		// direct access to all definitions in Package kermeta::exceptions 
...
// allows to write :
var s : Integer
var e : NotImplementedException init NotImplementedException.new

[Note]Note

For support of retro compatibilty with kermeta 1, the 2 following syntaxes have the same effect. However the second one raises a deprecation warning inviting you to use the first syntax.

using kermeta::standard::*	// direct access to all definition of Package
using kermeta::standard		// retro compatibility supported, exactly the same as above   
                            // (should raise a deprecation warning)

Example 2.3. shorthand giving access to a single definition with renaming

using kermeta::standard::Integer => MyInteger   // renaming
using kermeta::exceptions::NotImplementedException => NIException   // renaming
...
// allows to write :
var s : MyInteger
var e : NIException init NIException.new

Example 2.4. shorthand giving access to a single definition with direct renaming

using kermeta::standard::{Integer}
			// same as using kermeta::standard::Integer => Integer
using kermeta::exceptions::{NotImplementedException}
			// same as kermeta::exceptions::NotImplementedException => NotImplementedException
...
// allows to write :
var s : Integer
var e : NotImplementedException init NotImplementedException.new

Example 2.5. Other examples of renaming and shortcuts

using kermeta::standard::Integer => standard::Integer     // with renaming for direct access
using kermeta::{standard::Integer}              // shortcut : same as above
using kermeta::standard::Integer => ks::Integer // another renaming

using kermeta::exceptions::* => ke::*             // global renaming of a package
...
// allows to write :
var i1 : standard::Integer
var i2 : ks::Integer		
// note that i1 and i2 are actually of the same type kermeta::standard::Integer

var e : ke::NotImplementedException init ke::NotImplementedException.new

[Note]Note

The using statement is just a syntactic sugar used by the type resolver when building the Kermeta model of the program. This is different from the definition of a local datatype with an alias . (See Local datatype using "alias" subsection )

Be careful when declaring your using statements if there is a risk of conflicting names. In such situation, the type resolver will first look into the current package, then try each using in the order they are defined and choose the first type definition that exists.