Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Standalone code generation for list of files
Standalone code generation for list of files [message #1778035] Fri, 08 December 2017 12:28 Go to next message
Mukesh Sharma is currently offline Mukesh SharmaFriend
Messages: 1
Registered: December 2017
Junior Member
Scenario: I have a DSL in such a way that components can be distributed over multiple files. e.g. let say , I have foo.mydsl, bar.mydsl.

Now, I want to generate code for model composite of above mentioned files. I checked through the stub generated by xtext for standalone code generation, but it takes one resource at a time.

e.g.
def protected runGenerator(String string) {
	// Load the resource
	val set = resourceSetProvider.get
	val resource = set.getResource(URI.createFileURI(string), true)
	
       // Validate the resource
	val issues = validator.validate(resource, CheckMode.ALL, CancelIndicator.NullImpl)
	if (!issues.empty) {
		issues.forEach[System.err.println(it)]
		return
	}

	// Configure and start the generator
	fileAccess.outputPath = 'src-gen'
	val context = new GeneratorContext => [
		cancelIndicator = CancelIndicator.NullImpl
	]
	generator.generate(resource, fileAccess, context)
	System.out.println('Code generation finished.')
}


Now, this code fails for me, because foo.mydsl has some component dependency in bar.mydsl. I want to read all dsl files in a given folder and generate the code ?

Also, if I pass folder path to the above mentioned generator, then it throws "Cannot create a resource for 'file:/tmp/dsl/'; a registered resource factory is needed" ?
Re: Standalone code generation for list of files [message #1778176 is a reply to message #1778035] Mon, 11 December 2017 13:43 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14716
Registered: July 2009
Senior Member
you need to load all resources manually e.g.

val resource = set.getResource(URI.createFileURI(string), true)
val resource2 = set.getResource(URI.createFileURI(string2), true)
....
val resourceN = set.getResource(URI.createFileURI(stringN), true)

or traverse the file tree etc ..


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:Maven parallel build with Xtext
Next Topic:Best place to store a derived model and to make it referable from the DSL
Goto Forum:
  


Current Time: Wed Sep 18 20:45:07 GMT 2024

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

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

Back to the top