Suppose I have a UML model conforming to the org.eclipse.uml2.uml metamodel. Suppose that this model contains a Class
, a Property
, and an ownedAttribute
relationship between them.
At the Ecore level, the Class
and the Property
are EObjects
, while the ownedAttribute
is an EReference
.
My task is as follows: given an EObject
, retrieve all of its EReferences
. I can accomplish this using the following code snippet:
for (EReference eRef : myEObject.eClass().getEAllReferences()) {
if (eObject.eIsSet(eRef)) {
// found a relevant EReference
}
}
Going back to the UML example above, this code snippet would identify all of the following EReferences
: ownedElement
, ownedMember
, member
, feature
, attribute
, ownedAttribute
, role
.
My problem: out of the identified EReferences
, I would like to keep only ownedAttribute
, since this relationship subsets all of the others according to the UML standard. However, the Ecore metamodel does not specify any kind of hierarchy between EReferences. What approach could I use to filter out the more general EReferences
that I am not interested in?
You can filter out 'derived' references (org.eclipse.emf.ecore.EStructuralFeature.isDerived() == false).