Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » [Acceleo 3 - ocl] a "loop" question
[Acceleo 3 - ocl] a "loop" question [message #639037] Sun, 14 November 2010 23:28 Go to next message
Sergio  is currently offline Sergio Friend
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 #639089 is a reply to message #639037] Mon, 15 November 2010 09:23 Go to previous messageGo to next message
Stephane Begaudeau is currently offline Stephane BegaudeauFriend
Messages: 413
Registered: April 2010
Location: Nantes (France)
Senior Member

Hi Sergio,

Use something like this:
[for (Sequence{1..numberOfRelations(a, c.name)})]
[i/]
[/for]

("i" is the name of the default counter in a loop in Acceleo)

Stéphane Bégaudeau, Obeo



Re: [Acceleo 3 - ocl] a "loop" question [message #639594 is a reply to message #639089] Wed, 17 November 2010 06:12 Go to previous messageGo to next message
Sergio  is currently offline Sergio Friend
Messages: 21
Registered: August 2010
Location: Cardedeu
Junior Member
Hi Stéphane,

I have this code:
start
[for (a : Association | class.getAssociations() )] 
[numberOfRelations(a, class.name)/]
[for (Sequence{1..numberOfRelations(a, class.name)})]
here is inside
[/for]
here is outside
[/for]
end


this is the query:
[query public numberOfRelations(a : Association, sourceClass : String) : UnlimitedNatural = a.ownedElement->asSequence().oclAsType(Property)->select(type.name.equalsIgnoreCase(sourceClass))->upper /]


and this is the generated code:
         start
	 1
	 here is outside
	 2
	 here is outside	


what's worng?

thank you!!!



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 Go to previous messageGo to next message
Laurent Goubet is currently offline Laurent GoubetFriend
Messages: 1639
Registered: July 2009
Senior Member
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 #639634 is a reply to message #639614] Wed, 17 November 2010 09:47 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 4187
Registered: July 2009
Senior Member
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
Re: [Acceleo 3 - ocl] a "loop" question [message #639668 is a reply to message #639634] Wed, 17 November 2010 12:08 Go to previous messageGo to next message
Laurent Goubet is currently offline Laurent GoubetFriend
Messages: 1639
Registered: July 2009
Senior Member
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--
Re: [Acceleo 3 - ocl] a "loop" question [message #639776 is a reply to message #639668] Wed, 17 November 2010 17:39 Go to previous message
Ed Willink is currently offline Ed WillinkFriend
Messages: 4187
Registered: July 2009
Senior Member
Hi Laurent, Sergio
> Sequence{1..1} indeed returns a Collection,
and its size = 1, but
> yet its iterator will never do a step IIUC :
iterating over it behaves as empty.

Raised as https://bugs.eclipse.org/bugs/show_bug.cgi?id=330489, the fix
seems trivial.

Will be in 3.0.2 and 3.1.

Ed
Previous Topic:Incremental Gen. throws nullPointer
Next Topic:Class with any operation with more of one parameter
Goto Forum:
  


Current Time: Fri Dec 19 10:13:51 GMT 2014

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

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