|
Re: [ATL] Problems when copying properties from a class [message #5283 is a reply to message #5081] |
Fri, 05 January 2007 10:35 |
Eclipse User |
|
|
|
Originally posted by: mikael.barbero.gmail.com
Hi Aitor,
First, could you stick with the rule in this newsgroup of always
prefixing the subject line of your question, answer or comment by the
[ATL] tag ? We absolutely need to enforce this rule/habit since the M2M
project has several components. Thank you very much.
Your issue seems to get its source from a little misunderstanding of how
ATL actually works. In your imperative rule part (do {...}), you are
trying to bind ("<-") something from your target model
(t.ownedAttribute) to something from your source model
Note: I suppose that you allClasses helper is doing something like this:
helper def: allClasses : Sequence(UML2!Class) =
UML2!Class.allInstancesFrom('YourSourceModelName');
You cannot copy something from you source model directly to your output
model. When you want to copy a UML2!Class, you are doing a rule, thus,
you have to do the same thing for UML2!Attribute. But you may not want
to copy all attributes from your source model. So you should create a
lazy rule for attribute (a lazy rule is a matched rule that is matched
only when its called). This should look this:
lazy rule Attribute {
from
i : UML2!Attribute
to
o : UML2!Attribute (
...
)
}
And then, call it in your imperative rule part like this :
t.ownedAttribute <-
thisModule.allClasses->select(p|p.name='B').first().ownedAttribute- >collect(e
| thisModule.Attribute(e))
and
t.ownedAttribute <- Sequence{thisModule.Attribute(attribute)} -- Here, i
think that t.ownedAttribute is multivalued, then you have to create a
Sequence.
Hope this help.
Mikaël
Aitor Bediaga a écrit :
> Hi all,
>
> I'm trying to copy some properties from a class (B) to other class (A).
> If class A has a property with type = B then all properties of B has to
> be copied to A.
>
> Class A:
> -property1 : integer
> -property2 : integer
> -property3 : B
>
> Class B:
> -property4 :integer
> -property5 : integer
>
> AFTER TRANSFORMATION
>
> Class A:
> -property1 : integer
> -property2 : integer
> -property4 :integer
> -property5 : integer
>
> Class B:
> -property4 :integer
> -property5 : integer
>
>
> I have produced this rule, but doesn't work very well...
> rule refine_class {
> from
> s : UML2!Class
> to
> t : UML2!Class (
> name <- s.name,
> -- ownedAttribute <- s.ownedAttribute,
> packageImport <- s.packageImport,
> nameExpression <- s.nameExpression
> )
> do { for (attribute in s.ownedAttribute){
> if (thisModule.allClasses.includes(attribute.type))
> t.ownedAttribute
> <-thisModule.allClasses->select(p|p.name='B').first().ownedAttribute;
> else
> t.ownedAttribute <-attribute;
> }
> }
>
> Any idea?
>
> Thank you in advance,
>
> Aitor Bediaga
>
>
--
Mikaël Barbero - PhD Candidate
ATLAS Group (INRIA & LINA) - University of Nantes
2, rue de la Houssinière
44322 Nantes Cedex 3 - France
tel. +33 2 51 12 58 08 /\ cell.+33 6 07 63 19 00
email: Mikael.Barbero@{gmail.com, univ-nantes.fr}
http://www.sciences.univ-nantes.fr/lina/atl/
|
|
|
Powered by
FUDForum. Page generated in 0.02573 seconds