Skip to main content



      Home
Home » Modeling » M2T (model-to-text transformation) » [Acceleo] How to get types for xcore meta-model
[Acceleo] How to get types for xcore meta-model [message #1378574] Sat, 24 May 2014 05:36 Go to next message
Eclipse UserFriend
Hi

I am using xcore for my meta-model, and am trying to use acceleo to generate classes.

Below is my acceleo template.

Here is a snippet from my xcore model:
class Role{
	String name
}


My current acceleo template- which is obviously incorrect - is generating:
public class Role{

	private org.eclipse.emf.ecore.xcore.XAttribute name;
     public Name getName getName() {
       return this.name;
}


How can I do find the type - in this case String - in the acceleo template?


[comment encoding = UTF-8 /]
[**
 * The documentation of the module generate.
 */]
[module generate('http://www.eclipse.org/emf/2011/Xcore')]


[**
 * The documentation of the template generateElement.
 * @param aXClass
 */]
[template public generateElement(aXClass : XClass)]
[comment @main/]
[file (aXClass.name.concat('.java'), false, 'UTF-8')]
public class [aXClass.name.toUpperFirst()/]{

[for (m: XMember | aXClass.members) separator('\n')]
	private [m.type.eContainer().eClass().instanceTypeName /] [m.name.toLowerCase()/];
[/for]
[for (p: XMember | aXClass.members) separator('\n')]
     public [p.name.toString().toUpperFirst() /] get[p.name.toUpperFirst()/] get[p.name.toUpperFirst()/]() {
       return this.[p.name/];
     }
[/for]
[for (o: XOperation | aXClass.) separator('\n')]
     public [o.type.name/] [o.name/]() {
       // TODO should be implemented
     }
[/for][/comment]
   [comment]
 
   [for (p: Property | aClass.attribute) separator('\n')]
     public [p.type.name/] get[p.name.toUpperFirst()/]() {
       return this.[p.name/];
     }
   [/for]
 
   [for (o: Operation | aClass.ownedOperation) separator('\n')]
     public [o.type.name/] [o.name/]() {
       // TODO should be implemented
     }
   [/for][/comment]
   }

[/file]
[/template]

Re: [Acceleo] How to get types for xcore meta-model [message #1384665 is a reply to message #1378574] Fri, 30 May 2014 03:14 Go to previous messageGo to next message
Eclipse UserFriend
Hi

Since no one who understands Xcore is answering....

Doing a transformation on Xcore types seems really wierd since you shut
yourself off from many other modeling technologies. Convert the Xcore to
Ecore and transform that. There are many examples of transformations on
Ecopre.

Regards

Ed Willink


On 24/05/2014 10:36, Anton Hughes wrote:
> Hi
>
> I am using xcore for my meta-model, and am trying to use acceleo to
> generate classes.
>
> Below is my acceleo template.
>
> Here is a snippet from my xcore model:
>
> class Role{
> String name
> }
>
>
> My current acceleo template- which is obviously incorrect - is
> generating:
> public class Role{
>
> private org.eclipse.emf.ecore.xcore.XAttribute name;
> public Name getName getName() {
> return this.name;
> }
>
> How can I do find the type - in this case String - in the acceleo
> template?
>
>
>
> [comment encoding = UTF-8 /]
> [**
> * The documentation of the module generate.
> */]
> [module generate('http://www.eclipse.org/emf/2011/Xcore')]
>
>
> [**
> * The documentation of the template generateElement.
> * @param aXClass
> */]
> [template public generateElement(aXClass : XClass)]
> [comment @main/]
> [file (aXClass.name.concat('.java'), false, 'UTF-8')]
> public class [aXClass.name.toUpperFirst()/]{
>
> [for (m: XMember | aXClass.members) separator('\n')]
> private [m.type.eContainer().eClass().instanceTypeName /]
> [m.name.toLowerCase()/];
> [/for]
> [for (p: XMember | aXClass.members) separator('\n')]
> public [p.name.toString().toUpperFirst() /]
> get[p.name.toUpperFirst()/] get[p.name.toUpperFirst()/]() {
> return this.[p.name/];
> }
> [/for]
> [for (o: XOperation | aXClass.) separator('\n')]
> public [o.type.name/] [o.name/]() {
> // TODO should be implemented
> }
> [/for][/comment]
>
>
> [for (p: Property | aClass.attribute) separator('\n')]
> public [p.type.name/] get[p.name.toUpperFirst()/]() {
> return this.[p.name/];
> }
> [/for]
>
> [for (o: Operation | aClass.ownedOperation) separator('\n')]
> public [o.type.name/] [o.name/]() {
> // TODO should be implemented
> }
> [/for][/comment]
> }
>
> [/file]
> [/template]
>
>
Re: [Acceleo] How to get types for xcore meta-model [message #1385865 is a reply to message #1384665] Wed, 11 June 2014 14:29 Go to previous messageGo to next message
Eclipse UserFriend
Hi Ed

I think your suggestion is very sensible.

Can you advise on how convert from xcore to ecore?

Thanks and kind regards
Re: [Acceleo] How to get types for xcore meta-model [message #1385867 is a reply to message #1385865] Wed, 11 June 2014 14:46 Go to previous message
Eclipse UserFriend
Oh, found it.

FYI - when creating a genmodel from xcore, the ecore file is also produced.
Previous Topic:C/C++ code generator
Next Topic:[Acceleo] Format date in acceleo
Goto Forum:
  


Current Time: Sat Nov 08 06:16:39 EST 2025

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

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

Back to the top