public static string getID(EObject eObject)
        {
            EClass     eClass       = eObject.eClass();
            EAttribute eIDAttribute = eClass.eIDAttribute;

            return(eIDAttribute == null || !eObject.eIsSet(eIDAttribute) ? null : convertToString(
                       eIDAttribute.eAttributeType,
                       eObject.eGet(eIDAttribute)));
        }
Exemple #2
0
        private EObject resolveRecurr(Queue <String> path, EObject current)
        {
            if (path.Count == 0)
            {
                return(current);
            }

            String segment = path.Dequeue();

            foreach (EStructuralFeature feature in current.eClass().eAllContainments)
            {
                if (segment.StartsWith("@"))
                {
                    var startIndex  = 1;
                    var endIndex    = segment.LastIndexOf(".");
                    var length      = endIndex - startIndex;
                    var featurename = segment.Substring(startIndex, length);

                    if (feature.name == featurename)
                    {
                        var length2     = segment.Length - endIndex - 1;
                        var array_index = Int32.Parse(segment.Substring(endIndex + 1, length2));

                        var enumerable = current.eGet(feature) as IEnumerable <EObject>;

                        var list = enumerable.ToList();

                        //TODO list of primitives/objects?

                        var item = list[array_index];

                        return(resolveRecurr(path, item));
                    }
                }
                else if (feature.name == segment)
                {
                    return(resolveRecurr(path, current.eGet(feature) as EObject));
                }
            }


            return(null);
        }
        private String value(EObject eobject, EAttribute attribute)
        {
            var classifier = attribute.eType;

            if (classifier.Equals(EcorePackageImpl.Literals.EBOOLEAN))
            {
                return($"{eobject.eGet(attribute)}");
            }
            else if (classifier.Equals(EcorePackageImpl.Literals.EINT))
            {
                return($"{eobject.eGet(attribute)}");
            }
            else if (classifier.Equals(EcorePackageImpl.Literals.EDOUBLE))
            {
                return($"{eobject.eGet(attribute)}");
            }
            else if (classifier.Equals(EcorePackageImpl.Literals.EFLOAT))
            {
                return($"{eobject.eGet(attribute)}");
            }
            else if (classifier.Equals(EcorePackageImpl.Literals.ESTRING))
            {
                return($"\"{eobject.eGet(attribute)}\"");
            }
            else if (classifier.Equals(EcorePackageImpl.Literals.ECHAR))
            {
                return($"\"{eobject.eGet(attribute)}\"");
            }
            else
            {
                throw new ArgumentException();
            }
        }
        private Collection <EAttribute> validEAllAttributes(EObject eobject, Collection <EAttribute> features)
        {
            var result = new Set <EAttribute>();

            foreach (EAttribute feature in features)
            {
                if (!feature.transient)
                {
                    if (eobject.eGet(feature) != null)
                    {
                        if (feature.many && !(eobject.eGet(feature) as Collection <Object>).isEmpty())
                        {
                            result.add(feature);
                        }
                        else if (!feature.many)
                        {
                            result.add(feature);
                        }
                    }
                }
            }
            return(result);
        }
        public String serialize(EObject eobject)
        {
            var eClass = eobject.eClass();

            var references = validEAllReferences(eobject, eClass.eAllReferences);
            var attributes = validEAllAttributes(eobject, eClass.eAllAttributes);

            var sb = new StringBuilder();

            sb.Append("{");
            {
                sb.Append($"\"{eClass.name}\":");
                sb.Append("{");
                {
                    var i3 = 0;
                    foreach (EReference ereference in references)
                    {
                        if (ereference.containment)
                        {
                            if (ereference.many)
                            {
                                sb.Append($"\"{ereference.name}\":");
                                var items = eobject.eGet(ereference) as Collection <EObject>;

                                sb.Append("[");
                                {
                                    var i = 0;
                                    foreach (EObject item in items)
                                    {
                                        sb.Append(serialize(item));

                                        if (i < items.size() - 1)
                                        {
                                            sb.Append(", ");
                                        }

                                        i++;
                                    }
                                }
                                sb.Append("]");
                            }
                            else
                            {
                                sb.Append($"\"{ereference.name}\": {serialize(eobject.eGet(ereference) as EObject)}");
                            }
                        }
                        else
                        {
                            if (ereference.many)
                            {
                                var items = eobject.eGet(ereference) as Collection <EObject>;
                                sb.Append("[");
                                {
                                    var i = 0;
                                    foreach (EObject item in items)
                                    {
                                        sb.Append(item.GetHashCode());

                                        if (i < items.size() - 1)
                                        {
                                            sb.Append(", ");
                                        }

                                        i++;
                                    }
                                }
                                sb.Append("]");
                            }
                            else
                            {
                                sb.Append($"\"{ereference.name}\": \"{eobject.eGet(ereference).GetHashCode()}\"");
                            }
                        }

                        if (i3 < attributes.size() - 1)
                        {
                            sb.Append(", ");
                        }

                        i3++;
                    }
                    if (!references.isEmpty() && !attributes.isEmpty())
                    {
                        sb.Append(", ");
                    }

                    var i2 = 0;
                    foreach (var attribute in attributes)
                    {
                        sb.Append($"\"{attribute.name}\": \"{eobject.eGet(attribute).ToString()}\"");


                        if (i2 < attributes.size() - 1)
                        {
                            sb.Append(", ");
                        }

                        i2++;
                    }
                }
                sb.Append("}");
            }
            sb.Append("}");

            return(sb.ToString());
        }
Exemple #6
0
        private void saveRecurr(EObject eobject, EReference relation)
        {
            if (eobject == null)
            {
                return;
            }

            var xmlAttributes = new Dictionary <string, string>();

            //xsi:type="ecore:EAttribute"

            var eclass  = eobject.eClass();
            var epackag = eclass.ePackage;

            if (epackag == null)
            {
                return;
            }
            var prefix = epackag.nsPrefix;

            xmlAttributes["xsi:type"] = eobject.eClass().ePackage.nsPrefix + ":" + eobject.eClass().name;

            foreach (EStructuralFeature feature in eobject.eClass().eAllStructuralFeatures)
            {
                if (feature is EReference)
                {
                    var erference = feature as EReference;

                    if (erference.many)
                    {
                        //TODO
                    }
                    else
                    {
                        var value = eobject.eGet(erference) as EObject;
                        if (value != null)
                        {
                            xmlAttributes[erference.name] = getFragment(value);
                        }
                    }

                    if (erference.containment)
                    {
                        var child = eobject.eGet(erference);

                        if (child != null)
                        {
                            if (erference.many)
                            {
                                var list = (IList)child;

                                var list2 = list.Cast <EObject>();
                                foreach (EObject c in list)
                                {
                                    saveRecurr(c, erference);
                                }
                            }
                            else
                            {
                                saveRecurr(child as EObject, erference);//TODO is casting safe here?
                            }
                        }
                    }
                }
                else if (feature is EAttribute)
                {
                    var eattribute = feature as EAttribute;

                    if (!eattribute.transient && !eattribute.derived && eattribute.defaultValue != eobject.eGet(eattribute))
                    {
                        //TODO many

                        xmlAttributes[eattribute.name] = eobject.eGet(eattribute).ToString();
                    }
                }
            }

            if (relation != null)
            {
                var sb = new StringBuilder();
                sb.Append($"<{relation.name}");
                foreach (String key in xmlAttributes.Keys)
                {
                    sb.Append($"{key}=\"{xmlAttributes[key]}\"");
                }
                sb.Append($">");
                //TODO childs
                sb.Append($"</{relation.name}>");
                Console.WriteLine(sb.ToString());
            }
        }
Exemple #7
0
        private string getFragment(EObject eobject)
        {
            EAttribute idfeature = eobject.eClass().eIDAttribute;

            return($"#//{eobject.eGet(idfeature)}");
        }
Exemple #8
0
        private void addEStructuralFeatures(EObject eobject, XmlNode node)
        {
            foreach (XmlAttribute attribute in node.Attributes)
            {
                var name = attribute.Name;
                var estructuralfeature = eobject.eClass().getEStructuralFeature(name);


                if (estructuralfeature is EAttribute && (estructuralfeature as EAttribute).iD)
                {
                    var id = attribute.InnerText;
                    registry[id] = eobject;
                }


                if (estructuralfeature is EAttribute)
                {
                    if (!estructuralfeature.many)
                    {
                        var etype = estructuralfeature.eType;
                        var value = attribute.InnerText;

                        if (etype?.ePackage?.nsURI == "http://www.eclipse.org/emf/2002/Ecore")
                        {
                            if (etype.name == "EBigDecimal")
                            {
                                throw new NotImplementedException();
                            }
                            else if (etype.name == "EBigInteger")
                            {
                                throw new NotImplementedException();
                            }
                            else if (etype.name == "EBoolean")
                            {
                                eobject.eSet(estructuralfeature, value == "true" ? true : false);
                            }
                            else if (etype.name == "EBooleanObject")
                            {
                                throw new NotImplementedException();
                            }
                            else if (etype.name == "EByteArray")
                            {
                                throw new NotImplementedException();
                            }
                            else if (etype.name == "EByteObject")
                            {
                                throw new NotImplementedException();
                            }
                            else if (etype.name == "EChar")
                            {
                                eobject.eSet(estructuralfeature, value[0]);
                            }
                            else if (etype.name == "ECharacterObject")
                            {
                                throw new NotImplementedException();
                            }
                            else if (etype.name == "EDateEDiagnosticChain")
                            {
                                throw new NotImplementedException();
                            }
                            else if (etype.name == "EDiagnosticChain")
                            {
                                throw new NotImplementedException();
                            }
                            else if (etype.name == "EDouble")
                            {
                                eobject.eSet(estructuralfeature, Double.Parse(value));
                            }
                            else if (etype.name == "EDoubleObject")
                            {
                                throw new NotImplementedException();
                            }
                            //EEList
                            //EEnumerator
                            //EFeatureMap
                            //EFeatureMapEntry
                            else if (etype.name == "EFloat")
                            {
                                eobject.eSet(estructuralfeature, Single.Parse(value));
                            }
                            else if (etype.name == "EFloatObject")
                            {
                                throw new NotImplementedException();
                            }
                            else if (etype.name == "EInt")
                            {
                                eobject.eSet(estructuralfeature, Int32.Parse(value));
                            }
                            else if (etype.name == "EIntegerObject")
                            {
                                throw new NotImplementedException();
                            }
                            //EJavaClass
                            //EJavaObject
                            else if (etype.name == "ELong")
                            {
                                eobject.eSet(estructuralfeature, Int64.Parse(value));
                            }
                            else if (etype.name == "ELongObject")
                            {
                                throw new NotImplementedException();
                            }
                            //EMap
                            //EResource
                            //EResourceSet
                            else if (etype.name == "EShort")
                            {
                                eobject.eSet(estructuralfeature, Int16.Parse(value));
                            }
                            else if (etype.name == "EShortObject")
                            {
                                throw new NotImplementedException();
                            }
                            else if (etype.name == "EString")
                            {
                                eobject.eSet(estructuralfeature, value);
                            }
                            //ETreeIterator
                            //EInvocationTargetException
                        }
                        else if (etype is EDataType)
                        {
                            var literalvalue = this.factory.createFromString(etype as EDataType, value);
                            eobject.eSet(estructuralfeature, literalvalue);
                        }
                    }
                    else if (estructuralfeature.many)
                    {
                        var y = 3;
                    }
                    else
                    {
                        var x = 2;
                    }
                }
                else if (estructuralfeature is EReference)
                {
                    this.resolve(eobject, estructuralfeature, attribute.InnerText);
                }
            }


            foreach (XmlNode child in node.ChildNodes)
            {
                var containment_name = child.Name;
                var containment      = eobject.eClass().getEStructuralFeature(containment_name);

                if (containment is EReference)
                {
                    var containment_er = containment as EReference;
                    if (containment_er.containment)
                    {
                        var classifierId2 = containment.eType.name;

                        if (child.Attributes["xsi:type"] != null)
                        {
                            //use xsi:type to declare a more specific type that is declared in EType of the EReference
                            classifierId2 = child.Attributes["xsi:type"]?.InnerText?.Split(':')[1];//TODO there might be more elegant ways
                        }

                        var eclassifier2 = epackage.getEClassifier(classifierId2);

                        if (eclassifier2 is EClass)
                        {
                            if (containment_er.eType.name == "EStringToStringMapEntry")
                            {
                                //new EcoreEMap<string, string> x = new EcoreEMap<string, string>(containment_er.eType as EClass, containment_er.eType.instanceClass, eobject as InternalEObject, containment_er.getFeatureID());



                                var key   = child.Attributes["key"].InnerText;
                                var value = child.Attributes["value"].InnerText;

                                dynamic bla = eobject;

                                //FIXME why is eGet(containment_er) not working?

                                dynamic map = bla.eGet(containment_er);
                                //var map = bla.eGet(containment_er.getFeatureID(), false, false);
                                //var ecoremap = map as EcoreEMap<string, string>;



                                //https://stackoverflow.com/questions/19283349/c-sharp-generics-wildcards
                                map.put(key, value);
                            }
                            else
                            {
                                var eclass2  = eclassifier2 as EClass;
                                var eobject2 = factory.create(eclass2);

                                if (containment_er.many)
                                {
                                    addEStructuralFeatures(eobject2, child);

                                    var list = (eobject.eGet(containment_er) as IEnumerable <EObject>).ToList();

                                    list.Add(eobject2);

                                    eobject.eSet(containment_er, list);
                                }
                                else
                                {
                                    addEStructuralFeatures(eobject2, child);

                                    eobject.eSet(containment_er, eobject2);
                                }
                            }
                        }
                    }
                    else
                    {
                        //TODO error
                    }
                }
                else
                {
                    //TODO error
                }
            }
        }
        protected bool validate_DataValueConforms(EObject eObject, EAttribute eAttribute, DiagnosticChain diagnostics, Dictionary <object, object> context)
        {
            if (!eObject.eIsSet(eAttribute))
            {
                return(true);
            }
            bool      result    = true;
            EDataType eDataType = eAttribute.eAttributeType;

            EValidator rootValidator = getRootEValidator(context);
            object     value         = eObject.eGet(eAttribute);

            /*
             * if (FeatureMapUtil.isFeatureMap(eAttribute))
             * {
             *  Collection<FeatureMap.Entry> featureMap = (Collection<FeatureMap.Entry>)value;
             *  EClass eClass = eObject.eClass();
             *  Dictionary<EStructuralFeature, DiagnosticChain> entryFeatureToDiagnosticChainMap = null;
             *  for (Iterator<FeatureMap.Entry> i = featureMap.iterator(); i.hasNext() && (result || diagnostics != null);)
             *  {
             *      FeatureMap.Entry entry = i.next();
             *      EStructuralFeature entryFeature = entry.getEStructuralFeature();
             *      if (entryFeature instanceof EAttribute &&
             *            ExtendedMetaData.INSTANCE.getAffiliation(eClass, entryFeature) == eAttribute)
             *      {
             *          EDataType entryType = (EDataType)entryFeature.getEType();
             *          Object entryValue = entry.getValue();
             *          bool entryIsValid = rootValidator.validate(entryType, entryValue, null, context);
             *          if (!entryIsValid)
             *          {
             *              result = false;
             *              if (diagnostics != null)
             *              {
             *                  if (entryFeatureToDiagnosticChainMap == null)
             *                  {
             *                      entryFeatureToDiagnosticChainMap = new HashMap<EStructuralFeature, DiagnosticChain>();
             *                  }
             *                  DiagnosticChain entryFeatureDiagnostic = entryFeatureToDiagnosticChainMap.get(entryFeature);
             *                  if (entryFeatureDiagnostic == null)
             *                  {
             *                      entryFeatureDiagnostic = createBadDataValueDiagnostic(eObject, (EAttribute)entryFeature, diagnostics, context);
             *                      entryFeatureToDiagnosticChainMap.put(entryFeature, entryFeatureDiagnostic);
             *                  }
             *                  rootValidator.validate(entryType, entryValue, entryFeatureDiagnostic, context);
             *              }
             *          }
             *      }
             *  }
             * }
             * else*/
            if (eAttribute.many)
            {
                foreach (object item in value as IList <object> )
                {
                    result &= rootValidator.validate(eDataType, item, null, context);
                }


                if (!result && diagnostics != null)
                {
                    DiagnosticChain diagnostic = createBadDataValueDiagnostic(eObject, eAttribute, diagnostics, context);

                    foreach (object item in value as IList <object> )
                    {
                        rootValidator.validate(eDataType, item, diagnostic, context);
                    }
                }
            }
            else if (value != null)
            {
                result = rootValidator.validate(eDataType, value, null, context);
                if (!result && diagnostics != null)
                {
                    DiagnosticChain diagnostic = createBadDataValueDiagnostic(eObject, eAttribute, diagnostics, context);
                    rootValidator.validate(eDataType, value, diagnostic, context);
                }
            }

            return(result);
        }
        public bool validate_EveryReferenceIsContained(EObject eObject, DiagnosticChain diagnostics, Dictionary <object, object> context)
        {
            bool result = true;

            if (eObject.eResource() != null)
            {
                foreach (EReference reference in eObject.eClass().eAllReferences)
                {
                    if (eObject.eIsSet(reference))
                    {
                        EObject eCrossReferenceObject = eObject.eGet(reference) as EObject;

                        if (eCrossReferenceObject.eResource() == null && !eCrossReferenceObject.eIsProxy() && !reference.transient)
                        {
                            result = false;
                            if (diagnostics != null)
                            {
                                diagnostics.add
                                    (createDiagnostic
                                        (BasicDiagnostic.ERROR,
                                        DIAGNOSTIC_SOURCE,
                                        EOBJECT__EVERY_REFERENCE_IS_CONTAINED,
                                        "_UI_DanglingReference_diagnostic",
                                        new Object[]
                                {
                                    getFeatureLabel(reference, context),
                                    getObjectLabel(eObject, context),
                                    getObjectLabel(eCrossReferenceObject, context)
                                },
                                        new Object[] { eObject, reference, eCrossReferenceObject },
                                        context));
                            }
                            else
                            {
                                break;
                            }
                        }
                    }
                }

                /*
                 * for (EContentsEList.FeatureIterator<EObject> i = (EContentsEList.FeatureIterator<EObject>)eObject.eCrossReferences().iterator(); i.hasNext();)
                 * {
                 *  EObject eCrossReferenceObject = i.next();
                 *  if (eCrossReferenceObject.eResource() == null && !eCrossReferenceObject.eIsProxy() && !i.feature().isTransient())
                 *  {
                 *      result = false;
                 *      if (diagnostics != null)
                 *      {
                 *          diagnostics.add
                 *            (createDiagnostic
                 *              (BasicDiagnostic.ERROR,
                 *               DIAGNOSTIC_SOURCE,
                 *               EOBJECT__EVERY_REFERENCE_IS_CONTAINED,
                 *               "_UI_DanglingReference_diagnostic",
                 *               new Object[]
                 *               {
                 * getFeatureLabel(i.feature(), context),
                 * getObjectLabel(eObject, context),
                 * getObjectLabel(eCrossReferenceObject, context)
                 *               },
                 *               new Object[] { eObject, i.feature(), eCrossReferenceObject },
                 *               context));
                 *      }
                 *      else
                 *      {
                 *          break;
                 *      }
                 *  }
                 * }
                 */
            }
            return(result);
        }
        protected bool validate_KeyUnique
            (EObject eObject, EReference eReference, DiagnosticChain diagnostics, Dictionary <object, object> context)
        {
            bool result = true;
            Dictionary <List <Object>, EObject> keys = new Dictionary <List <Object>, EObject>();
            List <EAttribute> eAttributes            = eReference.eKeys;// (EAttribute[])((BasicEList <?>)eReference.getEKeys()).data();

            List <EObject> values = (List <EObject>)eObject.eGet(eReference);

            foreach (EObject value in values)
            {
                List <Object> key = new List <Object>();
                for (int i = 0, size = eAttributes.Count; i < size; ++i)
                {
                    EAttribute eAttribute = eAttributes[i];
                    if (eAttribute == null)
                    {
                        break;
                    }
                    else
                    {
                        key.Add(value.eGet(eAttribute));
                    }
                }
                EObject otherValue = null;
                if (keys.ContainsKey(key))
                {
                    otherValue = keys[key];
                }

                keys.Add(key, value);

                if (otherValue != null)
                {
                    result = false;
                    if (diagnostics == null)
                    {
                        break;
                    }
                    else
                    {
                        String uriFragmentSegment = ((InternalEObject)eObject).eURIFragmentSegment(eReference, value);
                        int    index = uriFragmentSegment.IndexOf('[', 0);
                        if (index != -1)
                        {
                            uriFragmentSegment = uriFragmentSegment.Substring(index);
                        }
                        diagnostics.add
                            (createDiagnostic
                                (BasicDiagnostic.ERROR,
                                DIAGNOSTIC_SOURCE,
                                EOBJECT__EVERY_KEY_UNIQUE,
                                "_UI_DuplicateKey_diagnostic",
                                new Object[]
                        {
                            getFeatureLabel(eReference, context),
                            uriFragmentSegment,
                            getObjectLabel(value, context),
                            getObjectLabel(otherValue, context)
                        },
                                new Object[] { eObject, eReference, value, otherValue },
                                context));
                    }
                }
            }

            return(result);
        }
        public bool validate_EveryProxyResolves(EObject eObject, DiagnosticChain diagnostics, Dictionary <object, object> context)
        {
            bool result = true;

            foreach (EReference reference in eObject.eClass().eAllReferences)
            {
                if (eObject.eIsSet(reference))
                {
                    EObject eCrossReferenceObject = eObject.eGet(reference) as EObject;


                    if (eCrossReferenceObject.eIsProxy())
                    {
                        result = false;
                        if (diagnostics != null)
                        {
                            diagnostics.add
                                (createDiagnostic
                                    (BasicDiagnostic.ERROR,
                                    DIAGNOSTIC_SOURCE,
                                    EOBJECT__EVERY_PROXY_RESOLVES,
                                    "_UI_UnresolvedProxy_diagnostic",
                                    new Object[]
                            {
                                getFeatureLabel(reference, context),
                                getObjectLabel(eObject, context),
                                getObjectLabel(eCrossReferenceObject, context)
                            },
                                    new Object[] { eObject, reference, eCrossReferenceObject },
                                    context));
                        }
                        else
                        {
                            break;
                        }
                    }
                }
            }


            //for (EContentsEList.FeatureIterator<EObject> i = (EContentsEList.FeatureIterator<EObject>)eObject.eCrossReferences().iterator(); i.hasNext();)

            /*
             * foreach (EObject eCrossReferenceObject in eObject.eCrossReferences())
             * {
             *  //EObject eCrossReferenceObject = i.next();
             *  if (eCrossReferenceObject.eIsProxy())
             *  {
             *      result = false;
             *      if (diagnostics != null)
             *      {
             *          diagnostics.add
             *            (createDiagnostic
             *              (BasicDiagnostic.ERROR,
             *               DIAGNOSTIC_SOURCE,
             *               EOBJECT__EVERY_PROXY_RESOLVES,
             *               "_UI_UnresolvedProxy_diagnostic",
             *               new Object[]
             *               {
             *   getFeatureLabel(i.feature(), context),
             *   getObjectLabel(eObject, context),
             *   getObjectLabel(eCrossReferenceObject, context)
             *               },
             *               new Object[] { eObject, i.feature(), eCrossReferenceObject },
             *               context));
             *      }
             *      else
             *      {
             *          break;
             *      }
             *  }
             * }
             */
            return(result);
        }
        public bool validate_BidirectionalReferenceIsPaired(EObject eObject, EReference eReference, EReference eOpposite, DiagnosticChain diagnostics, Dictionary <object, object> context)
        {
            bool   result = true;
            Object value  = eObject.eGet(eReference);

            if (eReference.many)
            {
                List <EObject> values = (List <EObject>)value;
                if (eOpposite.many)
                {
                    foreach (EObject oppositeEObject in values)
                    {
                        List <EObject> oppositeValues = (List <EObject>)oppositeEObject.eGet(eOpposite);
                        if (!oppositeValues.Contains(eObject))
                        {
                            result = false;
                            if (diagnostics != null)
                            {
                                // TODO
                                diagnostics.add
                                    (createDiagnostic
                                        (BasicDiagnostic.ERROR,
                                        DIAGNOSTIC_SOURCE,
                                        EOBJECT__EVERY_BIDIRECTIONAL_REFERENCE_IS_PAIRED,
                                        "_UI_UnpairedBidirectionalReference_diagnostic",
                                        new Object[]
                                {
                                    getFeatureLabel(eReference, context),
                                    getObjectLabel(eObject, context),
                                    getFeatureLabel(eOpposite, context),
                                    getObjectLabel(oppositeEObject, context),
                                },
                                        new Object[] { eObject, eReference, oppositeEObject, eOpposite },
                                        context));
                            }
                            else
                            {
                                break;
                            }
                        }
                    }
                }
                else
                {
                    foreach (EObject oppositeEObject in values)
                    {
                        if (oppositeEObject.eGet(eOpposite) != eObject)
                        {
                            result = false;
                            if (diagnostics != null)
                            {
                                // TODO
                                diagnostics.add
                                    (createDiagnostic
                                        (BasicDiagnostic.ERROR,
                                        DIAGNOSTIC_SOURCE,
                                        EOBJECT__EVERY_BIDIRECTIONAL_REFERENCE_IS_PAIRED,
                                        "_UI_UnpairedBidirectionalReference_diagnostic",
                                        new Object[]
                                {
                                    getFeatureLabel(eReference, context),
                                    getObjectLabel(eObject, context),
                                    getFeatureLabel(eOpposite, context),
                                    getObjectLabel(oppositeEObject, context),
                                },
                                        new Object[] { eObject, eReference, oppositeEObject, eOpposite },
                                        context));
                            }
                            else
                            {
                                break;
                            }
                        }
                    }
                }
            }
            else
            {
                EObject oppositeEObject = (EObject)value;
                if (oppositeEObject != null)
                {
                    if (eOpposite.many)
                    {
                        List <EObject> oppositeValues = (List <EObject>)oppositeEObject.eGet(eOpposite);
                        if (!oppositeValues.Contains(eObject))
                        {
                            result = false;
                            if (diagnostics != null)
                            {
                                // TODO
                                diagnostics.add
                                    (createDiagnostic
                                        (BasicDiagnostic.ERROR,
                                        DIAGNOSTIC_SOURCE,
                                        EOBJECT__EVERY_BIDIRECTIONAL_REFERENCE_IS_PAIRED,
                                        "_UI_UnpairedBidirectionalReference_diagnostic",
                                        new Object[]
                                {
                                    getFeatureLabel(eReference, context),
                                    getObjectLabel(eObject, context),
                                    getFeatureLabel(eOpposite, context),
                                    getObjectLabel(oppositeEObject, context),
                                },
                                        new Object[] { eObject, eReference, oppositeEObject, eOpposite },
                                        context));
                            }
                        }
                    }
                    else
                    {
                        if (oppositeEObject.eGet(eOpposite) != eObject)
                        {
                            result = false;
                            if (diagnostics != null)
                            {
                                diagnostics.add
                                    (createDiagnostic
                                        (BasicDiagnostic.ERROR,
                                        DIAGNOSTIC_SOURCE,
                                        EOBJECT__EVERY_BIDIRECTIONAL_REFERENCE_IS_PAIRED,
                                        "_UI_UnpairedBidirectionalReference_diagnostic",
                                        new Object[]
                                {
                                    getFeatureLabel(eReference, context),
                                    getObjectLabel(eObject, context),
                                    getFeatureLabel(eOpposite, context),
                                    getObjectLabel(oppositeEObject, context),
                                },
                                        new Object[] { eObject, eReference, oppositeEObject, eOpposite },
                                        context));
                            }
                        }
                    }
                }
            }
            return(result);
        }
        protected bool validate_MultiplicityConforms
            (EObject eObject, EStructuralFeature eStructuralFeature, DiagnosticChain diagnostics, Dictionary <object, object> context)
        {
            bool result = true;

            if (eStructuralFeature.many)
            {
                if (false)
                {
                    /*
                     * if (FeatureMapUtil.isFeatureMap(eStructuralFeature) && ExtendedMetaData.INSTANCE.isDocumentRoot(eObject.eClass()))
                     * {
                     *  FeatureMap featureMap = (FeatureMap)eObject.eGet(eStructuralFeature);
                     *  int count = 0;
                     *  for (int i = 0, size = featureMap.size(); i < size; ++i)
                     *  {
                     *      EStructuralFeature feature = featureMap.getEStructuralFeature(i);
                     *      int kind = ExtendedMetaData.INSTANCE.getFeatureKind(feature);
                     *      if (kind == ExtendedMetaData.ELEMENT_FEATURE &&
                     *            feature != XMLTypePackage.Literals.XML_TYPE_DOCUMENT_ROOT__CDATA &&
                     *            feature != XMLTypePackage.Literals.XML_TYPE_DOCUMENT_ROOT__COMMENT &&
                     *            feature != XMLTypePackage.Literals.XML_TYPE_DOCUMENT_ROOT__TEXT &&
                     *            feature != XMLTypePackage.Literals.XML_TYPE_DOCUMENT_ROOT__PROCESSING_INSTRUCTION &&
                     ++count > 1)
                     *      {
                     *          result = false;
                     *          break;
                     *      }
                     *  }
                     *  if (count != 1)
                     *  {
                     *      result = false;
                     *      if (diagnostics != null)
                     *      {
                     *          diagnostics.add
                     *            (createDiagnostic
                     *              (Diagnostic.ERROR,
                     *               DIAGNOSTIC_SOURCE,
                     *               EOBJECT__EVERY_MULTIPCITY_CONFORMS,
                     *               "_UI_DocumentRootMustHaveOneElement_diagnostic",
                     *                new Object[]
                     *                {
                     *  getFeatureLabel(eStructuralFeature, context),
                     *  getObjectLabel(eObject, context),
                     *  count
                     *                },
                     *               new Object[] { eObject, eStructuralFeature },
                     *               context));
                     *      }
                     *  }
                     */
                }
                else
                {
                    int lowerBound = eStructuralFeature.lowerBound;
                    if (lowerBound > 0)
                    {
                        int size = ((List <object>)eObject.eGet(eStructuralFeature)).Count;
                        if (size < lowerBound)
                        {
                            result = false;
                            if (diagnostics != null)
                            {
                                diagnostics.add
                                    (createDiagnostic
                                        (BasicDiagnostic.ERROR,
                                        DIAGNOSTIC_SOURCE,
                                        EOBJECT__EVERY_MULTIPCITY_CONFORMS,
                                        "_UI_FeatureHasTooFewValues_diagnostic",
                                        new Object[]
                                {
                                    getFeatureLabel(eStructuralFeature, context),
                                    getObjectLabel(eObject, context),
                                    size,
                                    lowerBound
                                },
                                        new Object[] { eObject, eStructuralFeature },
                                        context));
                            }
                        }
                        int upperBound = eStructuralFeature.upperBound;
                        if (upperBound > 0 && size > upperBound)
                        {
                            result = false;
                            if (diagnostics != null)
                            {
                                diagnostics.add
                                    (createDiagnostic
                                        (BasicDiagnostic.ERROR,
                                        DIAGNOSTIC_SOURCE,
                                        EOBJECT__EVERY_MULTIPCITY_CONFORMS,
                                        "_UI_FeatureHasTooManyValues_diagnostic",
                                        new Object[]
                                {
                                    getFeatureLabel(eStructuralFeature, context),
                                    getObjectLabel(eObject, context),
                                    size,
                                    upperBound
                                },
                                        new Object[] { eObject, eStructuralFeature },
                                        context));
                            }
                        }
                    }
                    else
                    {
                        int upperBound = eStructuralFeature.upperBound;
                        if (upperBound > 0)
                        {
                            int size = ((List <object>)eObject.eGet(eStructuralFeature)).Count;
                            if (size > upperBound)
                            {
                                result = false;
                                if (diagnostics != null)
                                {
                                    diagnostics.add
                                        (createDiagnostic
                                            (BasicDiagnostic.ERROR,
                                            DIAGNOSTIC_SOURCE,
                                            EOBJECT__EVERY_MULTIPCITY_CONFORMS,
                                            "_UI_FeatureHasTooManyValues_diagnostic",
                                            new Object[]
                                    {
                                        getFeatureLabel(eStructuralFeature, context),
                                        getObjectLabel(eObject, context),
                                        size,
                                        upperBound
                                    },
                                            new Object[] { eObject, eStructuralFeature },
                                            context));
                                }
                            }
                        }
                    }
                }
            }
            else if (eStructuralFeature.required)
            {
                if (eStructuralFeature.unsettable ? !eObject.eIsSet(eStructuralFeature) : eObject.eGet(eStructuralFeature, false) == null)
                {
                    result = false;
                    if (diagnostics != null)
                    {
                        diagnostics.add
                            (createDiagnostic
                                (BasicDiagnostic.ERROR,
                                DIAGNOSTIC_SOURCE,
                                EOBJECT__EVERY_MULTIPCITY_CONFORMS,
                                "_UI_RequiredFeatureMustBeSet_diagnostic",
                                new Object[] { getFeatureLabel(eStructuralFeature, context), getObjectLabel(eObject, context) },
                                new Object[] { eObject, eStructuralFeature },
                                context));
                    }
                }
            }

            return(result);
        }