configure multiple generators with XText 2.9 [message #1722300] |
Wed, 03 February 2016 18:00  |
Eclipse User |
|
|
|
Hi,
XText is really nice and exactly what I need. but after reading the docs and looking for info on the web, I still don't understand how I should configure my project, the mwe2, to produce multiple files from the same grammar.
I have modified the sample that uses the JvmModelInferrer to my needs, but now I need to add other generators to the workflow.
How is it done ?
Thanks,
Herve
|
|
|
|
|
Re: configure multiple generators with XText 2.9 [message #1722455 is a reply to message #1722300] |
Thu, 04 February 2016 18:02   |
Eclipse User |
|
|
|
Thanks for your answer,
I followed the steps about the JVM language tutorial.
I get the xtext, the mwe2 and a MyDomainJvmModelInferrer that extends AbstractModelInferrer and a MyDomainGenerator that extends an AbstractGenerator.
I put the code that generates the java class in the MyDomainJvmModelInferrer, and it works.
But I don't see a reference of this class any where in the code, I don't understand how it is used by the workflow. Neither do I see a reference to the MyDomainGenerator.
Given a .mydomain source file I want to generate a java class and other related files, like a schema, etc...
Maybe a fragment is what I need, but I can't get how to use it, for ex, just to produce a .txt version of my source next to the .java.
A pointer to a simple example, or a simple source code would be appreciated
Herve
|
|
|
|
|
Re: configure multiple generators with XText 2.9 [message #1782110 is a reply to message #1722300] |
Sun, 18 February 2018 06:11   |
Eclipse User |
|
|
|
Hello, So i followed your conversation and got a similiar problem.
So I got an old IGenerator and now i want to add the possibility to do something with an new IGenerator as well.
In my case I want to do something with the generated class of my jvmModelInferrer.
If i got your example right, I added a new RootGenerator and injected my old Generator and the jvmModelGenerator.
But how can i add a mapping or something, which gives me the possibility to get the reference to the gernated class of my jvmModelinferrer and use it in my old gernator?
This is my Workflow component:
component = org.eclipse.xtext.generator.GeneratorComponent {
register = QvtModelJoinGeneratorStandaloneSetup {}
slot = "model"
outlet = {
path = targetDir
}
}
And in the QvtModelJoinModule i bind my RootGenerator:
public class QvtModelJoinModule extends AbstractModule {
@Override
protected void configure() {
bind(IGenerator2.class).to(IGeneratorRoot.class);
}
}
And finally the code of my IGeneratorRoot:
public class IGeneratorRoot implements IGenerator2 {
@Inject
JvmModelGenerator jvmModelGenerator;
@Inject
QvtModelJoinGenerator qvtModelJoinGenerator;
@Override
public void doGenerate(Resource input, IFileSystemAccess2 fsa, IGeneratorContext context) {
jvmModelGenerator.doGenerate(input, fsa);
qvtModelJoinGenerator.doGenerate(input, fsa, context);
}
If i save my textfile the jvmModelInferrer gets called and will generate a class.
So that part works.
So my question is, how can i give my qvtModelJoinGenerator the possibility to use the code that my jvmModelInferrer generated, or at least how to save the reference to that generated class?
Thx in advance
|
|
|
Re: configure multiple generators with XText 2.9 [message #1782133 is a reply to message #1722475] |
Mon, 19 February 2018 06:07   |
Eclipse User |
|
|
|
Hey guys,
So i read your disscussion and i think i have a similiar problem.
I have a xtext grammar which i extended which xbase. I implemented the jvmModelInferrer which generates a class, when i start the eclipse application.
But now i want to connect my old IGenerator which the jvmModelGenerator. How can i use the class which gets generated by the jvmModelInferrer?
So i added an IRootGenerator where i inject my old generator and the jvmModelGenerator.
My question is now, how can i use the code, that the jvmModelInferrer generated, or at least how to save a reference to the class which got generated?
So my mwe2 workflow component looks like that:
component = org.eclipse.xtext.generator.GeneratorComponent {
register = QvtModelJoinGeneratorStandaloneSetup {}
slot = "model"
outlet = {
path = targetDir
}
}
The QvtModelJoinGeneratorStandaloneSetup looks like that:
public class QvtModelJoinGeneratorStandaloneSetup extends ModelJoinStandaloneSetup {
@Override
public Injector createInjector() {
Injector injector = Guice.createInjector(new QvtModelJoinModule()).createChildInjector(new ModelJoinRuntimeModule());
register(injector);
return injector;
}
}
And the QvtModelJoinModule looks like that:
public class QvtModelJoinModule extends AbstractModule {
@Override
protected void configure() {
bind(IGenerator2.class).to(IGeneratorRoot.class);
}
}
And at least the IGeneratorRoot:
public class IGeneratorRoot implements IGenerator2 {
@Inject
JvmModelGenerator jvmModelGenerator;
@Inject
QvtModelJoinGenerator qvtModelJoinGenerator;
@Override
public void doGenerate(Resource input, IFileSystemAccess2 fsa, IGeneratorContext context) {
jvmModelGenerator.doGenerate(input, fsa);
qvtModelJoinGenerator.doGenerate(input, fsa, context);
}
Is that right?
Now how use the class, generated by jvmModelInferrer, in the qvtModelJoinGenerator?
Any ideas?
Thanks
|
|
|
|
Re: configure multiple generators with XText 2.9 [message #1782653 is a reply to message #1782237] |
Tue, 27 February 2018 07:07   |
Eclipse User |
|
|
|
Thx for your answer, so i will try to specify my problem:
First of all i have grammar, which validation i want to improve.
So i implemented the jvmModelInferrer. This will create methods and parameters based on the file i want to check. The class, which gets generated has something like isValid(parameter1, parameter2){ ...body} method.
Now i want to implement something like validator class, which will have a reference to the created class and calls that method.
I have a generator class which has a doGenerateMethod and looks like that
@Override
public void doGenerate(Resource input, IFileSystemAccess2 fileAccess, IGeneratorContext context) {
super.doGenerate(input, fileAccess, context);
Resource targetMetaModel = ((MetamodelGenerator) mmGenerator).getTargetMM();
transformationAnnotationBasedGenerator.doGenerate(targetMetaModel, fileAccess);
constraintsAnnotationBasedGenerator.doGenerate(targetMetaModel, fileAccess);
editableTransformationGenerator.doGenerate(targetMetaModel, fileAccess);
}
So i would change it into:
@Override
public void doGenerate(Resource input, IFileSystemAccess2 fileAccess, IGeneratorContext context) {
val wrapper = new MyWrapper(originalfsa)
jvmmodelgenerator.doGenerate(wrapper)
#### How can the later generators now get the class that the jvmModelGenerator creates?
##### How would a wrapper class looks like?
super.doGenerate(input, fileAccess, context);
Resource targetMetaModel = ((MetamodelGenerator) mmGenerator).getTargetMM();
transformationAnnotationBasedGenerator.doGenerate(targetMetaModel, fileAccess);
constraintsAnnotationBasedGenerator.doGenerate(targetMetaModel, fileAccess);
editableTransformationGenerator.doGenerate(targetMetaModel, fileAccess);
}
Hope my question got more clear.
Maybe u got an example code where you reused the generated code of the jvmModelInferrer?
Thx
|
|
|
|
Powered by
FUDForum. Page generated in 0.05942 seconds