Standalone code generation for list of files [message #1778035] |
Fri, 08 December 2017 07:28  |
Eclipse User |
|
|
|
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  |
Eclipse User |
|
|
|
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 ..
|
|
|
Powered by
FUDForum. Page generated in 0.10153 seconds