| where can I learn ATL for handling java metamodel [message #783794] |
Thu, 26 January 2012 08:29  |
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   |
Hugo Bruneliere Messages: 462 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 #784248 is a reply to message #783846] |
Fri, 27 January 2012 03:47   |
Fabien Giquel Messages: 134 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 #784400 is a reply to message #784380] |
Fri, 27 January 2012 08:15   |
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
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.02161 seconds