Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » MoDisco » where can I learn ATL for handling java metamodel
where can I learn ATL for handling java metamodel [message #783794] Thu, 26 January 2012 08:29 Go to next message
Jing Ge is currently offline Jing Ge
Messages: 12
Registered: January 2012
Junior Member
Hello community,

I am new here and try to transform one java project to another one. I have read all available online information and found this cool demo video posted in New MoDisco presentation and demo available online [message #727468]

Now my question is: where can I get the information about using ATL for handling the java metamodel like it is used in the video?

for example, if I want to replace one annotation of a field with another one, how to write the atl script?

...
@Foo
private SomeClass some;

after the transformation:

...
@Bar
private SomeClass some;


any online tutorial or books? Thanks.

best regards
Jing
Re: where can I learn ATL for handling java metamodel [message #783807 is a reply to message #783794] Thu, 26 January 2012 09:05 Go to previous messageGo to next message
Hugo Bruneliere is currently offline Hugo Bruneliere
Messages: 600
Registered: July 2009
Senior Member
Hello Jing,

Thanks for using the MoDisco Java metamodel and corresponding model discoverer. Your feedback is always appreciated.

Answering to your question, there is nothing specific about ATL for handling Java models: the related Java metamodel is simply one metamodel (defined using Ecore) among others.
The demo video you mentioned just shows some transformations that can be quickly implemented in ATL.
Of course, they can be used as base references to implement more elaborated transformations on Java models.

If your problem is about the structure of the Java metamodel, I strongly encourage you to take a look to the MoDisco documentation to have a better overview of what's in there: http://download.eclipse.org/modeling/mdt/modisco/doc/org.eclipse.modisco.doc/
To learn the Java metamodel, the best solution is to automatically discover some Java models (out of Java projects) and to navigate them thanks to the MoDisco Model Browser.

If your problem is about the use of the ATL language itself, then you should post your question on the Modeling M2M forum by putting the [ATL] tag in the subject.
Anyway, just as a quick idea, you could use a simple rule like this one in your transformation:
   rule ModifyTagElement {
	from
		ite : Java!TagElement (
                        ite.refImmediateComposite()
                           .refImmediateComposite()
                           .oclIsTypeOf(Java!FieldDeclaration)
                     and
                        ite.tagName = 'Foo'
		)
	to
		ote : Java!TagElement (
			tagName <- 'Bar'
		)
   }

Best regards,

Hugo


------------------------------------------
Hugo Bruneliere - R&D Engineer
AtlanMod research team (Inria, EMN & LINA)
Ecole des Mines de Nantes
Nantes - France
------------------------------------------
Re: where can I learn ATL for handling java metamodel [message #783846 is a reply to message #783807] Thu, 26 January 2012 10:24 Go to previous messageGo to next message
Jing Ge is currently offline Jing Ge
Messages: 12
Registered: January 2012
Junior Member
Hello Hugo,

thanks for your replay and the suggested rule. I realy appreciate it.

While using ATL for different metamodel, for example java metamodel or kdm metamodel or uml metamodel, different attributes will be used. That is why I ask for how to handle the java metamodel using ATL.

Let's take the rule you suggested as example. I had read the online description of java metamodel. The TagElement is depicted very very shortly under the "comments" topic. In this case, how could I know that the TagElement should be used for my example of replacing the annotation?

The project (5.6M loc!) we want to tansform is far more complicated than the replacing annotation (just as an example) I posted here. Even a task of Proof of concept forces us understanding the use of ATL + java metamodel in details.... Where can I get the information? Any comprehensive tutorial/book for ATL, for java metamodel, and for the combination? Could a book of OCL help us here?

Should we use the programmatical way presented by the junit3->junit4 transformation example?

Sorry for so many questions. I have really no idea where I can get the information....

thank you very much for your help.

best regards
Jing
Re: where can I learn ATL for handling java metamodel [message #784248 is a reply to message #783846] Fri, 27 January 2012 03:47 Go to previous messageGo to next message
Fabien Giquel is currently offline Fabien Giquel
Messages: 138
Registered: July 2009
Senior Member
Hello Jing,

thank you for your interest in MoDisco and related components.
i will just complete Hugo informations about one of your needs : Java metamodel understanding.

There is no advanced documentation, other than the "Java Metamodel" page available in "http://download.eclipse.org/modeling/mdt/modisco/doc/org.eclipse.modisco.doc/".
This page is an introduction to the main concepts. Yes, if you need to understand some precise semantic it will not be suficient. Here are some additional tips to understand the metamodel :

-> An usual tip, when working with models : just browse some existing models. Write some Java code in one class (e.g. with annotations if you deal with), launch the MoDisco Java model dicoverer (contextual menu->Discovery...->Discover Java project), and then browse the resulting model in MoDisco browser to understand the relations between elements. From my point of view that is a good way for understanding one metamodel, often faster than any documentation.
-> You may also browse Java metamodel ecore definition. Use the MoDisco button in toolbar of your Eclipse (tooltip "Open model from EPCkage Registry") -> then select the MoDisco/Java metamodel.
-> "A good tip is also to see the javadoc associated to the Java code DOM implemented by the Eclipse team in the JDT (Java Development Tools) project. The JDT code DOM and the Java metamodel are very similar." -> http://help.eclipse.org/galileo/index.jsp?topic=/org.eclipse.jdt.doc.isv/reference/api/org/eclipse/jdt/core/dom/package-summary.html

Hoping it will help you.
Fabien.


----------------------------------------------------
Fabien GIQUEL
R&D Engineer
Mia-Software
4, rue du Ch√Ęteau de l'Eraudiere
44324 NANTES CEDEX 03
----------------------------------------------------
Re: where can I learn ATL for handling java metamodel [message #784380 is a reply to message #784248] Fri, 27 January 2012 07:49 Go to previous messageGo to next message
Jing Ge is currently offline Jing Ge
Messages: 12
Registered: January 2012
Junior Member
Hello Fabien,

thank you for you reply. I will follow your suggestion and tips and try to understand the java metamodel.

best regards
Jing
Re: where can I learn ATL for handling java metamodel [message #784397 is a reply to message #784380] Fri, 27 January 2012 08:14 Go to previous messageGo to next message
Jing Ge is currently offline Jing Ge
Messages: 12
Registered: January 2012
Junior Member
sorry for this but I need to break the ice of "You cannot use links until you have posted more than 5 messages." Smile
Re: where can I learn ATL for handling java metamodel [message #784398 is a reply to message #784397] Fri, 27 January 2012 08:14 Go to previous messageGo to next message
Jing Ge is currently offline Jing Ge
Messages: 12
Registered: January 2012
Junior Member
...

[Updated on: Fri, 27 January 2012 08:16]

Report message to a moderator

Re: where can I learn ATL for handling java metamodel [message #784399 is a reply to message #784398] Fri, 27 January 2012 08:15 Go to previous messageGo to next message
Jing Ge is currently offline Jing Ge
Messages: 12
Registered: January 2012
Junior Member
...

[Updated on: Fri, 27 January 2012 08:16]

Report message to a moderator

Re: where can I learn ATL for handling java metamodel [message #784400 is a reply to message #784380] Fri, 27 January 2012 08:15 Go to previous messageGo to next message
Jing Ge is currently offline Jing Ge
Messages: 12
Registered: January 2012
Junior Member
Hello Hugo, Hello Fabien,

following the tips given by Fabien, I am trying to use Hugo's ATL rule to do my first java class transformation.

the java class looks like:

import javax.inject.Inject;


public class Person {
	
	@Inject
	private String firstName;
	private String lastName;
	
	public Person(String firstName, String lastName) {
		this.firstName = firstName;
		this.lastName = lastName;
	}

	public String getFirstName() {
		return firstName;
	}

	public String getLastName() {
		return lastName;
	}

}


Here is some piece of the java metamodel:

<?xml version="1.0" encoding="ASCII"?>
<java:Model xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:java="http://www.eclipse.org/MoDisco/Java/0.2.incubation/java" name="getFirsAndLasttName">
  <ownedElements name="com">
    <ownedPackages name="singlename">
      <ownedElements xsi:type="java:ClassDeclaration" originalCompilationUnit="//@compilationUnits.0" name="Person">
        <modifier visibility="public"/>
        <bodyDeclarations xsi:type="java:FieldDeclaration" originalCompilationUnit="//@compilationUnits.0">
          <annotations originalCompilationUnit="//@compilationUnits.0">
            <type type="//@ownedElements.1/@ownedPackages.0/@ownedElements.0"/>
          </annotations>
          <modifier visibility="private"/>
          <type type="//@ownedElements.2/@ownedPackages.0/@ownedElements.0"/>
          <fragments originalCompilationUnit="//@compilationUnits.0" name="firstName" usageInVariableAccess="//@ownedElements.0/@ownedPackages.0/@ownedElements.0/@bodyDeclarations.2/@body/@statements.0/@expression/@leftHandSide/@field //@ownedElements.0/@ownedPackages.0/@ownedElements.0/@bodyDeclarations.3/@body/@statements.0/@expression"/>
        </bodyDeclarations>
        <bodyDeclarations xsi:type="java:FieldDeclaration" originalCompilationUnit="//@compilationUnits.0">
          <modifier visibility="private"/>
          <type type="//@ownedElements.2/@ownedPackages.0/@ownedElements.0"/>
          <fragments originalCompilationUnit="//@compilationUnits.0" name="lastName" usageInVariableAccess="//@ownedElements.0/@ownedPackages.0/@ownedElements.0/@bodyDeclarations.2/@body/@statements.1/@expression/@leftHandSide/@field //@ownedElements.0/@ownedPackages.0/@ownedElements.0/@bodyDeclarations.4/@body/@statements.0/@expression"/>
        </bodyDeclarations>

.......


Now I want to replace the annotation to spring @Autowired.

with the rule Hugo suggested and some others rules that the video inspired me, I build a ATL script like this:

-- atlcomiler atl2010
-- @nsURI Java=http://www.eclipse.org/MoDisco/Java/0.2.incubation/java

module Entity2EntityBean;
create OUT: Java from IN: Java;

rule ModifyTagElement {
	from
		ite: Java!TagElement (
			ite.refImmediateComposite().refImmediateComposite().
					oclIsTypeOf(Java!FieldDeclaration) and ite.tagName = 'Inject'
		)
	to
		ote: Java!TagElement (
			tagName <- 'Autowired'
		)
}

rule Class2Class {
	from
		e: Java!ClassDeclaration
	to
		out: Java!ClassDeclaration (
			name <- e.name
		)
}

rule Field2Field {
	from
		e: Java!FieldDeclaration
	to
		out: Java!FieldDeclaration (
			name <- e.name
		)
}


I know the atl script does not work correctly but I just want to see what will be generated after the transformation. Here is the result:

<?xml version="1.0" encoding="ISO-8859-1"?>
<xmi:XMI xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:java="http://www.eclipse.org/MoDisco/Java/0.2.incubation/java">
  <java:ClassDeclaration name="Person"/>
  <java:ClassDeclaration name="String"/>
  <java:FieldDeclaration/>
  <java:FieldDeclaration/>
</xmi:XMI>


That is not what I expected. It looks like the schema
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

is not used by the generated java metamodel.

What is wrong here? Would you please give me some further suggestions? thanks.

best regards
Jing

[Updated on: Mon, 30 January 2012 03:32]

Report message to a moderator

Re: where can I learn ATL for handling java metamodel [message #786458 is a reply to message #784400] Mon, 30 January 2012 08:08 Go to previous messageGo to next message
Hugo Bruneliere is currently offline Hugo Bruneliere
Messages: 600
Registered: July 2009
Senior Member
Hi Jing,

In the specific case you mentioned here, the transformation is a refactoring one (i.e.; same metamodel as input and output). So don't forget to use the ATL Refining Mode and to declare it properly in the header of the ATL transformation: http://wiki.eclipse.org/ATL/User_Guide_-_The_ATL_Language#ATL_Refining_Mode

module Entity2EntityBean;
create OUT: Java refining IN: Java;

Best regards,

Hugo


------------------------------------------
Hugo Bruneliere - R&D Engineer
AtlanMod research team (Inria, EMN & LINA)
Ecole des Mines de Nantes
Nantes - France
------------------------------------------
Re: where can I learn ATL for handling java metamodel [message #789892 is a reply to message #786458] Fri, 03 February 2012 09:45 Go to previous message
Jing Ge is currently offline Jing Ge
Messages: 12
Registered: January 2012
Junior Member
Hi Hugo,

Thank you. I got it. Smile

best regards
Jing
Previous Topic:How to manipulate java models once parsed JavaDiscoverer
Next Topic:How can I use ATL to modify a java model based on a third party lib
Goto Forum:
  


Current Time: Fri Jul 25 06:38:49 EDT 2014

Powered by FUDForum. Page generated in 0.01978 seconds