|
|
Re: [XPand] Invoke XPand programmatically: how templates are resolved? [message #641807 is a reply to message #641727] |
Sun, 28 November 2010 10:26 ![Go to previous message Go to previous message](theme/Solstice/images/up.png) ![Go to next message Go to next message](theme/Solstice/images/down.png) |
|
Thank you Christian, also using XpandFacade I keep having the same problem: the template definition is not found. I thought Xpand looked into the classpath for the templates (and my template is accessible through classpath) but it is not found. I got this error:
EvaluationException : No Definition templates::Template::formatParser for positionalParserDsl::Format could be found!
Internal error : element was null
at org.eclipse.xpand2.XpandFacade.evaluate2(XpandFacade.java:59)
at org.eclipse.xpand2.XpandFacade.evaluate(XpandFacade.java:43)
at it.polito.CodeGenerator.generate(CodeGenerator.java:75)
at it.polito.CodeGeneratorTest.testGenerate(CodeGeneratorTest.java:15)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:76)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:49)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
I invoke XpandFacade in this way:
public void generate(Format format){
Output output = new MemoryOutput();
XpandExecutionContextImpl execCtx = new XpandExecutionContextImpl(output, null);
execCtx.registerMetaModel(new EmfRegistryMetaModel());
XpandFacade facade = XpandFacade.create(execCtx);
facade.evaluate("templates::Template::formatParser", format);
}
website: http://www.federico-tomassetti.it
|
|
|
Re: [XPand] Invoke XPand programmatically: how templates are resolved? [message #641810 is a reply to message #641725] |
Sun, 28 November 2010 11:09 ![Go to previous message Go to previous message](theme/Solstice/images/up.png) ![Go to next message Go to next message](theme/Solstice/images/down.png) |
Stephan Krusche![Friend of Eclipse Friend](/donate/web-api/friends_decorator.php?email=stephan.krusche%40berner-mattner.com) Messages: 18 Registered: August 2010 Location: Munich |
Junior Member |
|
|
You have 3 potential errors:
1) Does your template definition look like?
«DEFINE formatParser FOR Format»
...
«ENDDEFINE»
2) If the template is in a source folder (that meas the folder is on the build path) then you must write:
facade.evaluate("formatParser", format);
3) You only register the standard EmfRegistryMetamodel. Where is your type (class or interface) Format defined?
Xpand needs to know this. If you have created your own metamodel you must register either the whole ecore file or each package (e.g. positionalParserDsl) that includes types you use in your code generation.
This can e.g. be done using the following code (assuming that positionParserDsl is your package):
EmfMetaModel metamodel = new EmfMetaModel();
String packageName = positionalParserDsl.class.getName();
metamodel.setMetaModelPackage(packageName);
execCtx.registerMetaModel(metamodel);
[Updated on: Sun, 28 November 2010 15:50] Report message to a moderator
|
|
|
|
Powered by
FUDForum. Page generated in 0.03832 seconds