Skip to main content



      Home
Home » Modeling » EMF "Technology" (Ecore Tools, EMFatic, etc)  » How to declare type of empty collection in OCL?
How to declare type of empty collection in OCL? [message #61231] Tue, 14 November 2006 05:25 Go to next message
Eclipse UserFriend
How can I declare that for example a Set contains objects of some type
and then initialize it to be empty. Neither I or II below works, but III
does.

(I) Not OK
let a:Set(Integer)=Set{} in a

'Init expression type does not conform to type of variable (a).'

(II) Not OK
let a:Set(Integer)=Set(Integer){} in a

'1:20:1:31 "collectionTypeIdentifierCS" expected instead of "Set(Integer)"'

(III) OK
let a:Set(Integer)=Set{1,3,2} in a

2
1
3

Regards
Tord
Re: How to declare type of empty collection in OCL? [message #61256 is a reply to message #61231] Tue, 14 November 2006 06:21 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: merks.ca.ibm.com

Tord,

I'll forward your question to the new OCL newsgroup.


Tord Alenljung wrote:
> How can I declare that for example a Set contains objects of some type
> and then initialize it to be empty. Neither I or II below works, but
> III does.
>
> (I) Not OK
> let a:Set(Integer)=Set{} in a
>
> 'Init expression type does not conform to type of variable (a).'
>
> (II) Not OK
> let a:Set(Integer)=Set(Integer){} in a
>
> '1:20:1:31 "collectionTypeIdentifierCS" expected instead of
> "Set(Integer)"'
>
> (III) OK
> let a:Set(Integer)=Set{1,3,2} in a
>
> 2
> 1
> 3
>
> Regards
> Tord
Re: How to declare type of empty collection in OCL? [message #61376 is a reply to message #61256] Tue, 14 November 2006 09:12 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: cdamus.ca.ibm.com

Hi, Tord,

The element type of a collection literal is inferred from its contents (as
the common supertype of its elements, which may be OclAny or
Collection(OclAny) in mixed cases). The inferred element type of an empty
collection literal is OclVoid, which conforms to all other types, so your
expression (I) should work.

This is a bug. Would you mind raising it? (on the MDT UML2 OCL component):

https://bugs.eclipse.org/bugs/enter_bug.cgi?product=MDT& version=1.0.1&component=UML2%20OCL&bug_severity=norm al&form_name=enter_bug

Thanks,

Christian


Ed Merks wrote:

> Tord,
>
> I'll forward your question to the new OCL newsgroup.
>
>
> Tord Alenljung wrote:
>> How can I declare that for example a Set contains objects of some type
>> and then initialize it to be empty. Neither I or II below works, but
>> III does.
>>
>> (I) Not OK
>> let a:Set(Integer)=Set{} in a
>>
>> 'Init expression type does not conform to type of variable (a).'
>>
>> (II) Not OK
>> let a:Set(Integer)=Set(Integer){} in a
>>
>> '1:20:1:31 "collectionTypeIdentifierCS" expected instead of
>> "Set(Integer)"'
>>
>> (III) OK
>> let a:Set(Integer)=Set{1,3,2} in a
>>
>> 2
>> 1
>> 3
>>
>> Regards
>> Tord
Re: How to declare type of empty collection in OCL? [message #61449 is a reply to message #61376] Wed, 15 November 2006 07:11 Go to previous message
Eclipse UserFriend
Bug report at https://bugs.eclipse.org/bugs/show_bug.cgi?id=164614

Thanks
Tord

Christian W. Damus wrote:
> Hi, Tord,
>
> The element type of a collection literal is inferred from its contents (as
> the common supertype of its elements, which may be OclAny or
> Collection(OclAny) in mixed cases). The inferred element type of an empty
> collection literal is OclVoid, which conforms to all other types, so your
> expression (I) should work.
>
> This is a bug. Would you mind raising it? (on the MDT UML2 OCL component):
>
> https://bugs.eclipse.org/bugs/enter_bug.cgi?product=MDT& version=1.0.1&component=UML2%20OCL&bug_severity=norm al&form_name=enter_bug
>
> Thanks,
>
> Christian
>
>
> Ed Merks wrote:
>
>> Tord,
>>
>> I'll forward your question to the new OCL newsgroup.
>>
>>
>> Tord Alenljung wrote:
>>> How can I declare that for example a Set contains objects of some type
>>> and then initialize it to be empty. Neither I or II below works, but
>>> III does.
>>>
>>> (I) Not OK
>>> let a:Set(Integer)=Set{} in a
>>>
>>> 'Init expression type does not conform to type of variable (a).'
>>>
>>> (II) Not OK
>>> let a:Set(Integer)=Set(Integer){} in a
>>>
>>> '1:20:1:31 "collectionTypeIdentifierCS" expected instead of
>>> "Set(Integer)"'
>>>
>>> (III) OK
>>> let a:Set(Integer)=Set{1,3,2} in a
>>>
>>> 2
>>> 1
>>> 3
>>>
>>> Regards
>>> Tord
>
Re: How to declare type of empty collection in OCL? [message #595597 is a reply to message #61231] Tue, 14 November 2006 06:21 Go to previous message
Eclipse UserFriend
Tord,

I'll forward your question to the new OCL newsgroup.


Tord Alenljung wrote:
> How can I declare that for example a Set contains objects of some type
> and then initialize it to be empty. Neither I or II below works, but
> III does.
>
> (I) Not OK
> let a:Set(Integer)=Set{} in a
>
> 'Init expression type does not conform to type of variable (a).'
>
> (II) Not OK
> let a:Set(Integer)=Set(Integer){} in a
>
> '1:20:1:31 "collectionTypeIdentifierCS" expected instead of
> "Set(Integer)"'
>
> (III) OK
> let a:Set(Integer)=Set{1,3,2} in a
>
> 2
> 1
> 3
>
> Regards
> Tord
Re: How to declare type of empty collection in OCL? [message #595643 is a reply to message #61256] Tue, 14 November 2006 09:12 Go to previous message
Eclipse UserFriend
Originally posted by: cdamus.ca.ibm.com

Hi, Tord,

The element type of a collection literal is inferred from its contents (as
the common supertype of its elements, which may be OclAny or
Collection(OclAny) in mixed cases). The inferred element type of an empty
collection literal is OclVoid, which conforms to all other types, so your
expression (I) should work.

This is a bug. Would you mind raising it? (on the MDT UML2 OCL component):

https://bugs.eclipse.org/bugs/enter_bug.cgi?product=MDT& version=1.0.1&component=UML2%20OCL&bug_severity=norm al&form_name=enter_bug

Thanks,

Christian


Ed Merks wrote:

> Tord,
>
> I'll forward your question to the new OCL newsgroup.
>
>
> Tord Alenljung wrote:
>> How can I declare that for example a Set contains objects of some type
>> and then initialize it to be empty. Neither I or II below works, but
>> III does.
>>
>> (I) Not OK
>> let a:Set(Integer)=Set{} in a
>>
>> 'Init expression type does not conform to type of variable (a).'
>>
>> (II) Not OK
>> let a:Set(Integer)=Set(Integer){} in a
>>
>> '1:20:1:31 "collectionTypeIdentifierCS" expected instead of
>> "Set(Integer)"'
>>
>> (III) OK
>> let a:Set(Integer)=Set{1,3,2} in a
>>
>> 2
>> 1
>> 3
>>
>> Regards
>> Tord
Re: How to declare type of empty collection in OCL? [message #595666 is a reply to message #61376] Wed, 15 November 2006 07:11 Go to previous message
Eclipse UserFriend
Bug report at https://bugs.eclipse.org/bugs/show_bug.cgi?id=164614

Thanks
Tord

Christian W. Damus wrote:
> Hi, Tord,
>
> The element type of a collection literal is inferred from its contents (as
> the common supertype of its elements, which may be OclAny or
> Collection(OclAny) in mixed cases). The inferred element type of an empty
> collection literal is OclVoid, which conforms to all other types, so your
> expression (I) should work.
>
> This is a bug. Would you mind raising it? (on the MDT UML2 OCL component):
>
> https://bugs.eclipse.org/bugs/enter_bug.cgi?product=MDT& version=1.0.1&component=UML2%20OCL&bug_severity=norm al&form_name=enter_bug
>
> Thanks,
>
> Christian
>
>
> Ed Merks wrote:
>
>> Tord,
>>
>> I'll forward your question to the new OCL newsgroup.
>>
>>
>> Tord Alenljung wrote:
>>> How can I declare that for example a Set contains objects of some type
>>> and then initialize it to be empty. Neither I or II below works, but
>>> III does.
>>>
>>> (I) Not OK
>>> let a:Set(Integer)=Set{} in a
>>>
>>> 'Init expression type does not conform to type of variable (a).'
>>>
>>> (II) Not OK
>>> let a:Set(Integer)=Set(Integer){} in a
>>>
>>> '1:20:1:31 "collectionTypeIdentifierCS" expected instead of
>>> "Set(Integer)"'
>>>
>>> (III) OK
>>> let a:Set(Integer)=Set{1,3,2} in a
>>>
>>> 2
>>> 1
>>> 3
>>>
>>> Regards
>>> Tord
>
Previous Topic:Performance Problem with Teneo 200610261350 / Jpox 1.1.3
Next Topic:Validation action failed due to attribute type is 'long'
Goto Forum:
  


Current Time: Mon Jun 02 20:37:57 EDT 2025

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

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

Back to the top