Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Code generation
Code generation [message #1810188] Fri, 02 August 2019 13:41 Go to next message
Sara Moh is currently offline Sara MohFriend
Messages: 2
Registered: August 2019
Junior Member
Hi,

Can someone help me, please?

I'm learning Xtext to generate a full mobile application. I wrote the KM3 grammar however I don't know what code I should generate to have an android application.

Is there any reference could help me with code generation?

Thanks,
Sara
Re: Code generation [message #1810562 is a reply to message #1810188] Tue, 13 August 2019 13:44 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13124
Registered: July 2009
Senior Member
Hi, can you be more specific with your question. i have no idea where you are stuck.
you can have a look at https://www.eclipse.org/Xtext/documentation/103_domainmodelnextsteps.html
for a simple generator tutorial


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/xtext/
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Code generation [message #1810671 is a reply to message #1810562] Thu, 15 August 2019 16:52 Go to previous messageGo to next message
Sara Moh is currently offline Sara MohFriend
Messages: 2
Registered: August 2019
Junior Member
Hi Christian, Thanks for your replay I solve the previous question but I have a new one here.

I want to generate a user interface for the android application in one XML file, I used the following code.

for (v : resource.allContents.toIterable.filter(ViewGUIElement)) {
fsa.generateFile(
"activity_main.xml",
v.generate)
}

but it overwrites the elements and displays only the last one.

When I use the following code I cannot use the method generate so it doesn't generate what I want

fsa.generateFile('activity_main.xml',
resource.allContents.toIterable.filter((ViewGUIElement))
.join('\n'))

}
Re: Code generation [message #1810672 is a reply to message #1810671] Thu, 15 August 2019 17:28 Go to previous messageGo to next message
Tamas Miklossy is currently offline Tamas MiklossyFriend
Messages: 54
Registered: February 2016
Member
You should use rich strings int the code generation, as described in the Xtext extended tutorial:
https://www.eclipse.org/Xtext/documentation/103_domainmodelnextsteps.html#tutorial-code-generation
Re: Code generation [message #1810715 is a reply to message #1810672] Sat, 17 August 2019 06:54 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13124
Registered: July 2009
Senior Member
so in your case it would look like

	override void doGenerate(Resource resource, IFileSystemAccess2 fsa, IGeneratorContext context) {
		fsa.generateFile("activity_main.xml", '''
		«FOR v : resource.allContents.toIterable.filter(ViewGUIElement)»
			«v.generate»
		«ENDFOR»
		''')
	}


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/xtext/
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:Content assist test with import
Next Topic:Maven: Getting the configured Java source version
Goto Forum:
  


Current Time: Thu Sep 19 13:08:45 GMT 2019

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

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

Back to the top