Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Using xpand templates in xtext 2
Using xpand templates in xtext 2 [message #1059047] Thu, 16 May 2013 12:29 Go to next message
Kevin SERIN is currently offline Kevin SERINFriend
Messages: 19
Registered: May 2013
Junior Member
Hi,

I'm migrating an old xtext project to xtext. For the code generation, this old project use xpand template (.xpt) and I would like to know if it's possible to use them in xtext 2 ? Or maybe I should use xtend instead ?

Regards.

[Updated on: Thu, 16 May 2013 12:35]

Report message to a moderator

Re: Using xpand templates in xtext 2 [message #1059049 is a reply to message #1059047] Thu, 16 May 2013 12:33 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Yes it is both possible.

~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Using xpand templates in xtext 2 [message #1059051 is a reply to message #1059049] Thu, 16 May 2013 12:38 Go to previous messageGo to next message
Kevin SERIN is currently offline Kevin SERINFriend
Messages: 19
Registered: May 2013
Junior Member
Okay and what is the best way to re-use xpand templates ? (Sorry but i'm beginning with xtext)
Re: Using xpand templates in xtext 2 [message #1059057 is a reply to message #1059051] Thu, 16 May 2013 13:04 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

it should be 1:1 (besides you have to switch to the javabeans metamodel)


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Using xpand templates in xtext 2 [message #1059187 is a reply to message #1059057] Fri, 17 May 2013 07:59 Go to previous messageGo to next message
Kevin SERIN is currently offline Kevin SERINFriend
Messages: 19
Registered: May 2013
Junior Member
I don't find what to do Sad I tried to use XpadnFacade.create(XpandExecutionContext) in the doGenerate-) method of MyDslGenerator.xtend but I need the xpandExecutionContext and I don't success to get it.

I also tried to create my own GeneratorFragment and override the generate methode like that:
public class MyGeneratorFragment extends GeneratorFragment {
	@Override
	public void generate(Grammar grammar, XpandExecutionContext ctx) {
		System.out.println("ok");
		XpandFacade
		.create(ctx)
		.evaluate(...);
	}
}

// generator API
    		fragment = MyGeneratorFragment {}
    		//fragment = generator.GeneratorFragment auto-inject {}

But the generate() method is never called Sad
Re: Using xpand templates in xtext 2 [message #1059191 is a reply to message #1059187] Fri, 17 May 2013 08:07 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

now we are talking about a different thing. (i thought you are standalone/build the stuf on your own.)
you want to hook into xtends builder api (that calls the igenerator) right?
then you should first have a look at org.eclipse.xtext.builder.BuilderParticipant
that calls the IGenerator.

btw the fragment generates stuff out of the grammar not at runtime.

so why dont you create the xpandexecutioncontext youself,
feed it with the given resource (or its content(s))
and call xpandfacade with that?


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Using xpand templates in xtext 2 [message #1059194 is a reply to message #1059191] Fri, 17 May 2013 08:26 Go to previous messageGo to next message
Kevin SERIN is currently offline Kevin SERINFriend
Messages: 19
Registered: May 2013
Junior Member
For creating my own xpandececutioncontext i saw the javadoc ( http://download.eclipse.org/modeling/m2t/xpand/javadoc/0.7.0/org/eclipse/xpand2/XpandExecutionContextImpl.html ) but custructors' documentation is not really explicit.
Moreover, i'm doing a migration, and I already have a class which extends IXTextBuilderParticipant (I don't really understand everything in this code ...) but I don't know how to (re)use this class in my xtext project. I think this class already do almost all job I need (I hope^^)
Re: Using xpand templates in xtext 2 [message #1059196 is a reply to message #1059194] Fri, 17 May 2013 08:33 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

Have a look at yourdsluimodule respectively its plugin.xml
there you can find stuff like

<extension
point="org.eclipse.xtext.builder.participant">
<participant
class="org.xtext.example.mydsl.ui.MyDslExecutableExtensionFactory:org.eclipse.xtext.builder.IXtextBuilderParticipant">
</participant>
</extension>

thus the binding for IXtextBuilderParticipant will be used.
and this looks like

@ImplementedBy(BuilderParticipant.class)
public interface IXtextBuilderParticipant

so far =>

simply adding a method

public Class<? extends IXtextBuilderParticipant> bindIXtextBuilderParticipant() {
return Whateever.class;
}

to the ui module should do the trick


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Using xpand templates in xtext 2 [message #1059223 is a reply to message #1059196] Fri, 17 May 2013 11:32 Go to previous messageGo to next message
Kevin SERIN is currently offline Kevin SERINFriend
Messages: 19
Registered: May 2013
Junior Member
Thanks a lot.

Maybe I do something wrong. I added the method bindITextBuilderParticipant() in MyDslUiModule class. The I started the new runtime eclipse and I tried to create a new project with a new file.mydsl. But when I create the file, the wizard is blocked but the file seems created. But he has no name and when I try to close it, a null pointer exception occur.
I put a System.out.println() in the method build() of my IXtextBuilderParticipant but the method doesn't seem to be called.

EDIT: it seems to come from the code of the Generator. I'm isolating the problem.

[Updated on: Fri, 17 May 2013 11:44]

Report message to a moderator

Re: Using xpand templates in xtext 2 [message #1059261 is a reply to message #1059223] Fri, 17 May 2013 11:44 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi please try it with a brand new Xtext project. If that does not
work please share something reproduceable

--
Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to xtext at itemis dot de


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Using xpand templates in xtext 2 [message #1059686 is a reply to message #1059047] Tue, 21 May 2013 08:29 Go to previous messageGo to next message
Kevin SERIN is currently offline Kevin SERINFriend
Messages: 19
Registered: May 2013
Junior Member
I success to isolate my problem:

1.Create a new xtext project with the "Hello World" grammar and generate xtext artifacts.

2. In the project org.xtext.example.mydsl.ui create the package org.xtext.example.mydsl.ui.generator and the class Generator.java with this code:
package org.xtext.example.mydsl.ui.generator;

import java.util.HashMap;
import java.util.Map;

import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.xpand2.XpandExecutionContextImpl;
import org.eclipse.xpand2.output.Outlet;
import org.eclipse.xpand2.output.OutputImpl;
import org.eclipse.xtend.expression.Variable;
import org.eclipse.xtext.builder.IXtextBuilderParticipant;
import org.eclipse.xtend.type.impl.java.JavaBeansMetaModel;

public class Generator implements IXtextBuilderParticipant {

	@Override
	public void build(IBuildContext context, IProgressMonitor monitor)
			throws CoreException {
		System.out.println("ok");
		
		OutputImpl output = new OutputImpl();
		Outlet outlet = new Outlet();
		output.addOutlet(outlet);
		Map<String, Variable> vars = new HashMap<>();
		XpandExecutionContextImpl ctx = new XpandExecutionContextImpl(output,
				null, vars, null, null);
		ctx.registerMetaModel(new JavaBeansMetaModel());
	}

}


3. In MyDslUiModule.java override the method bindIXtextBuilderParticipant:
@Override
	public Class<? extends IXtextBuilderParticipant> bindIXtextBuilderParticipant() {
		return org.xtext.example.mydsl.ui.generator.Generator.class;
	}


4. Then, run and create a new java project, and a new file 'test.mydsl" in this project. And at this time, the following error occur:
java.lang.ClassNotFoundException: org.eclipse.xtend.typesystem.MetaModel
Re: Using xpand templates in xtext 2 [message #1059690 is a reply to message #1059686] Tue, 21 May 2013 08:49 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi looks like your class path is insufficient

--
Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to xtext at itemis dot de


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Using xpand templates in xtext 2 [message #1059729 is a reply to message #1059047] Tue, 21 May 2013 12:42 Go to previous message
Kevin SERIN is currently offline Kevin SERINFriend
Messages: 19
Registered: May 2013
Junior Member
Ouups :$
Thanks !
Previous Topic:Change EMFResource
Next Topic:Debug support for DSL in Xtext
Goto Forum:
  


Current Time: Thu Apr 18 14:14:01 GMT 2024

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

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

Back to the top