Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » M2M (model-to-model transformation) » [ATL] ordered transformations
[ATL] ordered transformations [message #19276] Tue, 27 February 2007 18:29 Go to next message
Eclipse UserFriend
Originally posted by: irbull.cs.uvic.ca

I have two questions about the ordering of transformations:

1) Is it possibly to specify transformations to happen in the same order
that the elements exist in the source model. That is, if I have list of
elements [a,b,c,d] and I transform these to nodes, can I ensure the
transformations matches a,b,c,d in that order?

2) How does the sortedBy work? I have the following transformation (below):

In the imperative section I add the Item to my list of items, and then I
try to sort my entire list by the value. This doesn't seem to work. The
documentation says that sortedBy returns a list, so I have also tried:
thisModule.root.items <- thisModule.root.items->sortedBy( e | e.value );

Still no luck

<snip>
module ExampleTransformation; -- Module Header
create OUT : barchartviewer from IN : viewshaper;

rule MappRule1 {
from s : viewshaper!Node
to t : barchartviewer!Item (
label <- s.attributes-> ...
value <- s.attributes-> ...
)
do {
thisModule.root.items<-t;
thisModule.root.items->sortedBy( e | e.value );
}
}

helper def: root: barchartviewer!BarChartViewer=OclAny;

entrypoint rule ModelRule() {
to t : barchartviewer!BarChartViewer
do {
thisModule.root <- t;
}
}
</snip>

Thanks,
Ian
Re: [ATL] ordered transformations [message #22476 is a reply to message #19276] Fri, 09 March 2007 15:49 Go to previous messageGo to next message
Ronan is currently offline RonanFriend
Messages: 10
Registered: July 2009
Junior Member
Hi Ian,
If you defined your meta-model in KM3 then you can define elements to be
ordered. I don't use KM3 but there if details of how to do this on the old
yahoo newsgroup.

1) I use ECore to define all my meta-models and don't think it is possible
to guarantee the order of the output of the transformation. You can of
course order the source elements before the transformation, assuming the
source element has a useful attribute upon which the sort can be performed
on. For example I have an order attribute on some of my source model
elements, so I order the source collection ( ->sortedBy(e|e.order) ) and
then transform them.

2) You can perform a for loop over the sorted collection and access each
of the sorted elements appropriately.

Cheers,
Ronan
Re: [ATL] ordered transformations [message #25575 is a reply to message #19276] Fri, 23 March 2007 23:32 Go to previous message
Frédéric Jouault is currently offline Frédéric JouaultFriend
Messages: 572
Registered: July 2009
Senior Member
Hello Ian,

> 1) Is it possibly to specify transformations to happen in the same order
> that the elements exist in the source model. That is, if I have list of
> elements [a,b,c,d] and I transform these to nodes, can I ensure the
> transformations matches a,b,c,d in that order?

No it is not possible to specify the execution order of declarative
rules (with respect to each other, and to the elements they match).
Declarative transformations are still deterministic because this order
does not matter.

However, you may have problems when you insert imperative statements in
your declarative rules.

When you use imperative constructs, you have to make sure that the part
of the target model you are modifying is in a known state. For the
action block (i.e., the "do" part) of declarative rules, you can achieve
this by only working on the elements generated by this very same rule
for the current source.

If you need to perform something on a larger part of the model, you may
put the corresponding code in an endpoint rule.


> 2) How does the sortedBy work?

Yes.

> I have the following transformation
> (below):
>
> In the imperative section I add the Item to my list of items, and then I
> try to sort my entire list by the value. This doesn't seem to work. The
> documentation says that sortedBy returns a list, so I have also tried:
> thisModule.root.items <- thisModule.root.items->sortedBy( e | e.value );

You are right that this version is more likely to work than the one in
your code snippet, which does not store the value returned by sortedBy.

> Still no luck

However, you are trying to modify the root from a declarative rule, when
you know little about the state of the whole model.
You should do this in an endpoint rule (see above).

Additionally, you are assigning the elements to root.items several
times. You should only assign them once, in the correct order.

One way to do this is the following:

rule MappRule1 {
from s : viewshaper!Node
to t : barchartviewer!Item (
label <- s.attributes-> ...
value <- s.attributes-> ...
)
do {
thisModule.items <- thisModule.items->including(t);
}
}

helper def: item: Sequence(barchartviewer!Item)=Sequence{};

endpoint rule ModelRule() {
to t : barchartviewer!BarChartViewer
do {
t.items <- thisModule.items->sortedBy( e | e.value );
}
}


Note that we store the items in a temporary collection, and that we only
sort the whole collection once after the declarative part has finished
its execution.

If you need the root to be created before the execution of the
declarative part for some other reason, you may still create it in an
entrypoint. However, because it did not seem necessary to have both an
entrypoint and an endpoint here, I simplified the transformation.


Note that if you have a root element in your source model, it should
also be possible to have a declarative-only solution. You could indeed
sort the sequence of viewshaper!Node, which would resolve into a sorted
sequence of barchartviewer!Item.
To avoid recomputing the value, you could use an attribute helper.


Best regards,

Frédéric Jouault
Previous Topic:[ATL] How to run ATL from program in silent mode
Next Topic:[ATL] Code completion for ATL editor, when?
Goto Forum:
  


Current Time: Fri May 10 11:56:17 GMT 2024

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

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

Back to the top