Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Determining presence/absence of third parameter
Determining presence/absence of third parameter [message #1386133] Fri, 13 June 2014 14:32 Go to next message
Gary Worsham is currently offline Gary WorshamFriend
Messages: 176
Registered: September 2013
Senior Member
I created a (data type?) rule as follows:

GetDelayScaleControl: '@getDelayScaleControl' buffer = ID length = ID (control = ID)?;

So, clearly there are some cases where I want to send two parameters and some where I want to send three.

It's not clear to me how to sort out whether or not the third parameter was passed, in my code generator Xtend. In Java I would just write an overloaded function with the alternate parameter scheme. But in Xtend, I have to ask whether it was passed. If I try to reference it when it's not been passed, nothing comes out, which is fine. But I need to make a decision at code generation time.

Probably something really basic that I'm missing. Thanks for any hints.
Re: Determining presence/absence of third parameter [message #1386143 is a reply to message #1386133] Fri, 13 June 2014 15:30 Go to previous messageGo to next message
Uli Merkel is currently offline Uli MerkelFriend
Messages: 248
Registered: June 2013
Senior Member
Hi Gary, what about a simple thing in your generator like:

if (getDelayScaleControl.control != null) {...} else {...}
Re: Determining presence/absence of third parameter [message #1386144 is a reply to message #1386133] Fri, 13 June 2014 15:30 Go to previous messageGo to next message
Christian Dietrich is currently online Christian DietrichFriend
Messages: 13319
Registered: July 2009
Senior Member
Hi,

no this is a normal parser rule

you can do a simple null check like this in your generator. or you use emf facilities

def getInfo(YourRule it) {
		'''
		buffer: «buffer»
		length: «length»
		«IF control != null»
			control: «control»
		«ENDIF»
		«IF eIsSet(MyDslPackage.Literals.YOUR_RULE__CONTROL)»
			control: «control»
		«ENDIF»
		'''
	}


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/xtext/
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Determining presence/absence of third parameter [message #1386190 is a reply to message #1386144] Sat, 14 June 2014 15:52 Go to previous message
Gary Worsham is currently offline Gary WorshamFriend
Messages: 176
Registered: September 2013
Senior Member
Thanks guys, works great!
Previous Topic:2.6.1 released
Next Topic:arguments to mwe2 workflow
Goto Forum:
  


Current Time: Mon Jan 27 18:57:58 GMT 2020

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

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

Back to the top