|
|
|
|
|
Re: Using xpand templates in xtext 2 [message #1059191 is a reply to message #1059187] |
Fri, 17 May 2013 08:07 |
|
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 #1059196 is a reply to message #1059194] |
Fri, 17 May 2013 08:33 |
|
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 |
Kevin SERIN 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 #1059686 is a reply to message #1059047] |
Tue, 21 May 2013 08:29 |
Kevin SERIN 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
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.04142 seconds