/// <summary> /// Adds the given element to the collection /// </summary> /// <param name="item">The item to add</param> public override void Add(IModelElement item) { if ((this._parent.Identifies == null)) { LL.MDE.Components.Qvt.Metamodel.EMOF.IClass identifiesCasted = item.As <LL.MDE.Components.Qvt.Metamodel.EMOF.IClass>(); if ((identifiesCasted != null)) { this._parent.Identifies = identifiesCasted; return; } } IProperty oppositePartCasted = item.As <IProperty>(); if ((oppositePartCasted != null)) { this._parent.OppositePart.Add(oppositePartCasted); } IProperty partCasted = item.As <IProperty>(); if ((partCasted != null)) { this._parent.Part.Add(partCasted); } if ((this._parent.Transformation == null)) { IRelationalTransformation transformationCasted = item.As <IRelationalTransformation>(); if ((transformationCasted != null)) { this._parent.Transformation = transformationCasted; return; } } }
private EMOF.IClass ConstructClass(EnAr.Element classElement) { // We create a EMOF.Class EMOF.IClass clazz = new EMOF.Class() { IsAbstract = classElement.Abstract.ToLower() == "true", Name = classElement.Name }; elementToType.Add(classElement, clazz); // We browse the attributes of the EMOF.Class element (~= ecore attributes) foreach (EnAr.Attribute attribute in explorer.GetAttributes(classElement)) { EMOF.IProperty property = ConstructProperty(attribute); property.Class = clazz; clazz.OwnedAttribute.Add(property); } // We browse the connectors (~= ecore references + inheritance links) foreach (EnAr.Connector connector in explorer.GetConnectorsWithSource(classElement)) { EnAr.Element targetElement = explorer.GetTargetElement(connector); if (targetElement.Type.ToLower() == "class") { EMOF.IClass targetType = ConstructType(targetElement) as EMOF.Class; if (targetType != null) { // Case super type if (connector.Type.ToLower() == "generalization") { clazz.SuperClass.Add(targetType); } // Case reference(s) else { EMOF.IProperty prop1 = ConstructProperty(clazz, targetType, connector.ClientEnd, connector.SupplierEnd); EMOF.IProperty prop2 = ConstructProperty(targetType, clazz, connector.SupplierEnd, connector.ClientEnd); if (prop1 != null && prop2 != null) { prop1.Opposite = prop2; prop2.Opposite = prop1; } } } } } // And finally the methods foreach (EnAr.Method method in explorer.GetMethods(classElement)) { EMOF.IOperation operation = ConstructOperation(method); clazz.OwnedOperation.Add(operation); operation.Class = clazz; } return(clazz); }
private static QVTRelations.IKey ConstructKey(ISet <EMOF.IClass> reachableClasses, QvtKeyParserResult keyParserResult) { EMOF.IClass clazz = reachableClasses.Single(c => c.Name == keyParserResult.ClassName); QVTRelations.IKey key = new QVTRelations.Key { Identifies = clazz }; foreach (IList <string> propertyPathList in keyParserResult.NavigatedProperties) { // Case multiple navigated properties, we use our QVT extension "PropertyPaths" if (propertyPathList.Count > 1) { PropertyPath propertyPath = new PropertyPath(); EMOF.IClass currentClass = clazz; foreach (string propertyName in propertyPathList) { if (currentClass == null) { throw new InvalidQVTRelationsModelException("Wrong key somewhere, impossible to reach: \'" + propertyName + "\'"); } EMOF.IProperty nextProperty = currentClass.OwnedAttribute.Single(p => p.Name == propertyName); if (nextProperty.isMany()) { throw new InvalidQVTRelationsModelException("Wrong key somewhere, cannot use a collection as part of key for now: \'" + propertyName + "\'"); } propertyPath.Properties.Add(nextProperty); currentClass = nextProperty.Type as EMOF.IClass; } key.PropertyPaths().Add(propertyPath); } // Else, we fill the regular "part" of the key else { EMOF.IProperty property = clazz.OwnedAttribute.Single(p => p.Name == propertyPathList.Single()); if (property.isMany()) { throw new InvalidQVTRelationsModelException("Wrong key somewhere, cannot use a collection as part of key for now: \'" + property.Name + "\'"); } key.Part.Add(property); } } return(key); }
/// <summary> /// Adds the given element to the collection /// </summary> /// <param name="item">The item to add</param> public override void Add(IModelElement item) { IPropertyTemplateItem partCasted = item.As <IPropertyTemplateItem>(); if ((partCasted != null)) { this._parent.Part.Add(partCasted); } if ((this._parent.ReferredClass == null)) { LL.MDE.Components.Qvt.Metamodel.EMOF.IClass referredClassCasted = item.As <LL.MDE.Components.Qvt.Metamodel.EMOF.IClass>(); if ((referredClassCasted != null)) { this._parent.ReferredClass = referredClassCasted; return; } } }
private EMOF.IProperty ConstructProperty(EMOF.IClass source, EMOF.IClass target, EnAr.ConnectorEnd sourceC, EnAr.ConnectorEnd targetC) { if (!string.IsNullOrWhiteSpace(targetC.Role)) { EMOF.IProperty property = new EMOF.Property() { Name = targetC.Role, Type = target, IsComposite = sourceC.Aggregation > 0, Class = source, IsDerived = targetC.Derived, IsUnique = !targetC.AllowDuplicates, Lower = TranslateMultiplicityLower(targetC.Cardinality), Upper = TranslateMultiplicityUpper(targetC.Cardinality), }; source.OwnedAttribute.Add(property); return(property); } return(null); }