|
|
Re: Default Value of an Unsettable Enum Attribute [message #1393680 is a reply to message #1393090] |
Fri, 04 July 2014 05:36 |
Ed Merks Messages: 33218 Registered: July 2009 |
Senior Member |
|
|
Ed,
Note that enums are treated like primitives. E.g., if the type were
int, it can't be null. So it is reasonable to have an unsettable
primitive (which can't be null) and has a lower bound of 1 (it must be
explicitly set).
On 03/07/2014 10:18 AM, Ed Willink wrote:
> Hi
>
> What you ask seems contradictory.
>
> If it is unset it has no value.
>
> The 'unset' value is 'null', without quotes.
>
> An unsettable value must be able to be null so its multiplicity lower
> bound must be 0.
>
> HTH. Without a repro that's the best I can do.
>
> Regards
>
> Ed Willink
>
> On 03/07/2014 02:29, Sascha Holl wrote:
>> I want to use OCL in EMF to validate my models. As decsribed in the
>> title: I have an enumeration type (call it EnumType) and an attribute
>> attribute attrib : EnumType { unsettable };
>>
>> I don't want that attrib is initialized with the default literal of
>> EnumType, but set to an "unset" state.
>>
>> I've tried to use the syntax which works for integral types, i.e.
>> "attrib : EnumTpye = 'null'", but I don't know the correct keyword
>> ('null' doesn't work).
>>
>> I've also noticed that there is another keyword called "initial"
>> which might help in this case, but I can't find any documentation
>> about it.
>>
>> I really hope someone could help me to solve this problem.
>
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
Re: Default Value of an Unsettable Enum Attribute [message #1393775 is a reply to message #1393680] |
Fri, 04 July 2014 08:48 |
Ed Willink Messages: 7670 Registered: July 2009 |
Senior Member |
|
|
Hi
> The 'unset' value is 'null', without quotes.
Except that I forgot that the OCLinEcore syntax for a direct Ecore
initializer uses quotes.
> If it is unset it has no value.
After trying all the permutations I can think of, I can see a discepancy
between the UML/OCL, Java and Ecore view of enumerations.
In UML/OCL, an N-valued enumeration with [1..1] multiplicity has N
states (ignoring the not-well-formed 'invalid' state).
In UML/OCL, an N-valued enumeration with [0..1] multiplicity has N+1
states; the extra one is 'null'.
In Ecore, an N-valued enumeration with [0..1] or [1..1] multiplicity and
unsettable=false has N states
In Ecore, an N-valued enumeration with [0..1] or [1..1] multiplicity and
unsettable=true has N+1 states with the additional state in an extra boolean
Ecore gives a validation error if you try to use null as the
defaultValueLiteral, which is unhelpful given that the generated Java
code would be quite happy with a null initializer, and EMF has yet to
adopt @NonNull annotations to stabilize the API.
----
Today your only choice is to expand your enumeration with an explicit
NULL/UNSET value.
----
https://bugs.eclipse.org/bugs/show_bug.cgi?id=438906 raised to add
support for Nullable enums.
Regards
Ed Willink
On 04/07/2014 06:36, Ed Merks wrote:
> Ed,
>
> Note that enums are treated like primitives. E.g., if the type were
> int, it can't be null. So it is reasonable to have an unsettable
> primitive (which can't be null) and has a lower bound of 1 (it must be
> explicitly set).
>
>
> On 03/07/2014 10:18 AM, Ed Willink wrote:
>> Hi
>>
>> What you ask seems contradictory.
>>
>> If it is unset it has no value.
>>
>> The 'unset' value is 'null', without quotes.
>>
>> An unsettable value must be able to be null so its multiplicity lower
>> bound must be 0.
>>
>> HTH. Without a repro that's the best I can do.
>>
>> Regards
>>
>> Ed Willink
>>
>> On 03/07/2014 02:29, Sascha Holl wrote:
>>> I want to use OCL in EMF to validate my models. As decsribed in the
>>> title: I have an enumeration type (call it EnumType) and an attribute
>>> attribute attrib : EnumType { unsettable };
>>>
>>> I don't want that attrib is initialized with the default literal of
>>> EnumType, but set to an "unset" state.
>>>
>>> I've tried to use the syntax which works for integral types, i.e.
>>> "attrib : EnumTpye = 'null'", but I don't know the correct keyword
>>> ('null' doesn't work).
>>>
>>> I've also noticed that there is another keyword called "initial"
>>> which might help in this case, but I can't find any documentation
>>> about it.
>>>
>>> I really hope someone could help me to solve this problem.
>>
>
|
|
|
Powered by
FUDForum. Page generated in 0.04878 seconds