[XPand / XText] Calling XPand template Generation from eclipse Plugin Event Handler [message #553566] |
Wed, 18 August 2010 00:08  |
Eclipse User |
|
|
|
[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 00:12] by Moderator
|
|
|
Re: [XPand / XText] Calling XPand template Generation from eclipse Plugin Event Handler [message #553589 is a reply to message #553566] |
Wed, 18 August 2010 02:38  |
Eclipse User |
|
|
|
Hello John,
in both cases you get error messages that should give you a hint what you are doing wrong.
(1) XpandFacade expects as first Parameter the name of the template to be called. It should templates::Template::main
but this would work neither when you call it with a Model and not a Greeting - so you have to iterate over the models greetings and pass each greeting to the template or have to introduce a new define for Model.
(2) Here is the same Problem. You use org.eclipse.emf.mwe.utils.Reader and not org.eclipse.xtext.mwe.Reader thus in the model slot there is not a List of greetings that allows you to call templates::Template::main FOREACH greetings so change here the Reader or the <expand /> tag and introduce a defintion for model.
~Christian
|
|
|
Powered by
FUDForum. Page generated in 0.26339 seconds