Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Problem with Terminal rule INT in generator
Problem with Terminal rule INT in generator [message #757679] Mon, 21 November 2011 09:04 Go to next message
Simon  is currently offline Simon Friend
Messages: 4
Registered: November 2011
Junior Member
Hey,

I have a little Problem with my grammar and my generator. Maybe anyone of you knows a solution for this.

In my grammar I defined an optional int property:

Properties:
('weightX' weightX=INT)?

Now I like to check in my generator if the value is set or not. Int is a primitive Java type and cannot be null (only references can be). So the the property gets the default value 0 and I can do the following check in:

«IF (c.properties.weightX != 0)»

My Problem with this check is that my property can't have the value 0 and this should be allowed. Is there any Solution for this? Is there any possibility that my generator uses Integer instead of int?

Best regards,
Simon
Re: Problem with Terminal rule INT in generator [message #757682 is a reply to message #757679] Mon, 21 November 2011 09:08 Go to previous messageGo to next message
Ingo Meyer is currently offline Ingo MeyerFriend
Messages: 162
Registered: July 2009
Senior Member
You could also do

(hasWeightX ?= 'weightX' weightX=INT)?


Then you have an additional boolean property "hasWeightX" which you can query if your hole block is present in the model.

«IF (c.properties.hasWeightX)»
«do something with c.properties.weightX ...»


Kind regards,
Ingo
Re: Problem with Terminal rule INT in generator [message #757683 is a reply to message #757679] Mon, 21 November 2011 09:10 Go to previous messageGo to next message
Meinte Boersma is currently offline Meinte BoersmaFriend
Messages: 434
Registered: July 2009
Location: Leiden, Netherlands
Senior Member
You can use Ecore's EObject#eIsSet method: c.properties.eIsSet(c.properties.eClass.getEStructuralFeature("weightX"))
(It's fairly easy to wrap this in a nice extension.)


Re: Problem with Terminal rule INT in generator [message #757689 is a reply to message #757679] Mon, 21 November 2011 09:17 Go to previous messageGo to next message
Simon  is currently offline Simon Friend
Messages: 4
Registered: November 2011
Junior Member
Thanks for the quick response! Smile
Meinte's Answer works like a charm.
Re: Problem with Terminal rule INT in generator [message #757694 is a reply to message #757679] Mon, 21 November 2011 09:32 Go to previous messageGo to next message
Simon  is currently offline Simon Friend
Messages: 4
Registered: November 2011
Junior Member
Sorry,

I still have a problem. With Meinte's solution it is not possible to set value 0 in my model Sad
Re: Problem with Terminal rule INT in generator [message #757699 is a reply to message #757694] Mon, 21 November 2011 09:46 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
use a Datatype Rule that returns a ecore::EIntegerObject + a valueconverter

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Problem with Terminal rule INT in generator [message #757721 is a reply to message #757679] Mon, 21 November 2011 11:03 Go to previous message
Simon  is currently offline Simon Friend
Messages: 4
Registered: November 2011
Junior Member
Hey Christian,

many thanks! You made my day Wink
Previous Topic:Generate Annotation with several parameters
Next Topic:understanding ImportManager
Goto Forum:
  


Current Time: Tue Apr 23 17:20:51 GMT 2024

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

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

Back to the top