Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » [Acceleo] Random order in UML for sequence of datatypes
[Acceleo] Random order in UML for sequence of datatypes [message #1221354] Tue, 17 December 2013 14:03 Go to next message
Johan Hardy is currently offline Johan HardyFriend
Messages: 47
Registered: December 2012
Member

Dear all,

I'm developing a generator UML to C based on Acceleo. One of my transformations is the generation of typedef in C. With the help of a profile, I mapped a stereotype called typedef on the meta-class datatype.

In the template, when I want to generate all the types and for instance the typedefs, I filter all the types of a Class to get a sequence of datatypes (with the stereotype 'typedef' applied). Here is my transformation:

[query public getAllTypedef(seq : Sequence(uml::DataType)) : Sequence(uml::DataType) =  
seq->select(d : uml::DataType | (hasStereotype(d, 'functional_C::Typedef')))->asSequence()/]

[template public genHTypedef(c : uml::Class) post(trim())]
[let seq : Sequence(uml::DataType) = getAllTypedef(ownedElement->filter(uml::DataType)->asSequence())]
[for (d : uml::DataType | seq )]
[d.genTypedef()/]

[/for]
[/let]
[/template]


My problem is that the typedefs are not generated in the same order from one generation to another AND the MODEL REMAINS the same. For example, Class A with datatype B and datatype C gives at the first generation:

typedef B
typedef C

And, for the second generation (the class remains the same) :

typedef C
typedef B

Does anyone know why the sequence of datatypes has different order from one generation to another ?
Does anyone know how to solve this problem ?

Best regards;
Johan

[Updated on: Wed, 18 December 2013 12:14]

Report message to a moderator

Re: [Acceleo] Random order in UML for sequence of datatypes [message #1221848 is a reply to message #1221354] Wed, 18 December 2013 14:44 Go to previous messageGo to next message
Johan Hardy is currently offline Johan HardyFriend
Messages: 47
Registered: December 2012
Member

Here is the query that ensures the same order as the one present in the XMI:

[query public orderByContents(b : Sequence(uml::NamedElement)) : Sequence (uml::NamedElement) = 
                                  b->sortedBy(
                                         n : uml::NamedElement | n.eContainer().eContents()->indexOf(n) 
                                  )
/]

Re: [Acceleo] Random order in UML for sequence of datatypes [message #1228483 is a reply to message #1221848] Tue, 07 January 2014 10:29 Go to previous messageGo to next message
Stephane Begaudeau is currently offline Stephane BegaudeauFriend
Messages: 458
Registered: April 2010
Location: Nantes (France)
Senior Member

Hi,

This issue occurs because the UML metamodel states that the order is not relevant for several properties (ordered = false). As a result, OCL uses instances of java.util.Set to manipulate those sequences so the order is random in Acceleo.

Regards,

Stephane Begaudeau, Obeo

--
Twitter: @sbegaudeau
Google+: +stephane.begaudeau
Blog: http://stephanebegaudeau.tumblr.com | Eclipse Java Development Tools Tips and Tricks
Re: [Acceleo] Random order in UML for sequence of datatypes [message #1232091 is a reply to message #1228483] Thu, 16 January 2014 08:02 Go to previous messageGo to next message
Johan Hardy is currently offline Johan HardyFriend
Messages: 47
Registered: December 2012
Member

Many thanks for the explanation, Stéphane.

Best regards;
Re: [Acceleo] Random order in UML for sequence of datatypes [message #1247965 is a reply to message #1228483] Sun, 16 February 2014 20:47 Go to previous messageGo to next message
Furkan Eke is currently offline Furkan EkeFriend
Messages: 31
Registered: June 2012
Member
This obviously brings a problem where one needs to revise the generated code during the development of the very Acceleo engine for her/his domain.

Can this problem be solved with a workaround like: prior to generation a sorting of the relevant elements based on their names?

How should one change the query for such a solution?
Re: [Acceleo] Random order in UML for sequence of datatypes [message #1248381 is a reply to message #1247965] Mon, 17 February 2014 07:36 Go to previous message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

It is not a problem so there is no need for a workaround. It is a user
misconception that there was an order.

If you want to impose 'your' order you need to use a ordering algorithm
such as the OCL sortedBy iteration.

e.g.

namedElements->sortedBy(name)

Regards

Ed Willink


On 16/02/2014 20:47, Furkan Eke wrote:
> This obviously brings a problem where one needs to revise the
> generated code during the development of the very Acceleo engine for
> her/his domain.
>
> Can this problem be solved with a workaround like: prior to generation
> a sorting of the relevant elements based on their names?
>
> How should one change the query for such a solution?
Previous Topic:[Acceleo] generate code from a model in Java Class (run-time)
Next Topic:[Acceleo] Generation no longer works after upgrade to Eclipse 4.3
Goto Forum:
  


Current Time: Thu Apr 25 05:40:04 GMT 2024

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

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

Back to the top