public static List<EReference> filterByContainerMetaclass(
     Collection<EReference> eReferences, NodeReference nodeReference, boolean containmentOnly) {
   EClass containerMetaClass = null;
   EClass targetMetaClass = null;
   if (nodeReference instanceof ChildReference) {
     containerMetaClass = ((ChildReference) nodeReference).getParentNode().getDomainMetaElement();
   } else if (nodeReference instanceof TopNodeReference) {
     CanvasMapping diagram = ((Mapping) nodeReference.eContainer()).getDiagram();
     if (diagram != null) {
       containerMetaClass = diagram.getDomainMetaElement();
     }
   }
   if (nodeReference.isSetChild()) {
     targetMetaClass = nodeReference.getChild().getDomainMetaElement();
   }
   List<EReference> fromHierarchy =
       sort(
           getEReferences(
               getEStructuralFeaturesOf(eReferences, containerMetaClass), containmentOnly));
   if (targetMetaClass == null) {
     // no child known, thus can take references from metaelement's hierarchy only
     return fromHierarchy;
   }
   List<EReference> targetsToChild =
       sort(getEReferences(getEReferencesOfType(eReferences, targetMetaClass), containmentOnly));
   for (Iterator<EReference> it = targetsToChild.iterator(); it.hasNext(); ) {
     if (fromHierarchy.contains(it.next())) {
       it.remove();
     }
   }
   ArrayList<EReference> rv =
       new ArrayList<EReference>(fromHierarchy.size() + targetsToChild.size());
   rv.addAll(fromHierarchy);
   rv.addAll(targetsToChild);
   return rv;
 }