Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 368220 - [Xbase] elvis "operator"
Summary: [Xbase] elvis "operator"
Status: CLOSED FIXED
Alias: None
Product: TMF
Classification: Modeling
Component: Xtext (show other bugs)
Version: 2.3.0   Edit
Hardware: PC Mac OS X - Carbon (unsup.)
: P3 enhancement (vote)
Target Milestone: Final   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-01-10 03:03 EST by Sven Efftinge CLA
Modified: 2017-10-31 10:59 EDT (History)
2 users (show)

See Also:
sebastian.zarnekow: juno+


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Sven Efftinge CLA 2012-01-10 03:03:51 EST
The elvis operator effectively allows to provide a default value in case an expression evaluates to 'null'.

Example :

  someStringOrNull :? 'hello'

I propose to do this via library using an extension method on java.lang.Object.

  someStringOrNull.ifnull['hello']

@rrmckinley suggested via twitter to use a shorter more readable name like 'or' or 'else'. 
Unfortunately 'else' being a keyword won't work and 'or' could be surprising since as it would be defined on Object the following expression would result in 'false':

false.or[true]

Any other suggestions?
Comment 1 McKinley CLA 2012-01-10 03:14:31 EST
I agree with you that 'or' is a bad surprise. I rescind! ;-) Null should be in the method name to be the best guide.
Comment 2 Sebastian Zarnekow CLA 2012-01-10 04:24:47 EST
I find ifNull the most intuitive name. IMO 'else' or 'or' are not descriptive enough and I don't think that we really need a shorter name than ifNull.
Comment 3 Sebastian Zarnekow CLA 2012-07-05 04:56:34 EDT
Available in 2.3
Comment 4 Eclipse Webmaster CLA 2017-10-31 10:48:16 EDT
Requested via bug 522520.

-M.
Comment 5 Eclipse Webmaster CLA 2017-10-31 10:59:16 EDT
Requested via bug 522520.

-M.