Hello everybody,
I created a simple Xtext project and exported its three generated projects as plugins. Then, I created a Java project which adds the Xtext Nature of my plugin.
I'm able to use Xtext programmatically after loading the model this way:
private Model loadModel() {
new org.eclipse.emf.mwe.utils.StandaloneSetup().setPlatformUri("../");
Injector injector = new TGStandaloneSetup().createInjectorAndDoEMFRegistration();
XtextResourceSet resourceSet = injector.getInstance(XtextResourceSet.class);
resourceSet.addLoadOption(XtextResource.OPTION_RESOLVE_ALL, Boolean.TRUE);
Resource resource = resourceSet.getResource(
URI.createURI("platform:/resource/JavaX/src/example.tg"), true);
return (Model) resource.getContents().get(0);
Now, I would like to generate code from my model using XpandFacade. This is my code for that:
Model model = loadModel();
// XPand
String outputFolder = "output";
OutputImpl output = new OutputImpl();
Outlet outlet = new Outlet(outputFolder);
outlet.setOverwrite(true);
output.addOutlet(outlet);
EmfMetaModel metaModel = new EmfMetaModel(TGPackage.eINSTANCE);
XpandExecutionContextImpl executionContext = new XpandExecutionContextImpl(output, null);
executionContext.registerMetaModel(metaModel);
XpandFacade facade = XpandFacade.create(executionContext);
facade.evaluate("templates::Template::main", model.getTables().get(0));
but Im getting the next exception
Exception in thread "main" EvaluationException : No Definition templates::Template::main for tG::Table could be found!
Internal error : element was null
That template is in the package src.templates of the org.xtext.example.tg.generator project (exported as a plugin).
I do not know if the template should be there. The other thing is that while I am able to import the org.xtext.example.tg project classes, I can't do that with org.xtext.example.tg.generator classes.
I would appreciate any help.
Thank you very much.