Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Can I generate a block of java independent of my model?
Can I generate a block of java independent of my model? [message #1052854] Tue, 30 April 2013 17:56 Go to next message
Dan Barr is currently offline Dan BarrFriend
Messages: 10
Registered: April 2013
Junior Member
Hi,

Is it possible to have a java source code generated that is always the same no matter what is entered into the dsl. such as the code to create a GUI, and then have a few variables that are different such as color depending on the DSL.

for example my dsl only has a few rules such as


Name:
  'name' name=ID;

Colour:
    ....


then when my user is using the dsl they will enter a name and a colour, and the block of java code I have all ready written will be generated using whatever name and colour the user typed.
Re: Can I generate a block of java independent of my model? [message #1052858 is a reply to message #1052854] Tue, 30 April 2013 18:07 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 6550
Registered: July 2009
Senior Member
Hi,

do you use xbase or dont you. if simply infer the static stuff.
if not you have a custom generator anyway
Re: Can I generate a block of java independent of my model? [message #1052859 is a reply to message #1052858] Tue, 30 April 2013 18:26 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 6550
Registered: July 2009
Senior Member
Alertnatively you can bypass the JvmModelGenerator anyway and (additionally) generate own stuff too not using the inferrer stuff at all.
http://www.eclipse.org/forums/index.php/mv/msg/473491/1038310/#msg_1038310

Re: Can I generate a block of java independent of my model? [message #1052864 is a reply to message #1052859] Tue, 30 April 2013 19:11 Go to previous message
Dan Barr is currently offline Dan BarrFriend
Messages: 10
Registered: April 2013
Junior Member
Hey,

Thanks for the link, I'm not using Xbase, just xTend and xText.


I curentlly have this in my .Xtend file

class GameGenerator implements IGenerator {
	
	override void doGenerate(Resource resource, IFileSystemAccess fsa) {
		fsa.generateFile(resource.className+".java", toJavaCode(resource.contents.head as Game))
	}
	
	
	def className(Resource res) {
		var name = res.URI.lastSegment
		return name.substring(0, name.indexOf('.'))
	}

def toJavaCode(Game sm) '''

	//JAVA CODE HERE 
	
	'''

}


Obviously it's not very sophisticated but it gets the job done.

In my java code there is a variable for time curentlly set to 5000 miliseconds,

So now I just need to change that depending on what the user types into the DSL and i'm set.

Smile

[Updated on: Tue, 30 April 2013 19:12]

Report message to a moderator

Previous Topic:can Xtext 2.3.1 be installed in Kepler?
Next Topic:Make an executable of my DSL once its complete?
Goto Forum:
  


Current Time: Sat Dec 20 01:44:46 GMT 2014

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

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