Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » [XPand / XText] Calling XPand template Generation from eclipse Plugin Event Handler(Generate output calling an Xpand template from within a eclipse Plugin Event Handler using an Xtext model as input)
[XPand / XText] Calling XPand template Generation from eclipse Plugin Event Handler [message #553566] Wed, 18 August 2010 04:08 Go to next message
jemurphy  is currently offline jemurphy Friend
Messages: 4
Registered: August 2010
Junior Member
[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

Re: [XPand / XText] Calling XPand template Generation from eclipse Plugin Event Handler [message #553589 is a reply to message #553566] Wed, 18 August 2010 06:38 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14722
Registered: July 2009
Senior Member
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


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Day Job: https://www.everest-systems.com
Previous Topic:oAW Recipies
Next Topic:[Xtend]: definition of recursive extensions
Goto Forum:
  


Current Time: Thu Oct 10 19:14:18 GMT 2024

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

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

Back to the top