Skip to main content

Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » [Xpand] Using Xpand programmatically
[Xpand] Using Xpand programmatically [message #638299] Wed, 10 November 2010 18:17 Go to next message
Rafael Angarita is currently offline Rafael AngaritaFriend
Messages: 94
Registered: November 2010
Hello, I exported my Xtext projects as pluging and created a new Java project and added the Xtext Nature, so I can write code using the language I defined. Now, I would like to generate source code using the template I defined in my Xpand project.

Unfortunally, I have not had much success in finding documenation and tutorials about using Xpand programmatically, so I am working almost only with the information I have found in other posts. Therefore I am a little bit lost.

In my Java project I created a class with the following code:
        OutputImpl output = new OutputImpl();
        Outlet outlet = new Outlet("xpandOutput");
        Outlet outputOutlet = new Outlet("testOutput");
       // create an execution context
       XpandExecutionContextImpl execCtx = new 
       XpandExecutionContextImpl(output, null);
       execCtx.registerMetaModel(new JavaBeansMetaModel());

      org.eclipse.xtend.expression.Resource template = 
		execCtx.getResourceManager().loadResource("myTemplate", "xpt");
		 execCtx = (XpandExecutionContextImpl)(execCtx.cloneWithResource(template));
		 XpandFacade facade = XpandFacade.create(execCtx);
		String templateName = "expSpecification";

		List<Object> params = new ArrayList<Object>();
		facade.evaluate2(templateName, targetObject, params);

One of the problems I have is that I am not sure about what the targetObject should be. Also, I don't know in which step I am suppossed to tell Xpand about the file from which the code would be generated.

I would appreciate if someone could help me or show me any tutorial or documentation about this specific proccess.

Thank you very much.
Re: [Xpand] Using Xpand programmatically [message #638307 is a reply to message #638299] Wed, 10 November 2010 18:59 Go to previous message
Darius Jockel is currently offline Darius JockelFriend
Messages: 63
Registered: July 2009

you are right, there is no documentation how to use the XpandFacade,
but take a look at this chapter:
5.8. Calling Extensions From Java


PS: there is another Xpand programmatically thread: 246#msg_638246
Previous Topic:How to invoke Xpand template into a Java-code????
Next Topic:[Xpand] Code Generation Architecture advise
Goto Forum:

Current Time: Thu Feb 29 23:13:18 GMT 2024

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

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

Back to the top