I'm trying to convert a model with Xpand. So far this works quite well. But there is a split and join situation, like shown below. Foreach 'followingElement' Class1 is expanded. This results in the correct generation of 'Action1' and 'Action2'. But when expanding the followingElement'-reference of 'Class1' I get two 'Join'-elements instead of one.
Any ideas how to avoid that? Is it possible to store every expanded element in a variable to be able to check, wheather it has already been generated?
since you didn't post your metamodel and sample template code it's hard to give you best advice
(1) you can of course use a already processed list with a global var http://help.eclipse.org/helios/index.jsp?topic=/org.eclipse.xpand.doc/help/ch04s02.html or a parameter «DEFINE definition(Set alreadyProcessed) FOR Type» and add the Things you have processed - there and stop the processing if an elment was already processed.
(2) or you try to change your generation strategy e.g. by differentiating beween the Things And the Connection between the things - but as said before this is hard to tell without knowing the metamodel not the target code.
Probably your second suggestion would be the better way to go. But as the rest of the transformation is already fine, I'd prefer not to change the whole strategy, but if it helps, I of course would.
Could you explain your first suggestion a bit more detailed? I did not work with GeneratorExtensions so far. The example in the Eclipse documentation only shows how to store a single string. How can I store a List? I assume I then have to define some setter and getter method, right? I don't know how to include that in my template.
I recognized this interesting topic. Currently I have similar problems!
I am writing a code generator for an Autosar XML file. (See file attached)!
In this XML file all necessary information for variable declarations, functionality, etc. are stored. I am reading out all needed information (e.g. for variable declarations) with following commands:
FOREACH runnable.dataSendPoints.dataSendPoint.dataElementIref AS dataElementIref-»
«LET dataElementIref.dataElementPrototypeRef.value.split("/PortInterface/").last().split("/").first() AS dataElementPrototypeRef_IF-»
«FOREACH this.eAllContents.typeSelect(autosar::SenderReceiverInterface) AS SenderReceiverInterface-»
«LET SenderReceiverInterface.dataElements.dataElementPrototype.typeTref.value.split("/DataType/").last() AS dataElementPrototypeType-»