Text not verified for kermeta 2 | |
---|---|
Kermeta implements a few primitive types. By primitive types, we mean types that are basic to any language, i.e integer, and that have a literal value. See below table.
Name |
Description |
Literal Example |
---|---|---|
Integer |
Represents integer numeric value like 10 or 12. (« int » data type in Java) |
101, 12, 14, -45, -123 |
String |
Represents a string of like « helloworld » (« String » data type in Java) |
"helloworld", "this is a string !!!" |
Boolean |
Represents a true/false value. (« boolean » data type in Java) |
true, false |
// Simple datatypes examples var myVar1 : Integer init 10 var myVar2 : Integer var myVar4 : String init "a new string value" var myVar5 : boolean
Kermeta also supports some other primitive types like Float and Character, but they currently don't have a surface syntax for their literals. The way to get them is to use the convertion methods available on String (for both of them) or Integer (for Float).
For example:
var c : Character init "f".elementAt(0) var r : Real init "4.5".toReal
You can define enumerations using the following syntax. Note that each enumeration literal must end with a ";".
enumeration Size { small; normal; big; huge; }
You can manipulate enumerated variables and literals with classical operators such as in the following example.
var mySize : Size if ( mySize == Size.small ) then stdio.writeln("This is small !") end
Note | |
---|---|
Enumeration is a concept of the same level as Class, they must both be defined in a package. |
In Kermeta, you can define your own datatype based on existing types without a hard dependency like inheritance.
This is done using the alias syntax.
Ex:
alias MyString : kermeta::standard::String;
In this sample, MyString has all the behavior of kermeta::standard::String but is declared locally. This means that you don't have any dependency to the framework, even to the String in the framework.
Obviously you can reuse existing type names :
alias String : kermeta::standard::String;
This will create a new type String in your package with the behavior of String in the framework.
The definition of an alias is different from the use of "using"
statement (as defined in
Section 2.14, “
using
keyword syntactic sugar
”
), when
you write
using kermeta::standard
you simply defined a syntactical shortcut allowing you to access any definition in this package from within this file.
Wheras defining an alias allows you to access this new definition from another package if needed.
Tip | |
---|---|
It is interesting to redefine your own datatype for all the standard type you use in your metamodel, so when you convert the file into ecore in order to have serialisation, you won't have any dependency to framework.ecore (which is the ecore version of the framework where Kermeta standard type) This allow a lazy coupling of the type definitions. |