Xcore how to define the value of an EnumLiterals [message #893435] |
Wed, 04 July 2012 07:37 |
René Brandstetter Messages: 17 Registered: July 2012 |
Junior Member |
|
|
Hi,
does anbody know how I can define the value of an EnumLiteral in a .xcore-File?
For example if I use ecore I was able to define the following properties on an EnumLiteral
Literal: ">"
Name: "GREATER_THAN"
Value: 2
and in xcore can only define the literal and the name like:
enum Operator
{
GREATER_THAN as ">"
LESS_THAN as "<"
...
}
In the generated java code the value of all enum literals is always 0 how can I specify this?
I already checked http://wiki.eclipse.org/Xcore#Specifying_an_Enumeration but there they didn't even explain the "as" keyword.
Btw does anybody knows hot to define the default value for attributes too for example how do I define null, "test" or what ever on an string attribute?
Regards
[Updated on: Wed, 04 July 2012 12:42] Report message to a moderator
|
|
|
|
|
|
|
Re: Xcore how to define the value of an EnumLiterals [message #893533 is a reply to message #893527] |
Wed, 04 July 2012 13:18 |
René Brandstetter Messages: 17 Registered: July 2012 |
Junior Member |
|
|
Thx for your help.
BTW if you want you can copy the following text and but it to the the "Specifing an Enumeration" section of your wiki. (It's already encoded in the eclipse wiki style)
===== Original ecore properties and their xcore counterpart =====
On the original ecore enumeration literal you can define the following properties:<br>
*Name<br>
*Literal<br>
*Value<br>
This can be defined in Xcore as<br>
''Name '''as''' "Literal" '''=''' Value''<br>
<u>Example:</u><br>
<pre>enum BookCategory
{
Mystery as "MYSTERY" = 2
ScienceFiction as "SiFi" = 1
Biography as "Bio" = 0
}
</pre>
The default value for literal and value are:<br>
*literal would be the same as the name<br>
*value would be 0<br>
===== Usage in xcore<br> =====
If you want to define a different enum default value for your attribute (e.g. ScienceFiction instead of Mystery) you can do this with an assignment of the literal.<br>
<u>Example:</u><br>
<pre>class Book
{
String title
int pages
BookCategory bookCategory = "SiFi"
container Library library opposite books
referes Writer[] authors opposite books
}
</pre>
It's not possible to define null as the default value for an enum because EMF treats enums as primitve datatypes and those can't be null. But you can make the attribute "unsettable" and this will generate an isSet...() and an unset...() method for your enum. Those to methods can be used to distinguish between just having a default value and being explicitly set to a value that happens to be the default value. If you absolutly need null values, you need to create a wrapper EDataType and use EDataType in place of the Enum.<br>
<u>Example for unsettable:</u>
<pre>class Book
{
String title
int pages
unsettable BookCategory bookCategory
container Library library opposite books
referes Writer[] authors opposite books
}</pre>
<br>
<u>Example for EDataType wrapping:</u>
<pre>@ExtendedMetaData(baseType="BookCategory")
type BookCategoryObject wraps Enumerator
class Book
{
String title
int pages
BookCategoryObject bookCategory
container Library library opposite books
referes Writer[] authors opposite books
}</pre>
<br>
[Updated on: Wed, 04 July 2012 13:18] Report message to a moderator
|
|
|
Powered by
FUDForum. Page generated in 0.02996 seconds