Home » Modeling » EMF "Technology" (Ecore Tools, EMFatic, etc) » Is it possible to modify/delete an eReference from an EObject?
| | |
Re: Is it possible to modify/delete an eReference from an EObject? [message #755919 is a reply to message #755880] |
Thu, 10 November 2011 08:06 |
Ed Merks Messages: 33140 Registered: July 2009 |
Senior Member |
|
|
Theo,
Comments below.
On 10/11/2011 12:58 AM, Theo Andersen wrote:
> Thanks for the response.
>
> My example has got an object with a containment reference which has
> got 4 objects. But when looking at the parent object,
I.e., the object that has a containment reference with 4 things in it?
It should have those four things in the eContents().
> it's got 0 items in the eCrossRefernces EList.
>
> If i use eGet with the reference i can find from the eClass, i get a
> List of EObjects with 4 elements.. the four elements are the elements
> which the parent contains.
So those should also appear in the eContents() given they're in the
containment reference...
> I can remove an item from this list fine using Ecoreutil, but it fails
> when i try to use eSet(eRef, newListWithElementRemoved) with "Could
> not find object in the basemodel".
I don't recognize that error message? Of course when you call
eObject.eSet(eRef,...) it must typically be the case that
eObject.eClass().getEAllStructuralFeatures().contains(eRef)...
>
> Is there any reason my EObject would have no items in the
> eCrossReferences,
If there are no non-containment references you'd not expect any...
> if thats where the containment-references are supposed to be?
No, the containment ones appear in the eContents().
>
> Does anybody know why i can eGet an eReference, but it can't find it
> when i try to eSet it?
Of course you're doing something not quite right, but without code,
stack traces, or other details, one can only guess...
>
> Is there any examples / documentation about these things that make it
> more clear?
Is it clear what EcoreUtil.remove is doing? The code is very simple.
Did you understand what I meant about fetching the list and modifying
the list (as EcoreUtil.remove does in the isMany case)?
>
> Thanks a lot for the help
> /Theo
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
| |
Re: Is it possible to modify/delete an eReference from an EObject? [message #756129 is a reply to message #756102] |
Fri, 11 November 2011 06:58 |
Ed Merks Messages: 33140 Registered: July 2009 |
Senior Member |
|
|
Theo,
Comments below.
On 10/11/2011 11:17 PM, Theo Andersen wrote:
> Hi again.
>
> Thanks for the comments. I'm sorry but i'm not allowed to disclose the
> code at this time, but i greatly appreciate the help in understanding
> the api.
>
> I've now managed to understand, and use eGet and eSet on a reference
> look an manipulate the object on which it points. By using this list
> of eObjects (the one i get when using eGet(eReference)) and then using
> eSet(),
Note that you don't generally need to use eSet for multi-valued
features. Changing the list is all that's needed.
> i can change how many objects the reference points to. (notice that i
> do not want to remove the objects, as other references in the
> meta-model might still need them).
>
> Another similar issue is with wanting to not only reset a
> structuralFeature which is a slot on an object to its default value,
> but entirely remove the slot (structural feature) from the list.
I'm having a hard time parsing this. Structural features are part of
the Ecore model but you use the term here as if it were data actually in
a multi-valued feature's list in your instance...
>
> Is there a way i can remove a particular structural feature from an
> eObject, and not just the value which it holds (referenced objects
> with references, or ex. an 'int' if its a slot containing an int).
If I'm understanding the question correctly, no, you can't modify the
Ecore model for existing instances.
> Or is it only possibly to modify the contents of the structural
> features on eObjects?
Yes, it's only possible to edit the instances, not the model that
describes their structure. (Just as in Java, you can't just add or
remove fields from classes at runtime and still have things continue to
work.)
>
> Thanks
> /Theo
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
Goto Forum:
Current Time: Thu Apr 25 12:00:44 GMT 2024
Powered by FUDForum. Page generated in 0.03636 seconds
|