Calling doGenerate in other doGenerate [message #1835954] |
Thu, 17 December 2020 08:04  |
Alexandra Tritean Messages: 37 Registered: March 2020 |
Member |
|
|
Hello,
Is it viable to call doGenerate in other doGenerate method?
What I'm trying to achieve is the following flow: from .datamodel file -> generate . model file -> (from model file) -> generate .java files.
I have both generators working fine as standalone generators, but when queuing them I'm struggling with a NullPointerException and I'm not sure if I'm missing something in the configuration or the flow is not correct.
class DatamodelGenerator extends AbstractGenerator {
override void doGenerate(Resource resource, IFileSystemAccess2 fsa, IGeneratorContext context) {
// datamodel to model generation
var resourceURI = resource.URI
var modelFileName = resourceURI.toString.substring(resourceURI.toString.lastIndexOf('/')+1).replace("datamodel","model");
if(fsa.isFile(modelFileName)) {
var modelResourceURI = resourceURI.trimSegments(resourceURI.segments.size - 2).appendSegment("src").appendSegment("main").appendSegment("resources").appendSegment(modelFileName)
if(modelResourceURI.isPlatform){
var modelResource = resource.resourceSet.getResource(modelResourceURI, true)
var project = ResourcesPlugin.workspace.getRoot.getFile(new Path(modelResourceURI.toPlatformString(true))).project
var modelGenerationFsa = new EclipseResourceFileSystemAccess2
modelGenerationFsa.setProject(project)
modelGenerationFsa.setMonitor(new NullProgressMonitor())
modelGenerationFsa.setOutputConfigurations(outputConfigurationsMap)
new ModelGenerator().doGenerate(modelResource, modelGenerationFsa, new GeneratorContext)
}
}
}
What I saw while debugging is that after executing 1-2 lines from ModelGenerator, it randomly 'jumps' into GeneratorDelegate.afterGenerate with the generator being DatamodelDslGenerator. I suppose that I need some kind of synchronization/ executing ModelGenerator only after the DatamodelGenerator finished or something. I tried having the ModelGenerator.doGenerate call in the afterGenerate method of DatamodelGenerator, but that doesn't help either.
Am I doing something wrong? Is there another approach that I can follow in order to achieve the flow?
Thank you!
Kind Regards,
Alexandra
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.01860 seconds