[Acceleo 3 - ocl] a "loop" question [message #639037] |
Sun, 14 November 2010 23:28 |
Sergio Messages: 21 Registered: August 2010 Location: Cardedeu |
Junior Member |
|
|
Hi,
I'm sorry. I know that this is a silly question, but you can be sure that I was searching for an answer and that I was trying some things before make the question...
Well, what I need to do is only a simple loop. Like the next one (that I can do in java) but in acceleo3
for (int i = 0; i<2; i++ ){
...
}
where "2" is an upper association...
I was trying some (wrongs) things like this
[for (i:Integer | Sequence{1..numberOfRelations(a, c.name)})]
private [ a.endType->last().name/] [a.endType->last().name.toLowerFirst().concat(i.toString())/];
[/for]
Thank you!
Sergio
Sergio Sacristán
http://s2o-bcn.blogspot.com/
|
|
|
|
|
Re: [Acceleo 3 - ocl] a "loop" question [message #639614 is a reply to message #639594] |
Wed, 17 November 2010 08:21 |
|
Hi Sergio,
Sequence{1..1} creates an empty Sequence. According to the OCL specification, "'x.y' denotes all the Integers between the values of x and y, including x an y themselves"... There is indeed no element "between" 1 and 1 ... but I believe "1" should still be included, the specification doesn't cover this. You'll have to raise a bug against MDT/OCL or start a thread on the eclipse.modeling.mdt.ocl newsgroup for discussion about this issue (Ed Willink does look at the m2t newsgroup, but I don't know if he'll stumble upon this discussion).
However, Sequence{1..2} does indeed instantiate a Sequence of 2 elements (the integers '1' and '2') ... and I don't understand why you don't get the two "here is inside" Strings this should generate. A test with the same for loops on my side properly generates the content with [for (Sequence{1..2})]...[/for]. Are you sure that this is indeed your generated content?
Laurent Goubet
Obeo
|
|
|
|
Re: [Acceleo 3 - ocl] a "loop" question [message #639668 is a reply to message #639634] |
Wed, 17 November 2010 12:08 |
|
This is a multi-part message in MIME format.
--------------030705060100020703000208
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Ed,
Sequence{1..1} indeed returns a Collection, yet its iterator will never
do a step IIUC :
line 2259 of EvaluationVisitorImpl :
public boolean hasNext() {
return curr < last;
}
"curr" being "1" and "last" ... 1.
This makes it so that "hasNext()" doesn't return true for "1..1".
Yet, with "hasNext" implemented like that, why does this properly make
two iterations for "1..2"? And that's because of "next" :
public Integer next() {
if (!initialized) {
curr = first - 1;
initialized = true;
}
[...]
with "initialized" set to "false" from the constructor. I don't really
understand why the implementation has been made like that ... but this
is the reason why a Sequence{1..1} acts exactly as would an empty
collection.
Sergio, please link to this discussion when raising the bug, it'll avoid
us searching the reason of this behavior again ^^.
Laurent Goubet
Obeo
On 17/11/2010 10:47, Ed Willink wrote:
> Hi Laurent
>
> I'm here. I try to spot 'OCL' in M2T.
>
> The OCL 2.2 specification does not make it easy to decode
> CollectionRange, but in Clause 8 the recursive definition of
> CollectionRangeEval::getRange is clearly first inclusive to last
> inclusive. I would really be very surprised if MDT/OCL has a bug here.
> Are you sure that MDT/OCL is at fault? If so please raise a Bugzilla.
>
> Regards
>
> Ed Willink
>
>
> On 17/11/2010 08:21, Laurent Goubet wrote:
>> Hi Sergio,
>>
>> Sequence{1..1} creates an empty Sequence. According to the OCL
>> specification, "'x.y' denotes all the Integers between the values of x
>> and y, including x an y themselves"... There is indeed no element
>> "between" 1 and 1 ... but I believe "1" should still be included, the
>> specification doesn't cover this. You'll have to raise a bug against
>> MDT/OCL or start a thread on the eclipse.modeling.mdt.ocl newsgroup
>> for discussion about this issue (Ed Willink does look at the m2t
>> newsgroup, but I don't know if he'll stumble upon this discussion).
>>
>> However, Sequence{1..2} does indeed instantiate a Sequence of 2
>> elements (the integers '1' and '2') ... and I don't understand why you
>> don't get the two "here is inside" Strings this should generate. A
>> test with the same for loops on my side properly generates the content
>> with [for (Sequence{1..2})]...[/for]. Are you sure that this is indeed
>> your generated content?
>>
>> Laurent Goubet
>> Obeo
>
--------------030705060100020703000208
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=
--------------030705060100020703000208--
|
|
|
|
Powered by
FUDForum. Page generated in 0.52399 seconds