InternalEObject eContainer = ((InternalEObject)eObject).eInternalContainer(); while (eContainer != null)
int count = 0; for (InternalEObject eContainer = ((InternalEObject)eObject).eInternalContainer(); eContainer != null && eContainer != eObject; eContainer = eContainer.eInternalContainer())
  public static boolean isAncestor(EObject ancestorEObject, EObject eObject)  {    if (eObject != null)    {      if (eObject == ancestorEObject)      {        return true;      }            InternalEObject eContainer = ((InternalEObject)eObject).eInternalContainer();      while (eContainer != null)      {        if (eContainer == ancestorEObject)        {          return true;        }        eContainer = eContainer.eInternalContainer();      }    }    return false;  }