Ternary operator inside Xtend

604 views
Skip to first unread message

Hemal Bavishi

unread,
Dec 2, 2014, 1:00:39 AM12/2/14
to xtend...@googlegroups.com
Hello,

Ternary operator inside Xtend is supported? I am getting an error "throw new Error("Unresolved compilation problems:"
      + "\nno viable alternative at input \'?\'"
      + "\nno viable alternative at input \'\"STD_ON\"\'"); "

#define CANSM_DEV_ERROR_DETECT « (instanceCanSM.canSMGeneral.canSMDevErrorDetect == true) ? "STD_ON" : "STD_OFF" »

If I write in a normal way then it works as expected

#define CANSM_DEV_ERROR_DETECT « if (instanceCanSM.canSMGeneral.canSMDevErrorDetect == true) {"STD_ON"} else{"STD_OFF"} »

Best Regards,
Hemal Bavishi


Sven Efftinge

unread,
Dec 2, 2014, 1:41:14 AM12/2/14
to xtend...@googlegroups.com
If-then-else is an expression so you can write

> #define CANSM_DEV_ERROR_DETECT «if (instanceCanSM.canSMGeneral.canSMDevErrorDetect == true) "STD_ON" else "STD_OFF” »

The ternary operator is not supported.

Cheers,
Sven

Hemal Bavishi

unread,
Dec 2, 2014, 2:42:00 AM12/2/14
to xtend...@googlegroups.com, efft...@itemis.de
Thanks for your quick response. Hope same will be added in the Xtend documentation. It will help others. 

I want to print total number of "canSMControllers" contained by canSMManagerNetworks class

in the given configuration, there are two instance of canSMManagerNetworks . First instance of canSMManagerNetworks contains only one instance of "canSMControllers" element and second instance contains two. I should get total 3 but I am getting two. Any reason why?

#define CANSM_NO_OF_CONTROLLER «(instanceCanSM.canSMConfiguration.canSMManagerNetworks.map[canSMControllers].size)»

Sven Efftinge

unread,
Dec 2, 2014, 3:02:46 AM12/2/14
to xtend...@googlegroups.com
I guess you get a list of lists.
You need to flatten that : map[…].flatten.size

--
You received this message because you are subscribed to the Google Groups "Xtend Programming Language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to xtend-lang+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Hemal Bavishi

unread,
Dec 2, 2014, 3:31:21 AM12/2/14
to xtend...@googlegroups.com
Thanks it worked 

--
You received this message because you are subscribed to a topic in the Google Groups "Xtend Programming Language" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/xtend-lang/i7MOkxucZOY/unsubscribe.
To unsubscribe from this group and all its topics, send an email to xtend-lang+...@googlegroups.com.
330.gif
Reply all
Reply to author
Forward
0 new messages