Skip to main content



      Home
Home » Modeling » EMF » EStructuralFeature.isNullable()
EStructuralFeature.isNullable() [message #431283] Tue, 07 July 2009 09:49 Go to next message
Eclipse UserFriend
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 10:06 Go to previous messageGo to next message
Eclipse UserFriend
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 10:28 Go to previous message
Eclipse UserFriend
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: Wed Jul 23 14:46:57 EDT 2025

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

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

Back to the top