public static List<EClass> filterByContainmentFeature(
     Collection<EClass> eClasses, MappingEntry mappingEntry) {
   EClass superType = null;
   if (mappingEntry instanceof NodeMapping) {
     NodeReference nodeReference = (NodeReference) mappingEntry.eContainer();
     if (nodeReference != null) {
       EReference modelReference =
           nodeReference.getChildrenFeature() != null
               ? nodeReference.getChildrenFeature()
               : nodeReference.getContainmentFeature();
       if (modelReference != null) {
         superType = modelReference.getEReferenceType();
       }
     }
   } else if (mappingEntry instanceof LinkMapping) {
     if (((LinkMapping) mappingEntry).getContainmentFeature() != null) {
       superType = ((LinkMapping) mappingEntry).getContainmentFeature().getEReferenceType();
     }
   }
   return sort(
       getConcreteEClasses(
           getSubtypesOf(
               filterValidEObjectsFrom(eClasses, mappingEntry.eResource().getResourceSet()),
               superType)));
 }
 @Override
 protected IScope getGlobalScope(final Resource context, final EReference reference) {
   IScope globalScope = super.getGlobalScope(context, reference, null);
   return SelectableBasedScope.createScope(
       globalScope,
       getAllDescriptions(context),
       reference.getEReferenceType(),
       isIgnoreCase(reference));
 }
Exemplo n.º 3
0
 private EObject getOrCreateProxyReference(
     EReference reference, JsonNode root, JsonNode node, Resource resource) {
   EObject obj = findEObject(resource, node);
   if (obj == null) {
     EClass refClass = findEClass(reference.getEReferenceType(), node, root, resource);
     obj = createProxy(resource, refClass, node);
   }
   return obj;
 }
Exemplo n.º 4
0
  private void update(
      EReference ref, EObject eParentObj, EObject eObj, EObject eRef, EObject eDef) {
    if (eObj != null && eObj instanceof DataPointComponent) {
      eDef =
          ChartDefaultValueUtil.getPercentileDataPointDefObj(
              (DataPointComponent) eObj, (DataPointComponent) eDef);
    }

    update(ref.getEReferenceType(), ref.getName(), eParentObj, eObj, eRef, eDef);
  }
Exemplo n.º 5
0
  private EObject createContainedObject(
      EReference reference, JsonNode root, JsonNode node, Resource resource) {
    EClass refClass = findEClass(reference.getEReferenceType(), node, root, resource);
    EObject obj;

    if (isRefNode(node)) {
      obj = createProxy(resource, refClass, node);
    } else {
      obj = createEObject(resource, refClass, node);
    }

    return obj;
  }
  @Override
  public void initialize(IInitializationParticipantContext context, Object facet) {
    if (!(facet instanceof EReference)) return;
    final EReference ref = (EReference) facet;
    if (!ref.isRequired() || ref.isContainer()) return;

    final EObject object = context.getObject();

    if (ref.getUpperBound() != 1) {
      /*
       * A list
       */
      @SuppressWarnings("unchecked")
      final EList<? extends EObject> l =
          (EList<? extends EObject>) context.getStructuralFeature(ref);
      int missing = ref.getLowerBound() - l.size();
      if (missing < 0) return;

      final List<EObject> newChildren = new ArrayList<EObject>(missing);
      for (; missing > 0; missing--) {
        final EObject newChild = EcoreUtil.create(ref.getEReferenceType());
        context.addCommand(
            IManager.Factory.getManager()
                .initializeObject(context.getEditingDomain(), object, ref, newChild, false));
      }
      context.addCommand(AddCommand.create(context.getEditingDomain(), object, ref, newChildren));
    } else {
      /*
       * Simple object
       */
      final Object o = context.getStructuralFeature(ref);
      if (o != null) return;

      final EObject newChild = EcoreUtil.create(ref.getEReferenceType());
      context.addCommand(
          IManager.Factory.getManager()
              .initializeObject(context.getEditingDomain(), object, ref, newChild, true));
    }
  }
 public static Collection<EReference> getEReferencesOfType(
     Collection<EReference> references, EClass referenceType) {
   Collection<EReference> result = getValidEStructuralFeatures(references);
   if (referenceType == null) {
     return result;
   }
   for (Iterator<EReference> it = result.iterator(); it.hasNext(); ) {
     EReference nextFeature = it.next();
     if (nextFeature != null && !nextFeature.getEReferenceType().isSuperTypeOf(referenceType)) {
       it.remove();
     }
   }
   return result;
 }
 /**
  * Retrieves all EClasses from <code>allEClasses</code> that can possibly be referenced by <code>
  * reference</code> and returns them as a list.
  *
  * @param reference the EReference to get EClasses for
  * @param allEClasses set of all possible EClasses
  * @return list of all EClasses that can be referenced by <code>reference</code>
  */
 public static Set<EClass> getReferenceClasses(EReference reference, Set<EClass> allEClasses) {
   Set<EClass> result = new LinkedHashSet<EClass>();
   EClass referenceType = reference.getEReferenceType();
   // 'referenceType: EObject' allows all kinds of EObjects
   if (referenceType.equals(EcorePackage.eINSTANCE.getEObject())) {
     return allEClasses;
   }
   for (EClass eClass : allEClasses) {
     // can eClass be referenced by reference
     if (referenceType.equals(eClass) || referenceType.isSuperTypeOf(eClass)) {
       result.add(eClass);
     }
   }
   return result;
 }
 protected void computeReferencedJvmTypeHighlighting(
     IHighlightedPositionAcceptor acceptor, EObject referencer, CancelIndicator cancelIndicator) {
   for (EReference reference : referencer.eClass().getEAllReferences()) {
     EClass referencedType = reference.getEReferenceType();
     if (EcoreUtil2.isAssignableFrom(TypesPackage.Literals.JVM_TYPE, referencedType)) {
       List<EObject> referencedObjects = EcoreUtil2.getAllReferencedObjects(referencer, reference);
       if (referencedObjects.size() > 0) operationCanceledManager.checkCanceled(cancelIndicator);
       for (EObject referencedObject : referencedObjects) {
         EObject resolvedReferencedObject = EcoreUtil.resolve(referencedObject, referencer);
         if (resolvedReferencedObject != null && !resolvedReferencedObject.eIsProxy()) {
           highlightReferenceJvmType(acceptor, referencer, reference, resolvedReferencedObject);
         }
       }
     }
   }
 }
 private boolean isAssociatorOrDissociatorFor(
     Method method, EReference eReference, final String prefix) {
   if (method.getParameterTypes().length != 1) {
     return false;
   }
   Class paramType = method.getParameterTypes()[0];
   Class referencedType = eReference.getEReferenceType().getInstanceClass();
   if (!paramType.equals(referencedType)) {
     return false;
   }
   String referenceName = eReference.getName();
   String associatorMethodName = prefix + new MethodNameHelper().titleCase(referenceName);
   if (!method.getName().equals(associatorMethodName)) {
     return false;
   }
   return true;
 }
  protected IScope getResourceScope(
      IScope globalScope, @SuppressWarnings("unused") Resource res, EReference reference) {
    IScope result = globalScope;
    ISelectable globalScopeSelectable = new ScopeBasedSelectable(result);

    // implicit imports (i.e. java.lang.*)
    List<ImportNormalizer> normalizers = getImplicitImports(isIgnoreCase(reference));
    if (!normalizers.isEmpty()) {
      result =
          createImportScope(
              result,
              normalizers,
              globalScopeSelectable,
              reference.getEReferenceType(),
              isIgnoreCase(reference));
    }

    return result;
  }
 /**
  * This standard implementation searches the tree for objects of the correct type with a name
  * attribute matching the identifier.
  */
 protected void resolve(
     String identifier,
     ContainerType container,
     org.eclipse.emf.ecore.EReference reference,
     int position,
     boolean resolveFuzzy,
     ssl.resource.ssl.ISslReferenceResolveResult<ReferenceType> result) {
   try {
     org.eclipse.emf.ecore.EClass type = reference.getEReferenceType();
     org.eclipse.emf.ecore.EObject root =
         ssl.resource.ssl.util.SslEObjectUtil.findRootContainer(container);
     // first check whether the root element matches
     boolean continueSearch = checkElement(root, type, identifier, resolveFuzzy, true, result);
     if (!continueSearch) {
       return;
     }
     // then check the contents
     for (java.util.Iterator<org.eclipse.emf.ecore.EObject> iterator = root.eAllContents();
         iterator.hasNext(); ) {
       org.eclipse.emf.ecore.EObject element = iterator.next();
       continueSearch = checkElement(element, type, identifier, resolveFuzzy, true, result);
       if (!continueSearch) {
         return;
       }
     }
     org.eclipse.emf.ecore.resource.Resource resource = container.eResource();
     if (resource != null) {
       org.eclipse.emf.common.util.URI uri = getURI(identifier, resource.getURI());
       if (uri != null) {
         org.eclipse.emf.ecore.EObject element =
             loadResource(container.eResource().getResourceSet(), uri);
         if (element == null) {
           return;
         }
         checkElement(element, type, identifier, resolveFuzzy, false, result);
       }
     }
   } catch (java.lang.RuntimeException rte) {
     // catch exception here to prevent EMF proxy resolution from swallowing it
     rte.printStackTrace();
   }
 }
  @Override
  public boolean isValidValue(Object value) {
    Object adaptedValue = getAdaptedValue(value);
    if (adaptedValue instanceof EObject) {
      // We cannot create objects in a read-only object
      if (EMFHelper.isReadOnly((EObject) adaptedValue)) {
        return false;
      }

      // We need at least one valid containment reference to store this
      // type of object
      for (EReference reference : ((EObject) adaptedValue).eClass().getEAllReferences()) {
        if (reference.isContainment()
            && EMFHelper.isSubclass(this.type, reference.getEReferenceType())) {
          return true;
        }
      }
    }
    return false;
  }
Exemplo n.º 14
0
 /**
  * Returns all containing references where <code>parentClass</code> is the container and <code>
  * childClass</code> the containment.
  *
  * @param childClass the EClass which shall be contained
  * @param parentClass the EClass to get containment references from
  * @return all possible container-references as a set
  */
 public static Set<EReference> getAllPossibleContainingReferences(
     EClass childClass, EClass parentClass) {
   List<EReference> allReferences = parentClass.getEAllContainments();
   Set<EReference> result = new LinkedHashSet<EReference>();
   for (EReference reference : allReferences) {
     EClass referenceType = reference.getEReferenceType();
     if (referenceType == null) {
       continue;
     }
     // is the reference type a perfect match?
     if (referenceType.equals(childClass)) {
       result.add(reference);
       // is the reference type either EObject or a super type?
     } else if (referenceType.equals(EcorePackage.eINSTANCE.getEObject())
         || referenceType.isSuperTypeOf(childClass)) {
       result.add(reference);
     }
   }
   return result;
 }
Exemplo n.º 15
0
	/**
	 * Get a collection from a target object by collection feature., use the
	 * last occurrence in the collection, to get an attribute value. return the
	 * attribute value incremented by 1.
	 * <p>
	 * If this is the first occurence the name will be.
	 * 
	 * <pre>
	 * &ltnew [target Object name] 1&gt
	 * </pre>
	 * 
	 * </p>
	 * @param targetParentObject
	 * @param collectionFeature
	 * @param identityFeature
	 *            An identity attribute which should be of type String.
	 * @return A String incremented by 1.
	 */
	public String nextSequenceNumber(EditingDomain domain,
			EObject targetParentObject, EReference collectionFeature,
			EAttribute identityFeature) {
		int maxSequence = -1;
		String highestIdentity = null;
		if (collectionFeature.isMany()) {
			final List<?> collection = (List<?>) targetParentObject
					.eGet(collectionFeature);

			for (Object child : collection) {
				if (((EObject) child).eIsSet(identityFeature)) {
					final String currentIdentity = (String) ((EObject) child)
							.eGet(identityFeature);
					int currentSequence = currentSequenceNumber(currentIdentity);
					if (currentSequence > maxSequence) {
						maxSequence = currentSequence;
						highestIdentity = currentIdentity;
					}
				}
			}

			if (maxSequence != -1 && highestIdentity != null) {
				return nextIdentity(highestIdentity);

			} else {
				// Note if we can't get a sequence number from the collection,
				// get the last entry and use this...
				if (!collection.isEmpty()) {
					Object object = collection.get(collection.size() - 1);
					final String lastIdentityInSequence = (String) ((EObject) object)
							.eGet(identityFeature);
					
					return lastIdentityInSequence != null ? lastIdentityInSequence + " 1" : "1";
				}
			}
		}

		return "<new "
				+ typeName(domain, targetParentObject,
						collectionFeature.getEReferenceType()) + " 1>";
	}
Exemplo n.º 16
0
 @Override
 public IScope getScope(EObject context, EReference reference) {
   if (context == null) {
     return IScope.NULLSCOPE;
   }
   Resource csResource = context.eResource();
   if (csResource == null) {
     return IScope.NULLSCOPE;
   }
   EClass eReferenceType = reference.getEReferenceType();
   if (eReferenceType == OCLstdlibCSPackage.Literals.JAVA_CLASS_CS) {
     if (csResource instanceof BaseCSResource) {
       AbstractJavaClassScope adapter = JavaClassScope.findAdapter((BaseCSResource) csResource);
       if (adapter == null) {
         EnvironmentFactoryAdapter environmentFactoryAdapter =
             EnvironmentFactoryAdapter.find(csResource);
         if (environmentFactoryAdapter == null) {
           ResourceSet csResourceSet = csResource.getResourceSet();
           if (csResourceSet != null) {
             environmentFactoryAdapter = EnvironmentFactoryAdapter.find(csResourceSet);
           }
         }
         List<@NonNull ClassLoader> classLoaders;
         if (environmentFactoryAdapter != null) {
           classLoaders =
               environmentFactoryAdapter
                   .getMetamodelManager()
                   .getImplementationManager()
                   .getClassLoaders();
         } else {
           classLoaders = Collections.emptyList();
         }
         adapter = JavaClassScope.getAdapter((BaseCSResource) csResource, classLoaders);
       }
       return adapter;
     }
     return IScope.NULLSCOPE;
   }
   return super.getScope(context, reference);
 }
Exemplo n.º 17
0
 public String getClassAssociations(EClass eClass) {
   // if associations exist
   if (eClass.getEReferences().size() > 0) {
     StringBuilder sb = new StringBuilder();
     sb.append("\\subsubsection*{Associations}\n");
     sb.append("\\begin{itemize}\n");
     for (EReference eReference : eClass.getEReferences()) {
       sb.append("\\item ");
       // Name
       sb.append(eReference.getName()).append(": ");
       // Type
       // Works only for internal
       sb.append("\\nameref{").append(eReference.getEReferenceType().getName()).append("} ");
       // Mult
       sb.append(getMultiplicity(eReference)).append(" ");
       // Containement
       if (eReference.isContainment()) {
         sb.append("(containment) ");
       }
       // Description
       if (getLatexDocAnnotation(
               eReference, prefs.getPreferenceString(PreferenceConstants.P_DESCRIPTION_KEY))
           != null) {
         sb.append("\\newline\n")
             .append(
                 getLatexDocAnnotation(
                     eReference,
                     prefs.getPreferenceString(PreferenceConstants.P_DESCRIPTION_KEY)));
       }
       sb.append("\n");
     }
     sb.append("\\end{itemize}");
     return sb.toString();
   }
   return "\\subsubsection*{Associations} ~\\\\ No additional associations";
 }
Exemplo n.º 18
0
 /**
  * Returns all possible EClasses, excluding abstract classes and interfaces, that can be contained
  * when using <code>reference</code>.
  *
  * @param reference the EReference to get containable EClasses for
  * @return a set of all EClasses that can be contained when using <code>reference</code>
  */
 public static List<EClass> getAllEContainments(EReference reference) {
   if (allEContainments.containsKey(reference)) {
     return allEContainments.get(reference);
   }
   if (reference == null) {
     allEContainments.put(reference, new LinkedList<EClass>());
     return allEContainments.get(reference);
   }
   List<EClass> result = new LinkedList<EClass>();
   EClass referenceType = reference.getEReferenceType();
   // no abstracts or interfaces
   if (canHaveInstance(referenceType)) {
     result.add(referenceType);
   }
   // 'referenceType: EObject' allows all kinds of EObjects
   if (EcorePackage.eINSTANCE.getEObject().equals(referenceType)) {
     return getAllEClasses();
   }
   // all sub EClasses can be referenced as well
   result.addAll(getAllSubEClasses(referenceType));
   // save the result for upcoming method calls
   allEContainments.put(reference, result);
   return result;
 }
Exemplo n.º 19
0
  /**
   * Returns {@link IChildCreationSpecification} for children of the specified list.
   *
   * @param l the list
   * @param sibling a possible sibling, if non-<code>null</code>
   * @return the possible top-level children
   */
  public static List<IChildCreationSpecification> getPossibleTopLevelChildObjects(
      IObservableList l, EObject sibling) {
    final List<IChildCreationSpecification> specs = new ArrayList<IChildCreationSpecification>();

    /*
     * Figure out the EReference of the elements
     */
    EObject parent = null;
    EReference ref = null;
    if (l instanceof EObjectEList<?>) {
      final EObjectEList<?> el = (EObjectEList<?>) l;
      final EStructuralFeature sf = el.getEStructuralFeature();
      if (sf instanceof EReference) {
        parent = (EObject) el.getNotifier();
        ref = (EReference) sf;
      }
    }
    if (ref == null && l instanceof MyDetailObservableList) {
      parent = (EObject) ((MyDetailObservableList) l).getObserved();
      ref = (EReference) ((MyDetailObservableList) l).getElementType();
    }
    if (ref == null && l instanceof EObjectObservableList) {
      parent = (EObject) ((EObjectObservableList) l).getObserved();
      ref = (EReference) ((EObjectObservableList) l).getElementType();
    }
    if (ref == null) return specs;
    final EClass childType = ref.getEReferenceType();
    int index = -1;
    if (sibling != null) {
      index = l.indexOf(sibling);
      if (index == -1) return specs;
    }

    UIBindingsUtils.addToChildCreationSpecification(specs, parent, ref, childType, index);
    return specs;
  }
Exemplo n.º 20
0
 protected boolean isTypeScope(EReference reference) {
   return TypesPackage.Literals.JVM_TYPE.isSuperTypeOf(reference.getEReferenceType());
 }
Exemplo n.º 21
0
 protected boolean isConstructorCallScope(EReference reference) {
   return reference.getEReferenceType() == TypesPackage.Literals.JVM_CONSTRUCTOR;
 }
Exemplo n.º 22
0
  // TODO ! need new presentation of set-text-selection command or hide args
  protected void convertSimple(Command command, ICommandFormatter formatter, boolean hasInput) {
    String commandName = CoreUtils.getScriptletNameByClass(command.eClass());
    formatter.addCommandName(commandName);

    Map<EStructuralFeature, Command> bindingMap = new HashMap<EStructuralFeature, Command>();
    for (Binding b : command.getBindings()) {
      bindingMap.put(b.getFeature(), b.getCommand());
    }

    List<EStructuralFeature> attributes = CoreUtils.getFeatures(command.eClass());

    boolean forced = false;
    boolean bigTextCommand =
        commandName.equals("upload-file") || commandName.equals("match-binary");

    for (EStructuralFeature feature : attributes) {
      if (feature.getEAnnotation(CoreUtils.INTERNAL_ANN) != null) continue;
      if (feature.getEAnnotation(CoreUtils.INPUT_ANN) != null && hasInput) continue;
      String name = feature.getName();
      if (isForced(commandName, name)) forced = true;
      Object val = command.eGet(feature);
      boolean skippped = true;
      Object defaultValue = feature.getDefaultValue();
      boolean isDefault = val == null || val.equals(defaultValue);
      if (!isDefault) {
        if (feature instanceof EAttribute) {
          EAttribute attr = (EAttribute) feature;
          String type = attr.getEAttributeType().getInstanceTypeName();
          if (val instanceof List<?>) {
            List<?> list = (List<?>) val;
            for (Object o : list) {
              String value = convertValue(o, type);
              if (value != null) {
                formatter.addAttrName(name, forced);
                formatter.addAttrValue(value);
                skippped = false;
              }
            }
          } else {
            if (val.equals(true)) {
              forced = true;
              formatter.addAttrName(name, forced);
            } else {
              String value = convertValue(val, type);
              if (value != null) {
                formatter.addAttrName(name, forced);
                if (bigTextCommand) formatter.addAttrValueWithLineBreak(value);
                else formatter.addAttrValue(value);
                skippped = false;
              }
            }
          }
        } else {
          EReference ref = (EReference) feature;
          EClass eclass = ref.getEReferenceType();
          if (eclass.getEPackage() == CorePackage.eINSTANCE
              && eclass.getClassifierID() == CorePackage.COMMAND) {
            boolean singleLine = !(val instanceof Sequence);
            formatter.addAttrName(name, forced);
            formatter.openGroup(singleLine);
            doConvert((Command) val, formatter, true);
            formatter.closeGroup(singleLine);
            skippped = false;
          } else {
            IParamConverter<?> converter =
                ParamConverterManager.getInstance().getConverter(eclass.getInstanceClass());
            if (converter != null) {
              try {
                String strVal = String.format("\"%s\"", converter.convertToCode(val));
                formatter.addAttrValue(strVal);
              } catch (CoreException e) {
                CorePlugin.log(e.getStatus());
              }
            }
          }
        }
      } else {
        Command c = bindingMap.get(feature);
        if (c != null) {
          formatter.addAttrName(name, forced);
          formatter.openExec();
          doConvert(c, formatter, hasInput);
          formatter.closeExec();
          skippped = false;
        }
      }
      if (skippped) forced = true;
    }
  }
  protected IScope getLocalElementsScope(
      IScope parent, IScope globalScope, EObject context, EReference reference) {
    IScope result = parent;
    QualifiedName name = getQualifiedNameOfLocalElement(context);
    boolean ignoreCase = isIgnoreCase(reference);
    ISelectable resourceOnlySelectable = getAllDescriptions(context.eResource());
    ISelectable globalScopeSelectable = new ScopeBasedSelectable(globalScope);

    // imports
    List<ImportNormalizer> explicitImports = getImportedNamespaceResolvers(context, ignoreCase);
    if (!explicitImports.isEmpty()) {
      result =
          createImportScope(
              result,
              explicitImports,
              globalScopeSelectable,
              reference.getEReferenceType(),
              ignoreCase);
    }

    // local element
    if (name != null) {
      ImportNormalizer localNormalizer = doCreateImportNormalizer(name, true, ignoreCase);
      result =
          createImportScope(
              result,
              singletonList(localNormalizer),
              resourceOnlySelectable,
              reference.getEReferenceType(),
              ignoreCase);
    }

    // scope for jvm elements
    Set<EObject> elements = associations.getJvmElements(context);
    for (EObject derivedJvmElement : elements) {
      // scope for JvmDeclaredTypes
      if (derivedJvmElement instanceof JvmDeclaredType) {
        JvmDeclaredType declaredType = (JvmDeclaredType) derivedJvmElement;
        QualifiedName jvmTypeName = getQualifiedNameOfLocalElement(declaredType);
        if (declaredType.getDeclaringType() == null
            && !Strings.isEmpty(declaredType.getPackageName())) {
          QualifiedName packageName =
              this.qualifiedNameConverter.toQualifiedName(declaredType.getPackageName());
          ImportNormalizer normalizer = doCreateImportNormalizer(packageName, true, ignoreCase);
          result =
              createImportScope(
                  result,
                  singletonList(normalizer),
                  globalScopeSelectable,
                  reference.getEReferenceType(),
                  ignoreCase);
        }
        if (jvmTypeName != null && !jvmTypeName.equals(name)) {
          ImportNormalizer localNormalizer =
              doCreateImportNormalizer(jvmTypeName, true, ignoreCase);
          result =
              createImportScope(
                  result,
                  singletonList(localNormalizer),
                  resourceOnlySelectable,
                  reference.getEReferenceType(),
                  ignoreCase);
        }
      }
      // scope for JvmTypeParameterDeclarator
      if (derivedJvmElement instanceof JvmTypeParameterDeclarator) {
        JvmTypeParameterDeclarator parameterDeclarator =
            (JvmTypeParameterDeclarator) derivedJvmElement;
        List<IEObjectDescription> descriptions = null;
        for (JvmTypeParameter param : parameterDeclarator.getTypeParameters()) {
          if (param.getSimpleName() != null) {
            if (descriptions == null) descriptions = Lists.newArrayList();
            QualifiedName paramName = QualifiedName.create(param.getSimpleName());
            descriptions.add(EObjectDescription.create(paramName, param));
          }
        }
        if (descriptions != null && !descriptions.isEmpty())
          result = MapBasedScope.createScope(result, descriptions);
      }
    }
    return result;
  }
Exemplo n.º 24
0
  /**
   * Converts the value of an EReference with isMany==true, the values of the collection are
   * converted to EObjects and added to the list in the correct feature in the eObject.
   *
   * @param modelObject the modelObject from which the value is retrieved.
   * @param eObject the eObject in which the value is set (after it has been converted)
   * @param eReference the eReference which is converted
   */
  protected void convertManyEReference(
      final ModelObject<?> modelObject, final EObject eObject, final EReference eReference) {
    // container feature is always set from the other side, the containment
    // side
    if (eReference.isContainer()) {
      return;
    }

    final Object manyValue = modelObject.eGet(eReference);
    final Collection<EObject> newValues = new ArrayList<EObject>();

    boolean isMap = Map.class.isAssignableFrom(manyValue.getClass());
    EStructuralFeature valueFeature = null;
    EStructuralFeature keyFeature = null;
    if (isMap) {
      final EClass mapEClass = eReference.getEReferenceType();
      valueFeature = mapEClass.getEStructuralFeature("value"); // $NON-NLS-1$
      keyFeature = mapEClass.getEStructuralFeature("key"); // $NON-NLS-1$

      Check.isTrue(
          ModelUtils.isEMap(eReference),
          "Expected emap EReference, but th// case for EReference " //$NON-NLS-1$
              + eReference);

      final Map<?, ?> map = (Map<?, ?>) manyValue;

      for (final Object key : map.keySet()) {
        final Object value = map.get(key);
        final EObject mapEntryEObject = EcoreUtil.create(mapEClass);

        // key and value maybe primitive types but can also be
        // references to model objects.
        if (valueFeature instanceof EReference) {
          mapEntryEObject.eSet(valueFeature, createTarget(value));
        } else {
          mapEntryEObject.eSet(valueFeature, value);
        }
        if (keyFeature instanceof EReference) {
          mapEntryEObject.eSet(keyFeature, createTarget(key));
        } else {
          mapEntryEObject.eSet(keyFeature, key);
        }
        newValues.add(mapEntryEObject);
      }
    } else {

      // a many to many
      if (eReference.getEOpposite() != null && eReference.getEOpposite().isMany()) {
        final ManyToMany mtm = new ManyToMany();
        mtm.setOwner(modelObject);
        mtm.setEReference(eReference);
        toRepairManyToMany.add(mtm);
      }

      @SuppressWarnings("unchecked")
      final Collection<Object> values = (Collection<Object>) manyValue;

      for (final Object value : values) {
        if (value == null) {
          newValues.add(null);
        } else {
          final InternalEObject eValue = (InternalEObject) createTarget(value);
          if (!newValues.contains(eValue)) {
            newValues.add(eValue);
          }
        }
      }
    }

    @SuppressWarnings("unchecked")
    final Collection<EObject> eValues = (Collection<EObject>) eObject.eGet(eReference);

    boolean updateList = false;
    if (newValues.size() == eValues.size()) {
      final Iterator<?> it = eValues.iterator();
      for (Object newValue : newValues) {
        final Object oldValue = it.next();

        if (isMap) {
          final EObject oldMapEntry = (EObject) oldValue;
          final EObject newMapEntry = (EObject) newValue;
          final Object oldMapValue = oldMapEntry.eGet(valueFeature);
          final Object oldMapKey = oldMapEntry.eGet(keyFeature);
          final Object newMapValue = newMapEntry.eGet(valueFeature);
          final Object newMapKey = newMapEntry.eGet(keyFeature);
          if (valueFeature instanceof EReference) {
            updateList = oldMapValue == newMapValue;
          } else {
            updateList =
                oldMapValue != null
                    ? !oldMapValue.equals(newMapValue)
                    : newMapValue != null ? !newMapValue.equals(oldMapValue) : false;
          }
          if (keyFeature instanceof EReference) {
            updateList = updateList || oldMapKey == newMapKey;
          } else {
            updateList =
                updateList
                    || (oldMapKey != null
                        ? !oldMapKey.equals(newMapKey)
                        : newMapKey != null ? !newMapKey.equals(oldMapKey) : false);
          }
        } else {
          updateList = oldValue != newValue;
        }

        if (updateList) {
          break;
        }
      }
    } else {
      updateList = true;
    }

    if (updateList) {
      // clear the evalues so that an empty tag is created in the xml
      eValues.clear();
      eValues.addAll(newValues);
    }
  }