Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » generate code out of metamodel(.ecore file ) using xpandfacade
generate code out of metamodel(.ecore file ) using xpandfacade [message #1223536] Mon, 23 December 2013 17:53 Go to next message
Adnan AL-SOSWA is currently offline Adnan AL-SOSWAFriend
Messages: 41
Registered: May 2010
Member
Hi all ,

I am creating plugin that allow the user to generate code out of .ecore file using xpandfacade .

I have probelm of specifying the .ecore file in evaluate function

for example
xpandFacade.evaluate("templates::Template::main", ??????);



i tried the metamodel path but it did not work ?

I appreciate any help ?
Re: generate code out of metamodel(.ecore file ) using xpandfacade [message #1223597 is a reply to message #1223536] Mon, 23 December 2013 22:28 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14588
Registered: July 2009
Senior Member
Hi you have to read the model with emf means yourself

--
Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to xtext at itemis dot de


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de

[Updated on: Tue, 24 December 2013 23:09]

Report message to a moderator

Re: generate code out of metamodel(.ecore file ) using xpandfacade [message #1225069 is a reply to message #1223597] Sat, 28 December 2013 16:50 Go to previous messageGo to next message
Adnan AL-SOSWA is currently offline Adnan AL-SOSWAFriend
Messages: 41
Registered: May 2010
Member
Thanks christian ,

I tried your suggestion but I am not sure if I understood completely
If you please could you explain for me the differenc in the registeration of metamodel
.ecore file and instance of it .xmi file as I want to generate code from the both
here is my code of regiseration ,
  
	    URI uri = URI.createURI("file:///D:/xpand/xpand/my.generator.project/src/metamodel/metamodel.ecore", true);
	    Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("ecore", new EcoreResourceFactoryImpl());
	    ResourceSet rs = new ResourceSetImpl();
	 // enable extended metadata
	    final ExtendedMetaData extendedMetaData = new BasicExtendedMetaData(rs.getPackageRegistry());
	    rs.getLoadOptions().put(XMLResource.OPTION_EXTENDED_META_DATA,extendedMetaData);
	    EPackage p = null ;
	    Resource r = rs.getResource(uri, true);
	    Object eObject =  r.getContents().get(0);
	    if (eObject instanceof EPackage) {
	      p = (EPackage)eObject;
	     rs.getPackageRegistry().put(p.getNsURI(), p);
	     }
              

                MyOutPutImpl out = new MyOutPutImpl();
		MyOutlet outlet = new MyOutlet("my-gen");
		out.addOutlet( outlet);
		
		ProtectedRegionResolver prs = new ProtectedRegionResolverImpl();
		XpandExecutionContext execCtx = new XpandExecutionContextImpl(out, prs);
                XpandFacade.create(execCtx).evaluate("template::Template::main", p);


and here my template for generating code from metamodel.ecore
               «DEFINE main FOR ecore::EPackage»
               «EXPAND javaClass FOREACH eClassifiers.typeSelect(ecore::EClass)»
               «ENDDEFINE»

               «DEFINE javaClass FOR ecore::EClass»

               public class «name» {
                                    }
  
              «ENDDEFINE»


When I run the project I got this exception
Exception in thread "main" EvaluationException : No Definition template::Template::main for Object could be found!
	                       Internal error : element was null

could you please guide me what I am doing wrong ?
thanks in advance .

[Updated on: Mon, 30 December 2013 20:49]

Report message to a moderator

Re: generate code out of metamodel(.ecore file ) using xpandfacade [message #1705591 is a reply to message #1225069] Mon, 17 August 2015 16:45 Go to previous message
ngoc tho huynh is currently offline ngoc tho huynhFriend
Messages: 2
Registered: October 2014
Junior Member
I have the same problem but it has an error:
Exception in thread "main" EvaluationException : Couldn't find extension 'getComponentList()'!
template::Template.xpt[172,18] on line 9 '.getComponentList()'


In the java class, i use

String templatePath = "template::Template::definition";
XpandExecutionContextImpl execCtx = new
XpandExecutionContextImpl(out, null);
execCtx.registerMetaModel(new EmfRegistryMetaModel());
XpandFacade facade = XpandFacade.create(execCtx);
facade.evaluate(templatePath, definition, params);

in Template.xpt, i declare:

«IMPORT fractal»
«EXTENSION template::Extensions»
«DEFINE definition FOR Definition»
//call template
«EXPAND component FOREACH getComponentList()»
«ENDDEFINE»

and in the extension file (Extensions.ext), i declare:

import fractal;
Definition definition1(Component this) :
eContainer;
List[Component] getComponentList(Definition this) :
subComponents.typeSelect(Component);

Could you help me please ?

[Updated on: Mon, 17 August 2015 21:25]

Report message to a moderator

Previous Topic:[Xtext] updating/writing resource descriptions chunk x of xxx
Next Topic:html Export
Goto Forum:
  


Current Time: Fri Dec 01 13:43:03 GMT 2023

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

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

Back to the top