[ATL] 1:M transformations [message #94633] |
Thu, 06 November 2008 15:56  |
Eclipse User |
|
|
|
Hi all,
Does anyone know how to create x elements in the target model for one in
the source where x is unknown at development time.
For example, below I want to great x number of T, which is the number of
S-1 and the targetModelElementAttrubutes will be different for each of the
generated TargetModelElements.
rule learningResourceModel2LearningResourceModel{
from
s:S!SourceModelElement
to
t:T!TargetModelElement(
targetModelElementAttribute <- ???
)
}
Thanks for your help,
Mark
|
|
|
Re: [ATL] 1:M transformations [message #94650 is a reply to message #94633] |
Fri, 07 November 2008 01:19   |
Eclipse User |
|
|
|
Hi Mark,
I think you can only do this imperatively with a called rule:
rule learningResourceModel2LearningResourceModel(s:S!SourceModelE lement) {
t <- T!TargetModelElement.newInstance();
for (n = s.lower .. s.upper) {
t.targetModelElementAttribute <- T!????.newInstance();
}
}
But not sure about the syntax or the newInstance call. Hope it helps though.
Regards,
Alfons
"Mark Melia" <mark.melia@gmail.com> schreef in bericht
news:7e8814c4a06b0d2a2b156f660b767a64$1@www.eclipse.org...
> Hi all,
>
> Does anyone know how to create x elements in the target model for one in
> the source where x is unknown at development time.
>
> For example, below I want to great x number of T, which is the number of
> S-1 and the targetModelElementAttrubutes will be different for each of the
> generated TargetModelElements.
>
> rule learningResourceModel2LearningResourceModel{
> from s:S!SourceModelElement
> to
> t:T!TargetModelElement(
> targetModelElementAttribute <- ???
> )
> }
>
> Thanks for your help,
> Mark
>
|
|
|
Re: [ATL] 1:M transformations [message #94663 is a reply to message #94650] |
Fri, 07 November 2008 01:22   |
Eclipse User |
|
|
|
"Alfons Laarman" <a.w.laarman@student.utwente.nl> schreef in bericht
news:gf053q$6lj$1@build.eclipse.org...
> Hi Mark,
>
> I think you can only do this imperatively with a called rule:
>
> rule learningResourceModel2LearningResourceModel(s:S!SourceModelE lement) {
> t <- T!TargetModelElement.newInstance();
> for (n = s.lower .. s.upper) {
> t.targetModelElementAttribute <- T!????.newInstance();
> }
> }
On second thought, a called rule is maybe not needed:
rule learningResourceModel2LearningResourceModel{
from s:S!SourceModelElement
to t:T!TargetModelElement
do {
for (n = s.lower .. s.upper) {
t.targetModelElementAttribute <- T!????.newInstance();
}
}
}
good luck!
|
|
|
Re: [ATL] 1:M transformations [message #94678 is a reply to message #94633] |
Fri, 07 November 2008 09:09  |
Eclipse User |
|
|
|
I'm not sure what your mean by S-1. I am guessing you mean
S!SourceModelElement->allInstances()->size()-1
If you like a declarative approach, you can try something like this:
helper def : sourceElements : Sequence(S!SourceModelElement) =
S!SourceModelElement->allInstances()->asSequence();
helper def : sMinusOne : Sequence(S!SourceModelElement) =
thisModule.sourceElements->excluding(thisModule.sourceElements- >last());
rule learningResourceModel2LearningResourceModel{
from s:S!SourceModelElement
to
t:T!TargetModelElement(
targetModelElementAttribute <- thisModule.sMinusOne
->collect(se|thisModule.Source2Attribute(se));
)
}
lazy rule Source2Attribute {
from s:S!SourceModelElement
to
t:T!TargetModelElementAttribute()
}
|
|
|
Powered by
FUDForum. Page generated in 0.05232 seconds