Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Default value of attribute with type enum
Default value of attribute with type enum [message #534411] Wed, 19 May 2010 05:24 Go to next message
Rimvydas is currently offline RimvydasFriend
Messages: 47
Registered: July 2009
Member
I have EMF model with a class that has attribute of type EEnum.
Default value is not specified (should be null). When I invoke get
(without setting it before ) I receive enumeration literal that is the
first in the EEnum. Multiplicity of the attribute is [0..1] so I think,
that get value should return null.

Maybe somebody can comment why it is implemented in this way?

Regards,

Rimvydas
Re: Default value of attribute with type enum [message #534457 is a reply to message #534411] Wed, 19 May 2010 09:19 Go to previous messageGo to next message
Jonas Helming is currently offline Jonas HelmingFriend
Messages: 699
Registered: July 2009
Senior Member
Hi,
IMHO returning null is the worse option. Even Boris admited that the
null returns in SWT were the "biggest mistake" ;-), see also
http://www.eclipsecon.org/2010/sessions/sessions?id=1427
I would rather model the "null" value explicit, e.g. as "not set". If
you really need "null" you can probably even model null explicitly in
the Enum (not tested).
To avoid surprises, it would be good to enforce a default value at any
enumeration...
Cheers
Jonas


Rimvydas Vaidelis wrote:
> I have EMF model with a class that has attribute of type EEnum.
> Default value is not specified (should be null). When I invoke get
> (without setting it before ) I receive enumeration literal that is the
> first in the EEnum. Multiplicity of the attribute is [0..1] so I think,
> that get value should return null.
>
> Maybe somebody can comment why it is implemented in this way?
>
> Regards,
>
> Rimvydas
Re: Default value of attribute with type enum [message #534458 is a reply to message #534457] Wed, 19 May 2010 09:21 Go to previous messageGo to next message
Jonas Helming is currently offline Jonas HelmingFriend
Messages: 699
Registered: July 2009
Senior Member
Addition: The default value is automatically set on the first literal
you set. So my last suggestion is already implemented by EMF...


Jonas wrote:
> Hi,
> IMHO returning null is the worse option. Even Boris admited that the
> null returns in SWT were the "biggest mistake" ;-), see also
> http://www.eclipsecon.org/2010/sessions/sessions?id=1427
> I would rather model the "null" value explicit, e.g. as "not set". If
> you really need "null" you can probably even model null explicitly in
> the Enum (not tested).
> To avoid surprises, it would be good to enforce a default value at any
> enumeration...
> Cheers
> Jonas
>
>
> Rimvydas Vaidelis wrote:
>> I have EMF model with a class that has attribute of type EEnum.
>> Default value is not specified (should be null). When I invoke get
>> (without setting it before ) I receive enumeration literal that is the
>> first in the EEnum. Multiplicity of the attribute is [0..1] so I think,
>> that get value should return null.
>>
>> Maybe somebody can comment why it is implemented in this way?
>>
>> Regards,
>>
>> Rimvydas
Re: Default value of attribute with type enum [message #534459 is a reply to message #534458] Wed, 19 May 2010 09:26 Go to previous messageGo to next message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
FYI, there has been some (detailed) discussion on this topic earlier:
http://www.eclipse.org/forums/index.php?t=tree&th=161533 &#page_top

gr. Martin

Jonas wrote:
> Addition: The default value is automatically set on the first literal
> you set. So my last suggestion is already implemented by EMF...
>
>
> Jonas wrote:
>> Hi,
>> IMHO returning null is the worse option. Even Boris admited that the
>> null returns in SWT were the "biggest mistake" ;-), see also
>> http://www.eclipsecon.org/2010/sessions/sessions?id=1427
>> I would rather model the "null" value explicit, e.g. as "not set". If
>> you really need "null" you can probably even model null explicitly in
>> the Enum (not tested).
>> To avoid surprises, it would be good to enforce a default value at any
>> enumeration...
>> Cheers
>> Jonas
>>
>>
>> Rimvydas Vaidelis wrote:
>>> I have EMF model with a class that has attribute of type EEnum.
>>> Default value is not specified (should be null). When I invoke get
>>> (without setting it before ) I receive enumeration literal that is
>>> the first in the EEnum. Multiplicity of the attribute is [0..1] so I
>>> think,
>>> that get value should return null.
>>>
>>> Maybe somebody can comment why it is implemented in this way?
>>>
>>> Regards,
>>>
>>> Rimvydas


--

With Regards, Martin Taal

Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
Cell: +31 (0)6 288 48 943
Tel: +31 (0)84 420 2397
Fax: +31 (0)84 225 9307
Mail: mtaal@springsite.com - mtaal@elver.org
Web: www.springsite.com - www.elver.org
Re: Default value of attribute with type enum [message #534473 is a reply to message #534459] Wed, 19 May 2010 09:53 Go to previous messageGo to next message
Eike Stepper is currently offline Eike StepperFriend
Messages: 6682
Registered: July 2009
Senior Member
Hi Martin,

I noticed CDO in the thread you mentioned. Could that be related to
https://bugs.eclipse.org/bugs/show_bug.cgi?id=306998 ?

Cheers
/Eike

----
http://thegordian.blogspot.com
http://twitter.com/eikestepper



Am 19.05.2010 11:26, schrieb Martin Taal:
> FYI, there has been some (detailed) discussion on this topic earlier:
> http://www.eclipse.org/forums/index.php?t=tree&th=161533 &#page_top
>
> gr. Martin
>
> Jonas wrote:
>> Addition: The default value is automatically set on the first literal
>> you set. So my last suggestion is already implemented by EMF...
>>
>>
>> Jonas wrote:
>>> Hi,
>>> IMHO returning null is the worse option. Even Boris admited that the
>>> null returns in SWT were the "biggest mistake" ;-), see also
>>> http://www.eclipsecon.org/2010/sessions/sessions?id=1427
>>> I would rather model the "null" value explicit, e.g. as "not set".
>>> If you really need "null" you can probably even model null
>>> explicitly in the Enum (not tested).
>>> To avoid surprises, it would be good to enforce a default value at
>>> any enumeration...
>>> Cheers
>>> Jonas
>>>
>>>
>>> Rimvydas Vaidelis wrote:
>>>> I have EMF model with a class that has attribute of type EEnum.
>>>> Default value is not specified (should be null). When I invoke get
>>>> (without setting it before ) I receive enumeration literal that is
>>>> the first in the EEnum. Multiplicity of the attribute is [0..1] so
>>>> I think,
>>>> that get value should return null.
>>>>
>>>> Maybe somebody can comment why it is implemented in this way?
>>>>
>>>> Regards,
>>>>
>>>> Rimvydas
>
>


Re: Default value of attribute with type enum [message #534475 is a reply to message #534473] Wed, 19 May 2010 10:07 Go to previous messageGo to next message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
It seems related but the topic of the bugzilla is more related to invalid default values (whereby the thread discusses
the whole default value philosophy of EMF in general).

I seem to remember that sometimes EMF generates an EnumObject datatype (for nullable types) for an enum type but I am
not sure when this happens or that I remember this correctly...

gr. Martin

Eike Stepper wrote:
> Hi Martin,
>
> I noticed CDO in the thread you mentioned. Could that be related to
> https://bugs.eclipse.org/bugs/show_bug.cgi?id=306998 ?
>
> Cheers
> /Eike
>
> ----
> http://thegordian.blogspot.com
> http://twitter.com/eikestepper
>
>
>
> Am 19.05.2010 11:26, schrieb Martin Taal:
>> FYI, there has been some (detailed) discussion on this topic earlier:
>> http://www.eclipse.org/forums/index.php?t=tree&th=161533 &#page_top
>>
>> gr. Martin
>>
>> Jonas wrote:
>>> Addition: The default value is automatically set on the first literal
>>> you set. So my last suggestion is already implemented by EMF...
>>>
>>>
>>> Jonas wrote:
>>>> Hi,
>>>> IMHO returning null is the worse option. Even Boris admited that the
>>>> null returns in SWT were the "biggest mistake" ;-), see also
>>>> http://www.eclipsecon.org/2010/sessions/sessions?id=1427
>>>> I would rather model the "null" value explicit, e.g. as "not set".
>>>> If you really need "null" you can probably even model null
>>>> explicitly in the Enum (not tested).
>>>> To avoid surprises, it would be good to enforce a default value at
>>>> any enumeration...
>>>> Cheers
>>>> Jonas
>>>>
>>>>
>>>> Rimvydas Vaidelis wrote:
>>>>> I have EMF model with a class that has attribute of type EEnum.
>>>>> Default value is not specified (should be null). When I invoke get
>>>>> (without setting it before ) I receive enumeration literal that is
>>>>> the first in the EEnum. Multiplicity of the attribute is [0..1] so
>>>>> I think,
>>>>> that get value should return null.
>>>>>
>>>>> Maybe somebody can comment why it is implemented in this way?
>>>>>
>>>>> Regards,
>>>>>
>>>>> Rimvydas
>>
>>


--

With Regards, Martin Taal

Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
Cell: +31 (0)6 288 48 943
Tel: +31 (0)84 420 2397
Fax: +31 (0)84 225 9307
Mail: mtaal@springsite.com - mtaal@elver.org
Web: www.springsite.com - www.elver.org
Re: Default value of attribute with type enum [message #534484 is a reply to message #534475] Wed, 19 May 2010 10:21 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33137
Registered: July 2009
Senior Member
Guys,

EMF treats EEnums just like primitives, i.e., like int where the first
enum is like 0. It's certainly possible to create an EDataType whose
instance type name is the generated enum; features of that type can be
null. We automatically produce such an EDataType when generating a
model from XML Schema to support nillable elements.


Martin Taal wrote:
> It seems related but the topic of the bugzilla is more related to
> invalid default values (whereby the thread discusses the whole default
> value philosophy of EMF in general).
>
> I seem to remember that sometimes EMF generates an EnumObject datatype
> (for nullable types) for an enum type but I am not sure when this
> happens or that I remember this correctly...
>
> gr. Martin
>
> Eike Stepper wrote:
>> Hi Martin,
>>
>> I noticed CDO in the thread you mentioned. Could that be related to
>> https://bugs.eclipse.org/bugs/show_bug.cgi?id=306998 ?
>>
>> Cheers
>> /Eike
>>
>> ----
>> http://thegordian.blogspot.com
>> http://twitter.com/eikestepper
>>
>>
>>
>> Am 19.05.2010 11:26, schrieb Martin Taal:
>>> FYI, there has been some (detailed) discussion on this topic earlier:
>>> http://www.eclipse.org/forums/index.php?t=tree&th=161533 &#page_top
>>>
>>> gr. Martin
>>>
>>> Jonas wrote:
>>>> Addition: The default value is automatically set on the first
>>>> literal you set. So my last suggestion is already implemented by
>>>> EMF...
>>>>
>>>>
>>>> Jonas wrote:
>>>>> Hi,
>>>>> IMHO returning null is the worse option. Even Boris admited that
>>>>> the null returns in SWT were the "biggest mistake" ;-), see also
>>>>> http://www.eclipsecon.org/2010/sessions/sessions?id=1427
>>>>> I would rather model the "null" value explicit, e.g. as "not set".
>>>>> If you really need "null" you can probably even model null
>>>>> explicitly in the Enum (not tested).
>>>>> To avoid surprises, it would be good to enforce a default value at
>>>>> any enumeration...
>>>>> Cheers
>>>>> Jonas
>>>>>
>>>>>
>>>>> Rimvydas Vaidelis wrote:
>>>>>> I have EMF model with a class that has attribute of type EEnum.
>>>>>> Default value is not specified (should be null). When I invoke
>>>>>> get (without setting it before ) I receive enumeration literal
>>>>>> that is the first in the EEnum. Multiplicity of the attribute is
>>>>>> [0..1] so I think,
>>>>>> that get value should return null.
>>>>>>
>>>>>> Maybe somebody can comment why it is implemented in this way?
>>>>>>
>>>>>> Regards,
>>>>>>
>>>>>> Rimvydas
>>>
>>>
>
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:[DataBinding] ComputedList refresh
Next Topic:Problem Creating Resource
Goto Forum:
  


Current Time: Fri Apr 19 11:15:41 GMT 2024

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

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

Back to the top