Dynamic type in ATL rules [message #41238] |
Thu, 24 May 2007 07:33 |
Eclipse User |
|
|
|
Originally posted by: paul.gribben.gmail.com
Hi,
I would like to define an ATL imperative rule that takes a parameter whose
type is a subtype of the declared parameter type, and the resulting
generated element is of the parameter's subtype.
For example the parameter type might be MODEL!Fruit and if I pass subtype
MODEL!Apple then the rule would generate an element of type MODEL!Apple.
Is is possible in ATL?
Thanks for any help.
|
|
|
Re: [ATL] Dynamic type in ATL rules [message #41360 is a reply to message #41238] |
Thu, 24 May 2007 13:56 |
Frédéric Jouault Messages: 572 Registered: July 2009 |
Senior Member |
|
|
Hi,
Could you please remember to prefix the subjects of your ATL-related
posts with [ATL], as I did in this reply? Thanks.
> I would like to define an ATL imperative rule that takes a parameter
> whose type is a subtype of the declared parameter type, and the
> resulting generated element is of the parameter's subtype.
>
> For example the parameter type might be MODEL!Fruit and if I pass
> subtype MODEL!Apple then the rule would generate an element of type
> MODEL!Apple. Is is possible in ATL?
>
> Thanks for any help.
We added an imperative part to ATL to make sure that any transformation
scenario can be written in ATL, even in cases for which the declarative
style is not appropriate.
So, the answer to your question is: yes, it is possible.
The simplest way to create elements of a type when you do not know the
type at compile time is to use the reflexive API. In your case:
OclAny.oclType() to get the type of the source element, and
MOF!Class.newInstance(), or ECore!EClass.newInstance() to create a new
element of this type.
The code could look like:
rule MyRule(s : MODEL!Fruit) {
do {
s.oclType().newInstance();
}
}
Another alternative would be to test for the type (if-else if-else
if-...) and call other rules to create the appropriate target element.
However, this would require a lot more code ;-).
May I ask why you chose to look for an imperative solution instead of a
declarative one? As I said above, the imperative part of ATL is there to
make sure you can handle any model transformation scenario. However, we
are very interested in knowing when the declarative part is not enough,
in order to understand what kinds of improvements we could make to it.
Moreover, as you may have noticed by reading this newsgroup, they are
often quite simpler declarative solutions that can be used instead of
imperative ones. It is very possible that your case could be handled by
the declarative part of ATL as it is today.
Regards,
Frédéric Jouault
|
|
|
Re: [ATL] Dynamic type in ATL rules [message #41582 is a reply to message #41360] |
Fri, 25 May 2007 07:28 |
Eclipse User |
|
|
|
Originally posted by: paul.gribben.gmail.com
Hi Frédéric,
Thanks- I'll try to remember the prefix :)
The transform I am executing is a rather complex 3-way merge, and although
I would have wanted to use the delclarative approach (being more natural
for ATL) the problem is that it presumes you can know what output elements
to generate given a group of input elements, and that you can establish
the correct processing context by examining those input elements (using
the OCL clause). In my case the processing context includes various other
aspects, and is more naturally expressed as procedural logic (hence
imperative approach).
Sorry if this seems a bit abstract, but to explain further would probably
require picking throught the actual transform and delving into lots of
details.
In this instance it would have been good to support syntax like this:
to
varname : param.oclType() (
attrname <- param.attrname
)
The other concern I have with declarative rules (for this transform
anyway) is that I cant control what elements the rules are fired against
except by filtering out in that rule using OCL. I'd rather be able to do
something like 'applyRules(collection)' in a similar manner to XSLT's
apply-templates.
Thanks again for your help.
|
|
|
Re: [ATL] Dynamic type in ATL rules [message #41763 is a reply to message #41582] |
Fri, 25 May 2007 14:59 |
Frédéric Jouault Messages: 572 Registered: July 2009 |
Senior Member |
|
|
Hi Paul,
> Thanks- I'll try to remember the prefix :)
Thanks ;-).
> The transform I am executing is a rather complex 3-way merge, and
> although I would have wanted to use the delclarative approach (being
> more natural for ATL) the problem is that it presumes you can know what
> output elements to generate given a group of input elements, and that
> you can establish the correct processing context by examining those
> input elements (using the OCL clause). In my case the processing context
> includes various other aspects, and is more naturally expressed as
> procedural logic (hence imperative approach).
>
> Sorry if this seems a bit abstract, but to explain further would
> probably require picking throught the actual transform and delving into
> lots of details.
Thanks for your explanation.
> In this instance it would have been good to support syntax like this:
> to
> varname : param.oclType() (
> attrname <- param.attrname
> )
This is exactly the example I discussed with Mikaël after having
answered your post ;-).
We are definitely considering this possibility.
> The other concern I have with declarative rules (for this transform
> anyway) is that I cant control what elements the rules are fired against
> except by filtering out in that rule using OCL. I'd rather be able to do
> something like 'applyRules(collection)' in a similar manner to XSLT's
> apply-templates.
Well, this is what lazy rules are for. The difference between lazy rules
and called rules is that lazy rules are "more" declarative. For
instance, and you can use automatic traceability (especially for unique
lazy rules).
Therefore, my advice is that you try using (unique) lazy rules, and come
back to us (i.e., on this newsgroup) if you have a problem, or if it
works (we are not *only* interested in problems ;-)).
Best regards,
Frédéric Jouault
|
|
|
Re: [ATL] Dynamic type in ATL rules [message #44082 is a reply to message #41763] |
Mon, 04 June 2007 13:13 |
Eclipse User |
|
|
|
Originally posted by: paul.gribben.gmail.com
Hi Frédéric,
Sorry for the delay in getting back to you. I've been using the ATL User
Manual (version 0.7) as my guide - it doesn't have anything about lazy
rules. However I did find something on the ATL_Language_Troubleshooter
wiki. Yes this does sound very much like what I need to use. Thanks for
the information!
Cheers
Paul
|
|
|
|
Powered by
FUDForum. Page generated in 0.03471 seconds