Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Calling doGenerate in other doGenerate
Calling doGenerate in other doGenerate [message #1835954] Thu, 17 December 2020 08:04 Go to next message
Alexandra Tritean is currently offline Alexandra TriteanFriend
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
Re: Calling doGenerate in other doGenerate [message #1835955 is a reply to message #1835954] Thu, 17 December 2020 08:10 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
if you want two dsls to ping pong each other you need to
create a second custom written builder that touches the files
the first builder creates so that eclipse then calls the xtext builder on
the generates files again.

the approach you took could work too, but i dont see the problem with NPE as you did not post what is null.


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Calling doGenerate in other doGenerate [message #1835959 is a reply to message #1835955] Thu, 17 December 2020 08:52 Go to previous messageGo to next message
Alexandra Tritean is currently offline Alexandra TriteanFriend
Messages: 37
Registered: March 2020
Member
Looks like sharing your problem with someone opens your eyes. :)

In ModelGenerator I have two extensions, which seem to be null.

@Inject extension TracingSugar (org.eclipse.xtext.generator.trace.node)
@Inject extension GeneratedClasses ( written by me)

Is there any particular way in which I should initialize the ModelGenerator?

Kind Regards,

Alexandra
Re: Calling doGenerate in other doGenerate [message #1835962 is a reply to message #1835959] Thu, 17 December 2020 09:23 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
dont do new ModelGenerator()
and use IGlobalServiceProvider to get other dsls IGenerator(2)


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Calling doGenerate in other doGenerate [message #1835966 is a reply to message #1835962] Thu, 17 December 2020 10:49 Go to previous message
Alexandra Tritean is currently offline Alexandra TriteanFriend
Messages: 37
Registered: March 2020
Member
That works. :)

As always, thank you very much for your help!

Happy Holidays!
Previous Topic:How to find the cross-references of an Eobject across files?
Next Topic:grammar to permit zipfiles in a string
Goto Forum:
  


Current Time: Fri Apr 19 22:41:55 GMT 2024

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

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

Back to the top