Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » [Xcore] Default value for multi-valued enum attributes
[Xcore] Default value for multi-valued enum attributes [message #1777880] Tue, 05 December 2017 15:07 Go to next message
Axel Guckelsberger is currently offline Axel GuckelsbergerFriend
Messages: 354
Registered: July 2009
Senior Member
Hi all,

does anybody know how to specify the default value(s) for an enum attribute which stores a list of enum values?

It seems that I can just add square brackets to make an attribute multi-valued.

MyEnumType[] foo


But I can't find the syntax to configure the default values correctly.

First I thought about something like:

MyEnumType[] foo = #['ONE', 'TWO', 'THREE']


like it is known from Xtend.

Also

MyEnumType[] foo = new EList('ONE', 'TWO', 'THREE')


does not work.

Any idea how it is done properly?
Re: [Xcore] Default value for multi-valued enum attributes [message #1777911 is a reply to message #1777880] Wed, 06 December 2017 06:37 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
Registered: July 2009
Senior Member
You can specify the value using DataType foo = 'default-literal-value' but note that while you can specify a default value literal for an attribute in general, the generated code will not actually use it for multi-valued attributes. I can explain all the various reasons why it's not supported, but in the end, it's not, it won't be, and even if you hand modified the generated code, it would not play nice with the rest of the frameworks.

Ed Merks
Professional Support: https://www.macromodeling.com/
Re: [Xcore] Default value for multi-valued enum attributes [message #1777915 is a reply to message #1777911] Wed, 06 December 2017 07:04 Go to previous messageGo to next message
Axel Guckelsberger is currently offline Axel GuckelsbergerFriend
Messages: 354
Registered: July 2009
Senior Member
Hi Ed,

so it would be better to use either a single-valued enumeration with all combinations (like ONE_TWO, ONE_THREE, ..., ONE_TWO_THREE) or several EBoolean attributes (useOne, useTwo) instead?
Re: [Xcore] Default value for multi-valued enum attributes [message #1777922 is a reply to message #1777915] Wed, 06 December 2017 08:23 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
Registered: July 2009
Senior Member
If you want defaults, yes. Alternatively you could do something like this:
package org.example.list

import java.util.List

class Example
{
	ValueList values = 'VALUE1 VALUE2'
}

enum Value
{
	VALUE1
	VALUE2
}

@ExtendedMetaData(itemType='Value')
type ValueList wraps List
I.e., define an data type that's a list of enum values and then use that to define a single-value attribute with a default. Unfortunately this Xcore file has a warning about the use of the raw List type. And of course you should not modify the result of getValues() but rather call setValues with a new list to modify the value. You could also define a data type for List<Value> but in that case you have to implement the create/convert methods for that data type.


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:Platform:/plugin uri could not be resolved
Next Topic:[CDO] Optimistic Concurrency Control - Reg.
Goto Forum:
  


Current Time: Thu Apr 25 09:37:57 GMT 2024

Powered by FUDForum. Page generated in 0.03384 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top