public static boolean affects(Notification notification, EClass clz) {
   if (notification.isTouch()) {
     return false;
   }
   switch (notification.getEventType()) {
     case Notification.ADD:
     case Notification.SET:
       return clz.isInstance(notification.getNewValue());
     case Notification.REMOVE:
     case Notification.UNSET:
       return clz.isInstance(notification.getOldValue());
     case Notification.ADD_MANY:
       return affects(notification.getNewValue(), clz);
     case Notification.REMOVE_MANY:
       return affects(notification.getOldValue(), clz);
     case Notification.MOVE:
       if (notification.getNotifier() instanceof EObject
           && notification.getFeature() instanceof EStructuralFeature) {
         return affects(
             ((EObject) notification.getNotifier())
                 .eGet((EStructuralFeature) notification.getFeature()),
             clz);
       }
       return false;
   }
   return false;
 }
 public static Collection<EObject> getAffectedValues(Notification notification, EClass clz) {
   if (notification.isTouch()) {
     return Collections.emptyList();
   }
   switch (notification.getEventType()) {
     case Notification.ADD:
     case Notification.SET:
       if (clz.isInstance(notification.getNewValue())) {
         return Collections.singletonList((EObject) notification.getNewValue());
       }
       return Collections.emptyList();
     case Notification.REMOVE:
     case Notification.UNSET:
       if (clz.isInstance(notification.getOldValue())) {
         return Collections.singletonList((EObject) notification.getOldValue());
       }
     case Notification.ADD_MANY:
       return affectingObjects(notification.getNewValue(), clz);
     case Notification.REMOVE_MANY:
       return affectingObjects(notification.getOldValue(), clz);
     case Notification.MOVE:
       if (notification.getNotifier() instanceof EObject
           && notification.getFeature() instanceof EStructuralFeature) {
         return affectingObjects(
             ((EObject) notification.getNotifier())
                 .eGet((EStructuralFeature) notification.getFeature()),
             clz);
       }
       return Collections.emptyList();
   }
   return Collections.emptyList();
 }
 /** Returns true if the given object is an instance of one of the EClasses. */
 public boolean isInstance(Object object, org.eclipse.emf.ecore.EClass[] allowedTypes) {
   for (org.eclipse.emf.ecore.EClass allowedType : allowedTypes) {
     if (allowedType.isInstance(object)) {
       return true;
     }
   }
   return false;
 }
 private static boolean affects(Object list, EClass clz) {
   if (list instanceof Collection<?>) {
     for (Object next : ((Collection<?>) list)) {
       if (clz.isInstance(next)) {
         return true;
       }
     }
   }
   return false;
 }
 /**
  *
  * <!-- begin-user-doc -->
  * <!-- end-user-doc -->
  *
  * @generated
  */
 public RedefinableElement getRedefinedElement(String name, boolean ignoreCase, EClass eClass) {
   redefinedElementLoop:
   for (RedefinableElement redefinedElement : getRedefinedElements()) {
     if (eClass != null && !eClass.isInstance(redefinedElement)) continue redefinedElementLoop;
     if (name != null
         && !(ignoreCase
             ? name.equalsIgnoreCase(redefinedElement.getName())
             : name.equals(redefinedElement.getName()))) continue redefinedElementLoop;
     return redefinedElement;
   }
   return null;
 }
  /** {@inheritDoc} */
  public Collection<EObject> getAllModelElementsbyClass(EClass clazz, boolean association) {
    Collection<EObject> ret = new BasicEList<EObject>();

    for (EObject element : getAllModelElements()) {
      if ((element.eClass() == clazz || clazz.isInstance(element))
          && (association || !getMetaModelElementContext().isAssociationClassElement(element))) {
        ret.add(element);
      }
    }

    return ret;
  }
 /**
  *
  * <!-- begin-user-doc -->
  * <!-- end-user-doc -->
  *
  * @generated
  */
 public Classifier getRedefinitionContext(String name, boolean ignoreCase, EClass eClass) {
   redefinitionContextLoop:
   for (Classifier redefinitionContext : getRedefinitionContexts()) {
     if (eClass != null && !eClass.isInstance(redefinitionContext))
       continue redefinitionContextLoop;
     if (name != null
         && !(ignoreCase
             ? name.equalsIgnoreCase(redefinitionContext.getName())
             : name.equals(redefinitionContext.getName()))) continue redefinitionContextLoop;
     return redefinitionContext;
   }
   return null;
 }
 @Override
 public boolean select(
     org.eclipse.jface.viewers.Viewer viewer, Object parentElement, Object element) {
   if (element instanceof org.eclipse.emf.ecore.EObject) {
     org.eclipse.emf.ecore.EObject eObject = (org.eclipse.emf.ecore.EObject) element;
     for (org.eclipse.emf.ecore.EClass filteredType : filteredTypes) {
       if (filteredType.isInstance(eObject)) {
         return false;
       }
     }
   }
   return true;
 }
 /**
  * Walks up the containment hierarchy to find an EObject that is able to hold (contain) the given
  * object.
  */
 protected EObject findHookParent(
     EObject container,
     EClass startClass,
     org.emftext.language.xpath3.resource.xpath3.mopp.Xpath3ContainedFeature currentLink,
     EObject object) {
   EClass containerClass = currentLink.getContainerClass();
   while (container != null) {
     if (containerClass.isInstance(object)) {
       if (startClass.equals(container.eClass())) {
         return container;
       }
     }
     container = container.eContainer();
   }
   return null;
 }
 private static Collection<EObject> affectingObjects(Object list, EClass clz) {
   Collection<EObject> result = null;
   if (list instanceof Collection<?>) {
     for (Object next : ((Collection<?>) list)) {
       if (clz.isInstance(next)) {
         if (result == null) {
           result = new BasicEList<EObject>();
         }
         result.add((EObject) next);
       }
     }
   }
   if (result != null) {
     return result;
   }
   return Collections.emptyList();
 }
 /**
  *
  * <!-- begin-user-doc -->
  * <!-- end-user-doc -->
  *
  * @generated
  */
 public Property getPropertyPath(String name, Type type, boolean ignoreCase, EClass eClass) {
   propertyPathLoop:
   for (Property propertyPath : getPropertyPath()) {
     if (eClass != null && !eClass.isInstance(propertyPath)) {
       continue propertyPathLoop;
     }
     if (name != null
         && !(ignoreCase
             ? name.equalsIgnoreCase(propertyPath.getName())
             : name.equals(propertyPath.getName()))) {
       continue propertyPathLoop;
     }
     if (type != null && !type.equals(propertyPath.getType())) {
       continue propertyPathLoop;
     }
     return propertyPath;
   }
   return null;
 }
  protected EObject findCorrectContainer(
      org.emftext.language.xpath3.resource.xpath3.mopp.Xpath3ExpectedTerminal expectedTerminal) {
    EObject container = expectedTerminal.getContainer();
    EClass ruleMetaclass = expectedTerminal.getTerminal().getRuleMetaclass();
    if (ruleMetaclass.isInstance(container)) {
      // container is correct for expected terminal
      return container;
    }
    // the container is wrong
    EObject parent = null;
    EObject previousParent = null;
    EObject correctContainer = null;
    EObject hookableParent = null;
    org.emftext.language.xpath3.resource.xpath3.grammar.Xpath3ContainmentTrace containmentTrace =
        expectedTerminal.getContainmentTrace();
    EClass startClass = containmentTrace.getStartClass();
    org.emftext.language.xpath3.resource.xpath3.mopp.Xpath3ContainedFeature currentLink = null;
    org.emftext.language.xpath3.resource.xpath3.mopp.Xpath3ContainedFeature previousLink = null;
    org.emftext.language.xpath3.resource.xpath3.mopp.Xpath3ContainedFeature[] containedFeatures =
        containmentTrace.getPath();
    for (int i = 0; i < containedFeatures.length; i++) {
      currentLink = containedFeatures[i];
      if (i > 0) {
        previousLink = containedFeatures[i - 1];
      }
      EClass containerClass = currentLink.getContainerClass();
      hookableParent = findHookParent(container, startClass, currentLink, parent);
      if (hookableParent != null) {
        // we found the correct parent
        break;
      } else {
        previousParent = parent;
        parent = containerClass.getEPackage().getEFactoryInstance().create(containerClass);
        if (parent != null) {
          if (previousParent == null) {
            // replace container for expectedTerminal with correctContainer
            correctContainer = parent;
          } else {
            // This assignment is only performed to get rid of a warning about a potential
            // null pointer access. Variable 'previousLink' cannot be null here, because it is
            // initialized for all loop iterations where 'i' is greather than 0 and for the
            // case where 'i' equals zero, this path is never executed, because
            // 'previousParent' is null in this case.
            org.emftext.language.xpath3.resource.xpath3.mopp.Xpath3ContainedFeature link =
                previousLink;
            org.emftext.language.xpath3.resource.xpath3.util.Xpath3EObjectUtil.setFeature(
                parent, link.getFeature(), previousParent, false);
          }
        }
      }
    }

    if (correctContainer == null) {
      correctContainer = container;
    }

    if (currentLink == null) {
      return correctContainer;
    }

    hookableParent = findHookParent(container, startClass, currentLink, parent);

    final EObject finalHookableParent = hookableParent;
    final EStructuralFeature finalFeature = currentLink.getFeature();
    final EObject finalParent = parent;
    if (parent != null && hookableParent != null) {
      expectedTerminal.setAttachmentCode(
          new Runnable() {

            public void run() {
              org.emftext.language.xpath3.resource.xpath3.util.Xpath3EObjectUtil.setFeature(
                  finalHookableParent, finalFeature, finalParent, false);
            }
          });
    }
    return correctContainer;
  }
Example #13
0
 /**
  * Transitively find the parent of type <code>container</code> of <code>element</code>. If <code>
  * element</code> is already of type <code>container</code>, the element will be returned.
  *
  * @param element An arbitrary {@link EObject}.
  * @param container The parent type we are looking for.
  * @return The parent of <code>element</code> of type <code>container</code> or <code>null</code>,
  *     if none is found.
  */
 public static EObject getContainerOfType(EObject element, EClass container) {
   if (element == null || container == null) return null;
   if (container.isInstance(element)) return element;
   return getContainerOfType(element.eContainer(), container);
 }