private void ConstructAttribute(EnAr.IElement clazz, Ecore.IEStructuralFeature eStructuralFeature)
        {
            EnAr.Attribute attribute = (EnAr.Attribute)clazz.Attributes.AddNew(eStructuralFeature.Name, "Attribute");

            // Case regular type without template
            if (eStructuralFeature.EType != null)
            {
                EnAr.Element attributeType = ConstructClassifier(eStructuralFeature.EType);
                attribute.ClassifierID = attributeType.ElementID;
                attribute.Type         = attributeType.Name;
            }

            else if (eStructuralFeature.EGenericType != null)
            {
                Ecore.IEGenericType eGenericType = eStructuralFeature.EGenericType;

                // Case templated type (eg. MyClass<T>)
                if (eGenericType.EClassifier != null)
                {
                    EnAr.Element attributeType = ConstructClassifier(eGenericType.EClassifier);
                    attribute.ClassifierID = attributeType.ElementID;
                    attribute.Type         = attributeType.Name;
                    foreach (Ecore.IEGenericType eTypeArgument in eGenericType.ETypeArguments)
                    {
                        //TODO impossible to manage local bindings with regular attribute in EA, needs to be a reference/association?
                    }
                }

                // Case template type (eg. T), we simply set the same name
                else if (eGenericType.ETypeParameter != null)
                {
                    // TODO can we do better than that in EA?
                    attribute.Type = eGenericType.ETypeParameter.Name;
                }
            }


            attribute.LowerBound = BoundToString(eStructuralFeature.LowerBound.GetValueOrDefault());
            attribute.UpperBound = BoundToString(eStructuralFeature.UpperBound.GetValueOrDefault());

            if (eStructuralFeature.UpperBound.GetValueOrDefault() == -1 ||
                eStructuralFeature.UpperBound.GetValueOrDefault() > 1)
            {
                attribute.IsOrdered = eStructuralFeature.Ordered.GetValueOrDefault();
            }

            attribute.AllowDuplicates = !eStructuralFeature.Unique.GetValueOrDefault();
            attribute.IsDerived       = eStructuralFeature.Derived.GetValueOrDefault();
            attribute.IsConst         = !eStructuralFeature.Changeable.GetValueOrDefault();
            attribute.IsCollection    = eStructuralFeature.UpperBound == -1 || eStructuralFeature.UpperBound > 1;
            attribute.Default         = eStructuralFeature.DefaultValueLiteral;

            clazz.Attributes.Refresh();
            attribute.Update();
        }
 private void ConstructAttributeOrAssociation(EnAr.IElement clazz, Ecore.IEStructuralFeature eStructuralFeature)
 {
     if (eStructuralFeature is Ecore.IEAttribute || eStructuralFeature.EGenericType?.ETypeParameter != null)
     {
         ConstructAttribute(clazz, eStructuralFeature);
     }
     else
     {
         ConstructConnectorEnd(clazz, (Ecore.IEReference)eStructuralFeature);
     }
 }
        private void ConstructConnectorEnd(EnAr.IElement clazz, Ecore.IEReference eReference)
        {
            EnAr.Connector    connector;
            EnAr.ConnectorEnd connectorEnd;
            EnAr.ConnectorEnd otherConnectorEnd;

            // First we find the type pointed by the reference
            Ecore.IEClass ecoreType = null;
            if (eReference.EType != null)
            {
                ecoreType = (Ecore.IEClass)eReference.EType;
            }
            else if (eReference.EGenericType != null)
            {
                ecoreType = (Ecore.IEClass)eReference.EGenericType.EClassifier;
            }


            // If no connector end managed yet, we set up everything
            if (!eReference2ConnectorEnd.ContainsKey(eReference))
            {
                connector          = (EnAr.Connector)clazz.Connectors.AddNew("", "Connector");
                connector.ClientID = clazz.ElementID;
                connectorEnd       = connector.SupplierEnd;
                eReference2ConnectorEnd[eReference] = new Tuple <EnAr.Connector, EnAr.ConnectorEnd>(connector,
                                                                                                    connectorEnd);
                otherConnectorEnd = connector.ClientEnd;

                // Managing navigability / direction
                connectorEnd.IsNavigable      = true;
                connectorEnd.Navigable        = "Navigable";
                otherConnectorEnd.IsNavigable = false;
                otherConnectorEnd.Navigable   = "Non-Navigable";
                connector.Direction           = "Source -> Destination";

                // In case of opposite, we manage the other connector end to have everything bi directionnal
                if (eReference.EOpposite != null)
                {
                    otherConnectorEnd.IsNavigable = true;
                    otherConnectorEnd.Navigable   = "Navigable";
                    connector.Direction           = "Bi-Directional";
                    eReference2ConnectorEnd[eReference.EOpposite] =
                        new Tuple <EnAr.Connector, EnAr.ConnectorEnd>(connector, otherConnectorEnd);
                }

                EnAr.Element pointedClass = ConstructClassifier(ecoreType);
                connector.SupplierID = pointedClass.ElementID;
            }

            // If there is already a connector end managed, we retrieve it
            else
            {
                connector    = eReference2ConnectorEnd[eReference].Item1;
                connectorEnd = eReference2ConnectorEnd[eReference].Item2;

                if (connectorEnd.End == "ClientEnd")
                {
                    otherConnectorEnd = connector.SupplierEnd;
                }
                else if (connectorEnd.End == "SupplierEnd")
                {
                    otherConnectorEnd = connector.ClientEnd;
                }
                else
                {
                    throw new Exception();
                }
            }

            // Containment must be set on the opposite end...
            otherConnectorEnd.Aggregation = eReference.Containment.GetValueOrDefault() ? 2 : 0;
            connector.Type = eReference.Containment.GetValueOrDefault() ? "Aggregation" : "Association";

            // Everything else is on the same end
            connectorEnd.Role        = eReference.Name;
            connectorEnd.Cardinality = BoundsToString(eReference.LowerBound.GetValueOrDefault(),
                                                      eReference.UpperBound.GetValueOrDefault());
            connectorEnd.Derived = eReference.Derived.GetValueOrDefault();
            if (eReference.UpperBound.GetValueOrDefault() == -1 || eReference.UpperBound.GetValueOrDefault() > 1)
            {
                connectorEnd.Ordering = eReference.Ordered.GetValueOrDefault() ? 1 : 0;
            }
            connectorEnd.AllowDuplicates = !eReference.Unique.GetValueOrDefault();

            // Finally we set the type arguments, if any (eg. T = Toto for type MyClass<T>)
            Ecore.IEGenericType eGenericType = eReference.EGenericType;
            if (eGenericType?.EClassifier != null)
            {
                if (connectorEnd.End == "SupplierEnd")
                {
                    Connector connectorEa = explorer.GetEaObject(connector);
                    foreach (Ecore.IEGenericType ecoreTypeArgument in eGenericType.ETypeArguments)
                    {
                        ConstructTemplateBinding(eGenericType, ecoreTypeArgument, connectorEa);
                    }
                    connectorEa.TemplateBindings.Refresh();
                }
            }

            connector.Update();
            connectorEnd.Update();
            otherConnectorEnd.Update();
            clazz.Connectors.Refresh();
            clazz.Update();
        }