|
Re: EStructuralFeature.isNullable() [message #431284 is a reply to message #431283] |
Tue, 07 July 2009 14:06 |
Ed Merks Messages: 33141 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
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
Re: EStructuralFeature.isNullable() [message #431285 is a reply to message #431284] |
Tue, 07 July 2009 14:28 |
Sven Efftinge 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
|
|
|
Powered by
FUDForum. Page generated in 0.04884 seconds