|EMF Compare get ModelElementChangeLeftTarget/ModelElementChangeRightTarget Attributes [message #1121500]
||Mon, 30 September 2013 13:36
| d 627
Registered: March 2013
I have a question about how to get the value of some attributes using emf compare.
I got an object that belongs to ModelElementChangeLeftTarget. Something like this:
org.eclipse.xxxxxxx@1a81efd (cardinality: null, predicated: false) (value: country) has been added
What I need is to get the value of the attribute "value", in this example "country", but I got not idea about how to get only that particular value. I have trying doing this:
ModelElementChangeLeftTarget meclt = (ModelElementChangeLeftTarget)obj
String value = (String)lt.getLeftElement().eGet((EStructuralFeature)eGet(meclt.eContainingFeature()).toString();
But obviously this did not work, I also tried other possibilities but...
What anyone give and advice about this?
Thanks a lot
|Re: EMF Compare get ModelElementChangeLeftTarget/ModelElementChangeRightTarget Attributes [message #1123316 is a reply to message #1121500]
||Wed, 02 October 2013 08:40
| Laurent Goubet
Registered: July 2009
You will have to get a good understanding of both the diff metamodel of EMF Compare 1 and EMF itself before properly navigating to the elment you need.
First of all, a "ModelElementChange" diff means that an EObject, as a whole, has been added or deleted. "value" is no more than one of the attribute of the EObject that's been added or removed from the model. As such, retrieving only the value of this changed element doesn't make sense wrt. EMF Compare; what you have is a pure EMF question.
In this case, you are trying to retrieve the value of a particular feature for a given EObject. Since you do not know said EObjet's type, you need to use the reflexive APIs of EMF (as you did, through "eGet"). The "particular feature", you have to find for yourself since EMF Compare does not know about it either (the diff is not on that feature).
If you know that the feature you need will always be called "value", you can use a code such as this :
ModelElementChangeLeftTarget diff = (ModelElementChangeLeftTarget)obj;
EObject changedEObject = diff.getLeftElement();
EStructuralFeature valueFeature = changedEObject.eClass().getEStructuralFeature("value");
Object featureValue = changedEObject.eGet(valueFeature);
Powered by FUDForum
. Page generated in 0.03359 seconds