Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » M2M (model-to-model transformation) » Re: [ATL] adding operation
Re: [ATL] adding operation [message #29547] Wed, 04 April 2007 19:33 Go to next message
Eclipse UserFriend
Originally posted by: marcos.didonet-del-fabro.univ-nantes.fr

Hello,


There are two plugins (that I know) that extend ATL with new operations.
- org.eclipse.m2m.atl.ocl.ecore in the ATL CVS. This plug-in is used to execute OCL
queries within ATL.
- org.eclipse.gmt.weaver.amw4atl in the AMW CVS. This plug-in is a model handler for using
weaving models with ATL.

I will explain you using the second plug-in because I know the code better.

In our case, we need to add a method that calculates the similarity between two strings.
For instance, to say that "name" is similar to "firstname".

-----------Implementing the method----------

we created the following method in the class ASMAMWModelElement:

public static ASMReal getStringSim(StackFrame frame, ASMString left, ASMString right)

The methods must be static. In this case, the return type is a float. The equivalent ATL
type is ASMReal. If you want another return type, you can use for instance ASMInteger,
ASMString, etc.

The first parameter is mandatory. I don't know exaclty why, but Frédéric probably knows it
better :). The second parameter is the type of the element that will call this method in
an ATL transformation, and the last parameter is the "real" method parameter. You can add
as much parameters as you want, but they must use the ATL types.

In this case, we call this method in ATL in the following way:

amodelElement <- "someString".getStringSim("anotherstring")

There are other similar methods in the same class, for instance

public static ASMOclAny getReferredElement(StackFrame frame, ASMEMFModelElement self)

Then you implement whatever you want in the method...

------------Registering the method-----------------

The next step is to register this method in the ATL VM. You need to call the method
"addVMOperation". An example is available in the ASMAMWModel class:

addVMOperation(ASMString.myType, toVMOperation(ASMAMWModelElement.class, "getStringSim"));

The first parameter is the type of the object that calls the method (String in this case).
Then, in the toVMOperation you put the class where you implemented the method, and the
method name.

You can copy and paste the code from "addVMOperation" and "toVMOperation" exactly how it
is in your own plug-in. That's what I did, by copying from the OCL plug-in I mentioned before.

------------Where to do it----------------------------

You can implement you own plug-in and add these methods. However, the plug-in must be
loaded and the method must be registered before it is called in the ATL transformation.

Before having this separated plug-in, I used to add all the extensions directly in the
code of the OCL plug-in (for simplicity reasons), in the class
org.eclipse.m2m.atl.ocl.core.OclEvaluator. This is not a very elegant solution, but I
could start testing the methods quickly.

I hope it helps,

Regards,

Marcos.

Bert Vanhooff wrote:
> All,
>
> I would like to extend ATL with a new OCL operation that I cannot
> express as a helper. I assume I will have to make some additions to the
> source code to accomplish that. Can anyone give me an idea of the
> effort this would require?. Also, where should I start looking in the
> source code?
>
>
> Thanks in advance,
> Bert.
Re: [ATL] adding operation [message #30634 is a reply to message #29547] Tue, 10 April 2007 15:22 Go to previous message
Bert Vanhooff is currently offline Bert VanhooffFriend
Messages: 6
Registered: July 2009
Junior Member
Thanks for the detailed explanation. I will take a closer look in the
coming weeks.


Best regards,
Bert.

Marcos Didonet Del Fabro wrote:
> Hello,
>
>
> There are two plugins (that I know) that extend ATL with new operations.
> - org.eclipse.m2m.atl.ocl.ecore in the ATL CVS. This plug-in is used to
> execute OCL queries within ATL.
> - org.eclipse.gmt.weaver.amw4atl in the AMW CVS. This plug-in is a model
> handler for using weaving models with ATL.
>
> I will explain you using the second plug-in because I know the code better.
>
> In our case, we need to add a method that calculates the similarity
> between two strings. For instance, to say that "name" is similar to
> "firstname".
>
> -----------Implementing the method----------
>
> we created the following method in the class ASMAMWModelElement:
>
> public static ASMReal getStringSim(StackFrame frame, ASMString left,
> ASMString right)
>
> The methods must be static. In this case, the return type is a float.
> The equivalent ATL type is ASMReal. If you want another return type, you
> can use for instance ASMInteger, ASMString, etc.
>
> The first parameter is mandatory. I don't know exaclty why, but Frédéric
> probably knows it better :). The second parameter is the type of the
> element that will call this method in an ATL transformation, and the
> last parameter is the "real" method parameter. You can add as much
> parameters as you want, but they must use the ATL types.
>
> In this case, we call this method in ATL in the following way:
>
> amodelElement <- "someString".getStringSim("anotherstring")
>
> There are other similar methods in the same class, for instance
>
> public static ASMOclAny getReferredElement(StackFrame frame,
> ASMEMFModelElement self)
>
> Then you implement whatever you want in the method...
>
> ------------Registering the method-----------------
>
> The next step is to register this method in the ATL VM. You need to call
> the method "addVMOperation". An example is available in the ASMAMWModel
> class:
>
> addVMOperation(ASMString.myType, toVMOperation(ASMAMWModelElement.class,
> "getStringSim"));
>
> The first parameter is the type of the object that calls the method
> (String in this case). Then, in the toVMOperation you put the class
> where you implemented the method, and the method name.
>
> You can copy and paste the code from "addVMOperation" and
> "toVMOperation" exactly how it is in your own plug-in. That's what I
> did, by copying from the OCL plug-in I mentioned before.
>
> ------------Where to do it----------------------------
>
> You can implement you own plug-in and add these methods. However, the
> plug-in must be loaded and the method must be registered before it is
> called in the ATL transformation.
>
> Before having this separated plug-in, I used to add all the extensions
> directly in the code of the OCL plug-in (for simplicity reasons), in the
> class org.eclipse.m2m.atl.ocl.core.OclEvaluator. This is not a very
> elegant solution, but I could start testing the methods quickly.
>
> I hope it helps,
>
> Regards,
>
> Marcos.
>
> Bert Vanhooff wrote:
>> All,
>>
>> I would like to extend ATL with a new OCL operation that I cannot
>> express as a helper. I assume I will have to make some additions to
>> the source code to accomplish that. Can anyone give me an idea of the
>> effort this would require?. Also, where should I start looking in the
>> source code?
>>
>>
>> Thanks in advance,
>> Bert.
Previous Topic:Cannot access uml2 stereotype values in ATL
Next Topic:[ATL] UML class diagram to ER
Goto Forum:
  


Current Time: Tue Mar 19 05:30:37 GMT 2024

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

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

Back to the top