|
Re: where can I learn ATL for handling java metamodel [message #783807 is a reply to message #783794] |
Thu, 26 January 2012 14:05 |
Hugo Bruneliere Messages: 674 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, PhD
NaoMod team (IMT Atlantique & LS2N-CNRS)
Nantes - France
--------------------------------------------------------
|
|
|
|
|
|
|
|
|
Re: where can I learn ATL for handling java metamodel [message #784400 is a reply to message #784380] |
Fri, 27 January 2012 13: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 08:32] Report message to a moderator
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.05762 seconds