Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    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 10:25 Go to next message
Tord Alenljung is currently offline Tord AlenljungFriend
Messages: 4
Registered: July 2009
Junior Member
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 11: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 14: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 12:11 Go to previous message
Tord Alenljung is currently offline Tord AlenljungFriend
Messages: 4
Registered: July 2009
Junior Member
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 11:21 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 31770
Registered: July 2009
Senior Member
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


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: How to declare type of empty collection in OCL? [message #595643 is a reply to message #61256] Tue, 14 November 2006 14: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 12:11 Go to previous message
Tord Alenljung is currently offline Tord AlenljungFriend
Messages: 4
Registered: July 2009
Junior Member
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: Thu Feb 25 23:24:33 GMT 2021

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

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

Back to the top