Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » [Acceleo] 'If' on an Iterate loop(Is it possible?)
[Acceleo] 'If' on an Iterate loop [message #501304] Tue, 01 December 2009 14:31 Go to next message
Andre is currently offline Andre
Messages: 29
Registered: November 2009
Location: Brazil
Junior Member
hi

Is it possible to use an 'if' expression on a iterate loop?

I've saw this expression on OMG OCL documentation (page 145)...
result = self->iterate( elem; acc : Integer = 0 | if elem = object then acc + 1 else acc endif)

... and have tried to used the expression below:
[query hasList(m : MetaComponent) : Boolean =
m.relationship->iterate(item; res : Boolean = false | if item.highCardinalitie <> 1 then true endif ) /]


This expression has this error: 'then unexpected token'.
Is the sintax incorrect? Is there any other way to obtain this result?

Another question: is there any command similar to java 'Break', used to terminate a loop?

thanks


Andre Silva
Natal-RN
Brazil
Re: [Acceleo] 'If' on an Iterate loop [message #501413 is a reply to message #501304] Wed, 02 December 2009 04:07 Go to previous message
Laurent Goubet is currently offline Laurent Goubet
Messages: 1621
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------050204050402050908000106
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit

Andre,

OCL if's need their "else" defined or else are incorrect, though the
error message they return doesn't make it clear.

m.relationship->iterate(item; res : Boolean = false | if
item.highCardinalitie <> 1 then true else false endif )

would see the if compile, though I don't really understand your need
here. As for a break, there is none in OCL. You should use

m.relationship->any(item | item.highCardinalitie <> 1 )

if you wish to check that at least one element of the list verifies the
condition.

Laurent Goubet
Obeo

Andre wrote:
> hi
>
> Is it possible to use an 'if' expression on a iterate loop?
>
> I've saw this expression on OMG OCL documentation (page 145)... result =
> self->iterate( elem; acc : Integer = 0 | if elem = object then acc +
> 1 else acc endif)
>
> .. and have tried to used the expression below:
> [query hasList(m : MetaComponent) : Boolean =
> m.relationship->iterate(item; res : Boolean = false | if
> item.highCardinalitie <> 1 then true endif ) /]
>
> This expression has this error: 'then unexpected token'.
> Is the sintax incorrect? Is there any other way to obtain this result?
>
> Another question: is there any command similar to java 'Break', used to
> terminate a loop?
>
> thanks


--------------050204050402050908000106
Content-Type: text/x-vcard; charset=utf-8;
name="laurent_goubet.vcf"
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
filename="laurent_goubet.vcf"

YmVnaW46dmNhcmQNCmZuOkxhdXJlbnQgR291YmV0DQpuOkdvdWJldDtMYXVy ZW50DQpvcmc6
PGEgaHJlZj0iaHR0cDovL3d3dy5vYmVvLmZyIj5PYmVvPC9hPg0KZW1haWw7 aW50ZXJuZXQ6
bGF1cmVudC5nb3ViZXRAb2Jlby5mcg0KdXJsOmh0dHA6Ly93d3cub2Jlby5m cg0KdmVyc2lv
bjoyLjENCmVuZDp2Y2FyZA0KDQo=
--------------050204050402050908000106--
Previous Topic:[Xpand/Xtend] MetaModelContributor for oAW
Next Topic:[MTL] the emtl-file
Goto Forum:
  


Current Time: Tue Jul 29 08:48:13 EDT 2014

Powered by FUDForum. Page generated in 0.03425 seconds