Skip to main content



      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 04:04 Go to next message
Eclipse UserFriend
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 04:08 Go to previous messageGo to next message
Eclipse UserFriend
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 04:10 Go to previous messageGo to next message
Eclipse UserFriend
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 04:17 Go to previous messageGo to next message
Eclipse UserFriend
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 04:32 Go to previous messageGo to next message
Eclipse UserFriend
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 04:46 Go to previous messageGo to next message
Eclipse UserFriend
use a Datatype Rule that returns a ecore::EIntegerObject + a valueconverter
Re: Problem with Terminal rule INT in generator [message #757721 is a reply to message #757679] Mon, 21 November 2011 06:03 Go to previous message
Eclipse UserFriend
Hey Christian,

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


Current Time: Thu Jul 24 15:12:54 EDT 2025

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

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

Back to the top