Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » configure multiple generators with XText 2.9
configure multiple generators with XText 2.9 [message #1722300] Wed, 03 February 2016 23:00 Go to next message
herve giraud is currently offline herve giraudFriend
Messages: 6
Registered: February 2016
Junior Member
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 #1722438 is a reply to message #1722300] Thu, 04 February 2016 19:32 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
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 #1722441 is a reply to message #1722438] Thu, 04 February 2016 20:18 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
(for the old xtext 2.8.x style of workflow the superclass and interfaces are IGeneratorFragment / DefaultGeneratorFragment

(I am not sure if I got your question at all)


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de

[Updated on: Thu, 04 February 2016 21:07]

Report message to a moderator

Re: configure multiple generators with XText 2.9 [message #1722455 is a reply to message #1722300] Thu, 04 February 2016 23:02 Go to previous messageGo to next message
herve giraud is currently offline herve giraudFriend
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 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
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 #1722475 is a reply to message #1722461] Fri, 05 February 2016 08:21 Go to previous messageGo to next message
herve giraud is currently offline herve giraudFriend
Messages: 6
Registered: February 2016
Junior Member
Yes, exactly what I needed. It works perfectly.

Thank you for your time.
Re: configure multiple generators with XText 2.9 [message #1782110 is a reply to message #1722300] Sun, 18 February 2018 11:11 Go to previous messageGo to next message
Hermann Ritzenthaler is currently offline Hermann RitzenthalerFriend
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 Go to previous messageGo to next message
Hermann Ritzenthaler is currently offline Hermann RitzenthalerFriend
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 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
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 Go to previous messageGo to next message
Hermann Ritzenthaler is currently offline Hermann RitzenthalerFriend
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
Re: configure multiple generators with XText 2.9 [message #1782655 is a reply to message #1782653] Tue, 27 February 2018 12:19 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
this makes no sense to me at all. calling a method is no reuse.
jvmmodelinferring has nothing todo with the generators you later call on the inferred model.

so i dont understand why you need any information about what jvmmodelgenerator did


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:Custom Lexer and Semantic Predicates issue
Next Topic:Xbase: Organize imports removes imported model packages
Goto Forum:
  


Current Time: Thu Apr 18 10:09:13 GMT 2024

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

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

Back to the top