Skip to main content



      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 07:28 Go to next message
Eclipse UserFriend
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 08:43 Go to previous message
Eclipse UserFriend
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 ..
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: Thu Jul 10 01:33:11 EDT 2025

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

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

Back to the top