Пример #1
0
 private EnAr.Connector ConstructGeneralization(Ecore.IEClass superEClass, EnAr.Element clazz)
 {
     EnAr.Element   superClass           = ConstructClassifier(superEClass);
     EnAr.Connector inheritanceConnector = (EnAr.Connector)clazz.Connectors.AddNew("", "Connector");
     inheritanceConnector.Type       = "Generalization";
     inheritanceConnector.ClientID   = clazz.ElementID;
     inheritanceConnector.SupplierID = superClass.ElementID;
     inheritanceConnector.Update();
     return(inheritanceConnector);
 }
Пример #2
0
        private EnAr.Element ConstructClass(Ecore.IEClass eClass)
        {
            EnAr.Package parentPackage;
            EnAr.Element clazz;

            if (!eclassifier2Class.ContainsKey(eClass))
            {
                parentPackage             = ConstructMetamodelPackage(eClass.EPackage);
                clazz                     = (EnAr.Element)parentPackage.Elements.AddNew(eClass.Name, "Class");
                eclassifier2Class[eClass] = clazz;
                clazz.Abstract            = Bool2String(eClass.Abstract.GetValueOrDefault() || eClass.Interface.GetValueOrDefault());


                // Manage normal super types
                foreach (Ecore.IEClass superEClass in eClass.ESuperTypes)
                {
                    ConstructGeneralization(superEClass, clazz);
                }

                // Manage super types that possess type parameters
                foreach (Ecore.IEGenericType eGenericSuperType in eClass.EGenericSuperTypes)
                {
                    if (eGenericSuperType.EClassifier != null)
                    {
                        EnAr.Connector generalization =
                            ConstructGeneralization((Ecore.IEClass)eGenericSuperType.EClassifier, clazz);
                        EA.Connector generalizationEa = explorer.GetEaObject(generalization);
                        foreach (Ecore.IEGenericType eTypeArgument in eGenericSuperType.ETypeArguments)
                        {
                            ConstructTemplateBinding(eGenericSuperType, eTypeArgument, generalizationEa);
                        }
                    }
                }


                foreach (Ecore.IEStructuralFeature eStructuralFeature in eClass.EStructuralFeatures)
                {
                    ConstructAttributeOrAssociation(eclassifier2Class[eClass], eStructuralFeature);
                }


                // eClass.EOperations //TODO
            }
            else
            {
                parentPackage = ePackage2Package[eClass.EPackage];
                clazz         = eclassifier2Class[eClass];
            }

            parentPackage.Elements.Refresh();
            parentPackage.Update();
            clazz.Update();
            clazz.Connectors.Refresh();
            return(clazz);
        }
Пример #3
0
        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();
        }