Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » [Xpand/Xtend] Type problem with packages
[Xpand/Xtend] Type problem with packages [message #631653] Fri, 08 October 2010 11:45 Go to next message
Albert M is currently offline Albert MFriend
Messages: 1
Registered: October 2010
Junior Member
Hey everybody,

I really like Xpand and Xtend as I can write very fast transformations with them. I'm using the newest version 1.0.1 under Eclipse 3.6.1. I have a really large metamodel (mm.ecore) with a lot of packages and have the following root type:

rootPackage::packageA::package1::first::RootType


I first deserialize my model and get the root object of it and then want to use XpandFacade to invoke my Xpand template:

public void generate(RootType rootObject) {
	  OutputImpl output = new OutputImpl();
	  Outlet outlet = new Outlet("D:\\src-gen");
	  output.addOutlet(outlet);
	  XpandExecutionContextImpl context = new XpandExecutionContextImpl(output, null);

	  // register meta model
	  EmfMetaModel mm = new EmfMetaModel();
	  mm.setMetaModelFile("mm.ecore"); // meta model is on build path
	  context.registerMetaModel(mm);

	  // invoke Xpand Template
	  XpandFacade facade = XpandFacade.create(context);
	  facade.evaluate("template::generate", rootObject); //template is on build path
}


This is my template "template.xpt":

«DEFINE generate FOR rootPackage::packageA::package1::first::RootType»
«REM» do something here «ENDREM»
«ENDDEFINE»


Unfortunately I get the following expection:

Message: No Definition template::generate for package1::first::RootType could be found!


Now I am a little bit confused, because my rootObject has the type "rootPackage::packageA::package1::first::RootType". It seems that Xpand's type system cuts the first two package names.

Debugging leads to the conclusion that the typesystem recursively evaluates the type of the rootObject and stops if it does not found an eContainer.

Changing the template above to

«DEFINE generate FOR package1::first::RootType»
«REM» do something here «ENDREM»
«ENDDEFINE»


doesn't solve the problem.

Using Xtend with XtendFacade is also not possible Sad

What is the problem?

[Updated on: Fri, 08 October 2010 11:47]

Report message to a moderator

Re: [Xpand/Xtend] Type problem with packages [message #632416 is a reply to message #631653] Tue, 12 October 2010 20:08 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

there are some things mixed up in your sample. to work on a concrete example i built my own ecore

<?xml version="1.0" encoding="UTF-8"?>
<ecore:EPackage xmi:version="2.0"
    xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" name="a"
    nsURI="a" nsPrefix="a">
  <eSubpackages name="b" nsURI="b" nsPrefix="b">
    <eSubpackages name="c" nsURI="c" nsPrefix="c">
      <eClassifiers xsi:type="ecore:EClass" name="D"/>
    </eSubpackages>
  </eSubpackages>
</ecore:EPackage>


In your Generator class you mix up Static and dynamic emf
(there should be a warning / error on the console). i chan ged it to

	public static void main(String[] args) {
		 OutputImpl output = new OutputImpl();
		  Outlet outlet = new Outlet("D:\\src-gen");
		  output.addOutlet(outlet);
		  XpandExecutionContextImpl context = new XpandExecutionContextImpl(output, null);

		  // register meta model
		  EmfMetaModel mm = new EmfMetaModel();
		  mm.setMetaModelPackage(CPackage.class.getName());// meta model is on build path
		  context.registerMetaModel(mm);

		  // invoke Xpand Template
		  XpandFacade facade = XpandFacade.create(context);
		  facade.evaluate("test::test", CFactory.eINSTANCE.createD()); //template is on build path
	}


but you have to change the template to use only one package too,

«DEFINE test FOR c::D»
«FILE "test.txt"»
«ENDFILE»
«ENDDEFINE»


an easy possibility to use full package names is to switch to the javabeans metamodel

	public static void main(String[] args) {
		 OutputImpl output = new OutputImpl();
		  Outlet outlet = new Outlet("D:\\src-gen");
		  output.addOutlet(outlet);
		  XpandExecutionContextImpl context = new XpandExecutionContextImpl(output, null);

		  // register meta model
		  context.registerMetaModel(new JavaBeansMetaModel());

		  // invoke Xpand Template
		  XpandFacade facade = XpandFacade.create(context);
		  facade.evaluate("test::test", CFactory.eINSTANCE.createD()); //template is on build path
	}


this should be not problem since you are using static emf / emf java classes.

~Christian



Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:[Acceleo] In search of a clean solution for namespace/block generation
Next Topic:[Xpand] Debugging
Goto Forum:
  


Current Time: Fri Apr 26 07:27:15 GMT 2024

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

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

Back to the top