Home » Modeling » TMF (Xtext) » configure multiple generators with XText 2.9
|
Re: configure multiple generators with XText 2.9 [message #1722438 is a reply to message #1722300] |
Thu, 04 February 2016 19:32 |
|
Hi,
can you be a bit more specific about what you want to do? you can add as many fragments to the language generator as you want.
language = StandardLanguage {
name = "org.xtext.example.mydsl.MyDsl"
fileExtensions = "mydsl"
serializer = {
generateStub = false
}
validator = {
// composedCheck = "org.eclipse.xtext.validation.NamesAreUniqueValidator"
}
fragment = x.y.z.YourFragment {
}
}
YourFragment implements IXtextGeneratorFragment (probably subclass of AbstractXtextGeneratorFragment)
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
|
|
| |
Re: configure multiple generators with XText 2.9 [message #1722455 is a reply to message #1722300] |
Thu, 04 February 2016 23:02 |
herve giraud Messages: 6 Registered: February 2016 |
Junior Member |
|
|
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 #1722461 is a reply to message #1722455] |
Fri, 05 February 2016 04:13 |
|
this is a different question. you dont want to generate different stuff from your grammar, you want to generate different stuff from your models
- simply inferr more than one class in your inferrer
- subclass jvmmodelgenenerator (add a binding in the RuntimeModule/see below) and hook into doGenerate / internalDoGenerate and call fsa.doSomething as often as you want
- bind i delegating generator in the runtimemodule that delegates to your generator AND JvmModelGenerator
public class DelegatingGenerator implements IGenerator {
@Inject
JvmModelGenerator jvmModelGenerator;
@Inject
YourGenerator yourGenerator;
@Override
public void doGenerate(Resource input, IFileSystemAccess fsa) {
jvmModelGenerator.doGenerate(input, fsa);
yourGenerator.doGenerate(input, fsa);
}
}
public class DomainmodelRuntimeModule extends AbstractDomainmodelRuntimeModule {
....
@Override
public Class<? extends IGenerator> bindIGenerator() {
return DelegatingGenerator,class
}
}
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
|
|
| |
Re: configure multiple generators with XText 2.9 [message #1782110 is a reply to message #1722300] |
Sun, 18 February 2018 11:11 |
Hermann Ritzenthaler Messages: 14 Registered: February 2018 |
Junior Member |
|
|
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 11:07 |
Hermann Ritzenthaler Messages: 14 Registered: February 2018 |
Junior Member |
|
|
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 #1782237 is a reply to message #1782133] |
Tue, 20 February 2018 19:27 |
|
Hi,
you would have to use a custom wrapping file system access to record what the jvm model generator does.
e.g. val wrapper = new MyWrapper(originalfsa)
jvmmodelgenerator.doGenerate(....,wrapper, ..)
or you use subclassing of jvmmodelgenerator instead of delegating.
but i am not sure since i dont know your actual problem.
but i am not sure about the actually problem
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
|
|
|
Re: configure multiple generators with XText 2.9 [message #1782653 is a reply to message #1782237] |
Tue, 27 February 2018 12:07 |
Hermann Ritzenthaler Messages: 14 Registered: February 2018 |
Junior Member |
|
|
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
|
|
| |
Goto Forum:
Current Time: Thu Apr 18 10:09:13 GMT 2024
Powered by FUDForum. Page generated in 0.03365 seconds
|