Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » EStructuralFeature.isNullable()
EStructuralFeature.isNullable() [message #431283] Tue, 07 July 2009 13:49 Go to next message
Sven Efftinge is currently offline Sven EfftingeFriend
Messages: 1823
Registered: July 2009
Senior Member
Hi,

how can I find out whether a certain feature can be set to null?
For example if I have a feature of type EInt I get a classcastexception,
because under the hood the code trys to autobox null to an int.

Are there any flags, which could give me a hint?

Cheers,
Sven
Re: EStructuralFeature.isNullable() [message #431284 is a reply to message #431283] Tue, 07 July 2009 14:06 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 30692
Registered: July 2009
Senior Member
Sven,

Comments below.

Sven Efftinge wrote:
> Hi,
>
> how can I find out whether a certain feature can be set to null?
Perhaps you should consider unsetting the feature, i.e., eUnset(feature)
rather eSet(feature, null). Certainly null isn't going to be valid for
an isMany feature, nor will it be valid for a single-valued feature if
EDataType.getInstanceClass().isPrimitive() is true because null is not
in the value space for primitives. There's also
EClassifier.getDefaultValue() which is null except for primitives.
> For example if I have a feature of type EInt I get a
> classcastexception, because under the hood the code trys to autobox
> null to an int.
>
> Are there any flags, which could give me a hint?
Maybe I should ask specifically what you're trying to do because eUnset
might be better, or setting to the feature's type's default value might
be better, but there's a subtle difference of course because an
unsettable feature will be set after you call eSet...
>
> Cheers,
> Sven
Re: EStructuralFeature.isNullable() [message #431285 is a reply to message #431284] Tue, 07 July 2009 14:28 Go to previous message
Sven Efftinge is currently offline Sven EfftingeFriend
Messages: 1823
Registered: July 2009
Senior Member
Hi Ed,

"EDataType.getInstanceClass().isPrimitive()" is what I was asking for.

I was just stumbling over a bug in Xtext
(https://bugs.eclipse.org/bugs/show_bug.cgi?id=280873) and was curious
about how to find this out reflectively.

Thanks,
Sven

Ed Merks schrieb:
> Sven,
>
> Comments below.
>
> Sven Efftinge wrote:
>> Hi,
>>
>> how can I find out whether a certain feature can be set to null?
> Perhaps you should consider unsetting the feature, i.e., eUnset(feature)
> rather eSet(feature, null). Certainly null isn't going to be valid for
> an isMany feature, nor will it be valid for a single-valued feature if
> EDataType.getInstanceClass().isPrimitive() is true because null is not
> in the value space for primitives. There's also
> EClassifier.getDefaultValue() which is null except for primitives.
>> For example if I have a feature of type EInt I get a
>> classcastexception, because under the hood the code trys to autobox
>> null to an int.
>>
>> Are there any flags, which could give me a hint?
> Maybe I should ask specifically what you're trying to do because eUnset
> might be better, or setting to the feature's type's default value might
> be better, but there's a subtle difference of course because an
> unsettable feature will be set after you call eSet...
>>
>> Cheers,
>> Sven
Previous Topic:[TENEO] Illegal attempt to associate a collection with two open sessions
Next Topic:EditingDomainActionBarContributor#init(IActionBars)
Goto Forum:
  


Current Time: Fri Dec 13 16:23:41 GMT 2019

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

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

Back to the top