|
Re: Calling eGet for invalid structural feature [message #1421505 is a reply to message #1421404] |
Thu, 11 September 2014 13:03 |
|
Hi, Felix,
I express my own opinions, below. Probably not the canonical answer :-)
Christian
On 2014-09-11 10:18:03 +0000, Felix Dorner said:
> I want to eGet a given feature on a collection of EObjects, but not all
> of the EObjects are instances of the EClass that defines the feature.
>
> So which is preferable?
>
> // This is the shortest, but is this safe? I guess if the feature isn't
> defined on the objects (super)type(s) it will just return null..
> for (EObject e : someEObjects){
> Object o = e.eGet(feature)
> }
This throws some kind of RuntimeException.
> // check if all structural features include the interesting feature
> for (EObject e : someEObjects){
> if (e.eClass().getEAllStructuralFeatures().contains(feature)){
> Object o = e.eGet(feature)
> }
> }
That works.
> // check if the object is an instance of the type that defines the feature
> for (EObject e : someEObjects){
> if (feature.eContainingClass().isInstance(e)){
> e.eGet(feature)
> }
> }
This feels best IMO because one really ought to be able to rely on the
EMF Run-time actually making the feature available if the instance
conforms to the feature's defining class.
|
|
|
|
|
Re: Calling eGet for invalid structural feature [message #1424103 is a reply to message #1423837] |
Mon, 15 September 2014 13:09 |
|
On 2014-09-15 04:11:54 +0000, Ed Merks said:
>
> Yes, or alternatively checking that
> e.eClass().getEAllStructuralFeatures().contains(feature) or for even
> better performance, using
> eObject.eGet(e.eClass().getFeatureID(feature)) *but* checking that the
> feature ID >= 0.
Whoa, that one rather blows my mind.
:-)
|
|
|
Powered by
FUDForum. Page generated in 0.03224 seconds