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); } }