[XPand / XText] Calling XPand template Generation from eclipse Plugin Event Handler
I wish to generate output calling an Xpand template from within a Plugin Event Handler using an Xtext model as input. Two approaches have been tried using XpandFacade and org.eclipse.emf.mwe.internal.core.Workflow on the Xtext "Greetings" example project but errors are produced. Below are the errors and pertinet pieces of code. The model and MetaModel objects were interrogated and found to be correctly formed.
Any assistance in solving this problem is very much appreciated,
Regards
John Murphy
EXPAND FACADE APPROACH
The XpandFacade approach produced the error:
Error: |
"EvaluationException : No Definition templates::Template::main FOREACH greetings for myDsl::Model could be found!
Internal error : element was null
at org.eclipse.xpand2.XpandFacade.evaluate2(XpandFacade.java:59 ) "
|
// Model instance
Resource resource = rs.getResource(URI.createURI(inputModel), true);
org.xtext.example.mydsl.myDsl.Model model = (Model) resource.getContents().get(0);
// Meta model
EmfMetaModel metaModel = new EmfMetaModel(MyDslPackage.eINSTANCE);
// create execution context
XpandExecutionContextImpl execCtx = new XpandExecutionContextImpl(output, null, globalVarsMap, null, null);
execCtx.registerMetaModel(metaModel);
// generate
XpandFacade facade = XpandFacade.create(execCtx);
String expand = "templates::Template::main FOREACH greetings";
facade.evaluate(expand, model);
WORKFLOW APPROACH
The WorkFlow approach produces the error:
Error: |
"org.eclipse.emf.mwe.core.WorkflowInterruptedException: Collection expected!
at org.eclipse.xtend.expression.AbstractExpressionsUsingWorkflo wComponent.invokeInternal(AbstractExpressionsUsingWorkflowCo mponent.java:247) "
|
// Get the Model path
String inputModel = extractSelection(selection).getFullPath().toString();
// Workflow
Workflow workflow = new Workflow();
// EMF reader
org.eclipse.emf.mwe.utils.Reader emfReader = new Reader();
emfReader.setUri(inputModel);
emfReader.setModelSlot("greetings");
// Meta model
EmfMetaModel metaModel = new EmfMetaModel(MyDslPackage.eINSTANCE);
// Generator
Generator generator = new Generator();
generator.addMetaModel(metaModel);
generator.addOutlet(outlet);
generator.setExpand("templates::Template::main FOREACH greetings");
// workflow
WorkflowContext wfx = new WorkflowContextDefaultImpl();
Issues issues = new org.eclipse.emf.mwe.core.issues.IssuesImpl();
NullProgressMonitor monitor = new NullProgressMonitor();
workflow.addComponent(emfReader);
workflow.addComponent(generator);
workflow.invoke(wfx, monitor, issues);
[Updated on: Wed, 18 August 2010 04:12]
Report message to a moderator