Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » [Acceleo] How to access elements in for loop OR use a java service for that?(I can't find a way to avoid duplicates in my selections.)
[Acceleo] How to access elements in for loop OR use a java service for that? [message #1781208] Fri, 02 February 2018 18:50 Go to next message
Francesco Cagnetta is currently offline Francesco CagnettaFriend
Messages: 1
Registered: January 2018
Junior Member
Hello there,

I'm Francesco and I'm quite new to this world, but working hard on it for my thesis project.

My situation is this:

I have an Ecore metamodel and a Xmi model built according to the Ecore metamodel.

I am using Acceleo in order to transform the model into C# code.

Everything is working fine, BUT I can't find a way to avoid iterations on elements that I don't want to operate on. I'm sorry if my English is not perfect. I'll try to explain an example.

I want to print a line of code that respects this selection: for every Actor that is not the main actor and is located just one time and is the protagonist of a scoring rule and is not the protagonist of any activity.

So I have a Collection of Actors (all different), a Collection of Locations (each contains an Actor element, there can be more of the same actor), a Collection of Scoring Rules (each contains an Actor element, there can be more of the same actor), a Collection of Activities (each contains an Actor Element, there can be more of the same actor).

Hence, my problem is that I can't stop the for loop with a boolean control (if this is possible please let me know how) so it will print more lines for the same actor if it meets the requirements. For example, an actor can be the protagonist of two scoring rules and it will print the line 2 times (I want just one).

I thought about using a Java service, but I don't know how to import the classes of the metamodel in order to use them in Java (I don't even know if this is possible, I'm completely new to Java services).

I tried many different ways of code for this behaviour, but every one took me at the same point because, in the end, they're logically the same thing.

Thank you for your time, I will appreciate a lot your help,
Francesco
Re: [Acceleo] How to access elements in for loop OR use a java service for that? [message #1781329 is a reply to message #1781208] Tue, 06 February 2018 07:15 Go to previous message
Ed Willink is currently offline Ed WillinkFriend
Messages: 5622
Registered: July 2009
Senior Member
Hi

A common trick to suppress the kind of duplicates you refer to is to use a Set (or OrderedSet) rather than a Sequence or Bag. e.g. aSequence->asSet().

More generally, if you can express in words what you would like to be the value of something, you can encode those words as a query.

Regards

Ed Willink
Previous Topic:Traceability
Next Topic:[Acceleo] Filename based on result of EOperation
Goto Forum:
  


Current Time: Sun Feb 18 08:30:42 GMT 2018

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

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