Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » [Xpand] How to save local variables in nested for loop
[Xpand] How to save local variables in nested for loop [message #648022] Mon, 10 January 2011 21:33 Go to next message
Eclipse User is currently offline Eclipse UserFriend
Messages: 14
Registered: January 2011
Junior Member
Hi,

I have a nested for loop that traverses a hierarchy of custom uml profile stereotypes. When I get to stereotyped operation parameters, I need to save off the names of the parameters depending on what stereotype property is set and output them as part of logic of an earlier for loop.

I tried looking into the "LET" capability of Xpand, but it seems that string variables with this approach are immutable, which wouldn't help me in this scenario.

Any suggestions on alternative ways of approaching this?

Thanks,

Lourdes
Re: [Xpand] How to save local variables in nested for loop [message #648024 is a reply to message #648022] Mon, 10 January 2011 21:39 Go to previous messageGo to next message
Christian Dietrich is currently online Christian DietrichFriend
Messages: 14667
Registered: July 2009
Senior Member
Hi,

one possibiliy are global vars (see std lib docs) but i doubt this is neccessary - you should be able to achive the same by a single expression but without having you problem code i cannot give futher advice. have a look at the list operations like select and collect.

~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: [Xpand] How to save local variables in nested for loop [message #648036 is a reply to message #648024] Mon, 10 January 2011 22:22 Go to previous messageGo to next message
Eclipse User is currently offline Eclipse UserFriend
Messages: 14
Registered: January 2011
Junior Member
Hi Christian,

Here's a example of the loop I'm trying to use in my Xpand template:

«DEFINE Root FOR MyProfile::MyPackageStereotype»
«FOREACH ownedType.typeSelect(MyProfile::MyInterfaceStereotype) AS p»
«FOREACH p.ownedOperation.typeSelect(MyProfile::MyOperationStereotype ) AS e»
«FOREACH e.ownedParameter.typeSelect(MyProfile::MyParam) AS param»
«REM» «IF param.level == "LOW"»
//would like to save to local var here
«ELSEIF param.level == "MEDIUM"»
//would like to save to local var here
«ENDIF» «ENDREM»
«ENDFOREACH»
«name», «p.name», «e.name», ... //would like to output "LOW" param followed by "MEDIUM" param
«ENDFOREACH»
«ENDFOREACH»
«ENDDEFINE»

I did try out the select statement in my sandbox Xpand template:

«DEFINE MyParamRoot FOR MyProfile::MyParam»
«FILE name+".txt"»
«LET this.ownedParameter.select(param | (param.level == "LOW")) AS foo»
«foo.name»
«ENDLET»
«ENDFILE»
«ENDDEFINE»

The output for this was:
[ ]

when I was expecting the name of the parameter.

Hopefully this provides sufficient detail for more specific guidance.

As a point of clarification, the two template samples provided were separate tests that do not depend on each other.

Thanks again!

[Updated on: Mon, 10 January 2011 22:24]

Report message to a moderator

Re: [Xpand] How to save local variables in nested for loop [message #648037 is a reply to message #648036] Mon, 10 January 2011 22:31 Go to previous messageGo to next message
Christian Dietrich is currently online Christian DietrichFriend
Messages: 14667
Registered: July 2009
Senior Member
hi, what about

«DEFINE Root FOR MyProfile::MyPackageStereotype»
«FOREACH ownedType.typeSelect(MyProfile::MyInterfaceStereotype) AS p»
«FOREACH p.ownedOperation.typeSelect(MyProfile::MyOperationStereotype ) AS e»
«name», «p.name», «e.name», «e.ownedParameter.typeSelect(MyProfile::MyParam).select(x|x.level == "LOW").collect(x|x.name).toString(",")»
, «e.ownedParameter.typeSelect(MyProfile::MyParam).select(x|x.level == "MEDIUM").collect(x|x.name).toString(",")»
«ENDFOREACH»
«ENDFOREACH»
«ENDDEFINE»


~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: [Xpand] How to save local variables in nested for loop [message #648061 is a reply to message #648037] Tue, 11 January 2011 03:37 Go to previous message
Eclipse User is currently offline Eclipse UserFriend
Messages: 14
Registered: January 2011
Junior Member
I had to make a slight modification to what you suggested to get it to work.

For example:
select(x|x.level == "LOW")

changed to:
select(x|x.level.name == "LOW")

so that the correct output would be produced.


Thanks again for the quick response! This was very helpful. Smile
Previous Topic:[Acceleo 3] Protected section ERROR ?
Next Topic:[Acceleo 3]Hibernate support?
Goto Forum:
  


Current Time: Fri Apr 26 17:49:45 GMT 2024

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

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

Back to the top