Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » multiple generators - Xtext2, xtend2
multiple generators - Xtext2, xtend2 [message #759945] Wed, 30 November 2011 16:25 Go to next message
Bruce L. is currently offline Bruce L.Friend
Messages: 81
Registered: June 2011
Member
Hello,
I'm using Xtext 2.0.1 and so Xtend2 for code generation.

How can I execute multiple different generators?
I mean more than one xtend2 class that implements the IGenerator interface (as the one that is created automatically in the generator package of the project)

I do not fully understand the relation between the workflow file and Main.java (again, in the generator package), and how I am supposed to modify them in order to run my multiple templates.

Main.java declares a single IGenerator that is instantiated magically somewhere with the default xtend2 class (file '<lang>Generator.xtend'). If I add another IGenerator member I can see (by debugging) that also this reference is instantiated magically, but with the same default class as the other one. How can I specify another class?

The workflow file '<lang>GeneratorMWE.mwe2' does not have any reference to any specific xtend2 class, so I do not know how to modify it (it only creates a generic org.eclipse.xtext.generator.GeneratorComponent)

I am sorry but as far as I can see the documentation describes the general syntax of MWE and xtend2, but does not show any example or explanation with respect to the files generated automatically by Xtext (ie the default Main.java and the workflow)

I hope this is somehow clear.
Thanks for any hint
Re: multiple generators - Xtext2, xtend2 [message #759954 is a reply to message #759945] Wed, 30 November 2011 16:59 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Hi,

(A) use a wrapper generator that delegates to all of your generators
(B)
component = GeneratorComponent {
  register = GeneratorASpecificSetup{}
}
component = GeneratorComponent {
  register = GeneratorBSpecificSetup{}
}

GeneratorASpecificSetup and GeneratorBSpecificSetup are i setups that come with a custom binding of IGnerator

~Christian



Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: multiple generators - Xtext2, xtend2 [message #759958 is a reply to message #759954] Wed, 30 November 2011 17:34 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Here a complete sample von B

class MyDslGeneratorA implements IGenerator {
	
	override void doGenerate(Resource resource, IFileSystemAccess fsa) {
		fsa.generateFile("a.txt","A")
	}
}


class MyDslGeneratorB implements IGenerator {
	
	override void doGenerate(Resource resource, IFileSystemAccess fsa) {
		fsa.generateFile("b.txt","B")
	}
}


public class MyDslStandaloneSetupGenA extends MyDslStandaloneSetup {

	public Injector createInjector() {
		return Guice.createInjector(new org.xtext.example.mydsl.MyDslRuntimeModule() {
			
			@Override
			public Class<? extends IGenerator> bindIGenerator() {
				return MyDslGeneratorA.class;
			}
			
		});
	}
}


public class MyDslStandaloneSetupGenB extends MyDslStandaloneSetup {
	
	public Injector createInjector() {
		return Guice.createInjector(new org.xtext.example.mydsl.MyDslRuntimeModule() {
			
			@Override
			public Class<? extends IGenerator> bindIGenerator() {
				return MyDslGeneratorB.class;
			}
			
		});
	}
	
}


	component = org.eclipse.xtext.generator.GeneratorComponent {
		register = org.xtext.example.mydsl.MyDslStandaloneSetupGenA {}
		slot = 'model'
		outlet = {
			path = targetDir
		}
	}
	
	component = org.eclipse.xtext.generator.GeneratorComponent {
		register = org.xtext.example.mydsl.MyDslStandaloneSetupGenB {}
		slot = 'model'
		outlet = {
			path = targetDir
		}
	}


so the keypoint is that the generated binding for IGenerator points to MydslGenerator
thus this one is used in Main / Workflow (and Builder)

~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: multiple generators - Xtext2, xtend2 [message #759962 is a reply to message #759954] Wed, 30 November 2011 18:01 Go to previous message
Bruce L. is currently offline Bruce L.Friend
Messages: 81
Registered: June 2011
Member
Thanks, it works!
I figured out the required overriding even before reading your last post, but it is good to have a confirmation! and as a reference for others with the same problem.

Anyhow, this works as far as the workflow file is concerned, for the main it looks to me that I have to modify something more, but I'm going to double check
Previous Topic:extending Xbase expression syntax and possible ambiguities
Next Topic:Problems with generated grammar from existing ecore model
Goto Forum:
  


Current Time: Thu Apr 25 07:48:12 GMT 2024

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

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

Back to the top