public CoreClassifier getExpressionType(CoreClassifier sourceType, CoreAssociationEnd associationEnd, CoreClassifier elementType) { if (sourceType.GetType() == typeof(CollectionType)) { if ((sourceType.GetType() == typeof(SetType) || sourceType.GetType() == typeof(BagType)) && (!associationEnd.isOrdered()) ) { return(getFactory().createBagType(elementType)); } else { return(getFactory().createSequenceType(elementType)); } } else { if (isSingleElementAccess(sourceType, associationEnd)) { return(elementType); } else if (associationEnd.isOrdered()) { return(getFactory().createOrderedSetType(elementType)); } else { return(getFactory().createSetType(elementType)); } } }
public CoreClassifier getExpressionType(OclExpression source, CoreClassifier propertyType) { if (source != null && source.getType().GetType() == typeof(CollectionType)) { CoreClassifier elementType; if (propertyType.GetType() == typeof(CollectionType)) { elementType = ((CollectionType)propertyType).getElementType(); } else { elementType = propertyType; } if ((source.getType().GetType() == typeof(SetType) || source.getType().GetType() == typeof(BagType))) { return(getFactory().createBagType(elementType)); } else { return(getFactory().createSequenceType(elementType)); } } else { return(propertyType); } }
/* (non-Javadoc) * @see br.cos.ufrj.lens.odyssey.tools.psw.metamodels.core.interfaces.CoreClassifier#conformsTo(br.cos.ufrj.lens.odyssey.tools.psw.metamodels.core.interfaces.CoreClassifier) */ public override bool conformsTo(CoreClassifier c) { if (c.getName().Equals("OclAny")) { return(true); } if (c.GetType() != typeof(TupleType)) { return(false); } TupleType typeToMatch = (TupleType)c; if (this.getTupleParts().Count != typeToMatch.getTupleParts().Count) { return(false); } List <object> tupleTypes = new List <object>(getTupleParts()); for (int i = 0; i < tupleTypes.Count; i++) { TuplePartType element = (TuplePartType)tupleTypes[i]; CoreAttribute elementFound = typeToMatch.lookupAttribute(element.getName()); if (elementFound == null || !element.getFeatureType().conformsTo(elementFound.getFeatureType())) { return(false); } } return(true); }
public override bool conformsTo(CoreClassifier type) { if (type.GetType() != typeof(CollectionType)) { return(false); } if (((CollectionTypeImpl)type).getCollectionKind() == CollectionKindEnum.COLLECTION || ((CollectionTypeImpl)type).getCollectionKind() == this.getKind()) { CoreClassifier targetType = ((CollectionType)type).getElementType(); foreach (CollectionLiteralPartImpl collectionItem in getParts()) { if (!collectionItem.conformsTo(targetType)) { return(false); } } } else { return(false); } return(true); }
private bool isSingleElementAccess(CoreClassifier sourceType, CoreAssociationEnd associationEnd) { return ((sourceType.GetType() == typeof(CoreAssociationClass)) || (associationEnd.isOneMultiplicity() && !associationEndHasQualifiers(associationEnd)) || (associationEnd.isOneMultiplicity() && associationEndHasQualifiers(associationEnd) && getQualifiers().Count > 0)); }
/* (non-Javadoc) * @see br.ufrj.cos.lens.odyssey.tools.psw.metamodels.core.interfaces.CoreClassifier#getMostSpecificCommonSuperType(br.ufrj.cos.lens.odyssey.tools.psw.metamodels.core.interfaces.CoreClassifier) */ public override CoreClassifier getMostSpecificCommonSuperType(CoreClassifier otherClassifier) { if (this.GetType() == otherClassifier.GetType()) { CollectionType otherCollection = (CollectionType)otherClassifier; return(createSpecificCollectionType(getElementType().getMostSpecificCommonSuperType(otherCollection.getElementType()))); } else if (otherClassifier.GetType() == typeof(CollectionType)) { CollectionType otherCollection = (CollectionType)otherClassifier; return(createGenericCollectionType(getElementType().getMostSpecificCommonSuperType(otherCollection.getElementType()))); } else { return((CoreClassifier)OclTypesDefinition.getType("OclAny")); } }
protected virtual bool areCollectionsCompatible(CoreClassifier c) { if (c.GetType() == this.GetType() || (c.getName().Equals(this.getName())) || (c is CollectionTypeImpl) && c.getName().StartsWith("Collection")) { return(elementTypesConformance(c)); } else { return(false); } }
public CoreClassifier getInnerMostElementType() { CoreClassifier innerElementType = this.getElementType(); while (innerElementType.GetType() == typeof(CollectionType)) { innerElementType = ((CollectionType)innerElementType).getElementType(); } return(innerElementType); }
public void setInnerMostElementType(CoreClassifier classifier) { CoreClassifier innerElementType = this.getElementType(); CollectionType collectionType = this; while (innerElementType.GetType() == typeof(CollectionType)) { collectionType = (CollectionType)innerElementType; innerElementType = ((CollectionType)innerElementType).getElementType(); } collectionType.setElementType(classifier); }
public override bool conformsTo(CoreClassifier type) { if (type.GetType() != typeof(TupleType)) { return(false); } TupleType targetType = (TupleType)type; foreach (VariableDeclaration declaration in getTuplePart()) { CoreAttribute targetElementType = targetType.lookupAttribute(declaration.getVarName()); if ((targetElementType == null) || (!declaration.getType().conformsTo(targetElementType.getFeatureType()))) { return(false); } } return(true); }
private CoreClassifier getParameterRealType(CoreClassifier parameter, CoreClassifier typeToBeMatched) { CollectionType ownerCollection = (CollectionType)getFeatureOwner(); if (parameter.getName().IndexOf("<T>") >= 0) { return(ownerCollection.getFactory().createCollectionType(parameter.getName(), ownerCollection.getElementType())); } else { if (typeToBeMatched.GetType() == typeof(CollectionType)) { CollectionType collection = (CollectionType)typeToBeMatched; return(ownerCollection.getFactory().createCollectionType(parameter.getName(), collection.getElementType())); } else { return(null); } } }
public static CoreClassifier createTypeFromString(String classifierName) { result = null; if (!OclTypesDefinition.isOclCollectionType(classifierName) && !OclTypesDefinition.isOclTupleType(classifierName)) { result = getType(classifierName); } if (result == null) { PSWOclCompiler oclCompiler = new PSWOclCompiler(environment, new ConstraintSourceTrackerImpl()); result = oclCompiler.parseType(environment, classifierName); if (result.GetType() == typeof(CollectionType)) { ((CollectionTypeImpl)result).setInnerMostElementType(getType(((CollectionTypeImpl)result).getInnerMostElementType().getName())); } } return(result); }
public bool conformsTo(CoreClassifier c) { return((c.GetType() == typeof(OclModelElementType)) || (c.getName().Equals("OclType"))); }
public CoreClassifier getReturnType(List <object> argumentTypes) { CollectionTypeImpl collection = (CollectionTypeImpl)getFeatureOwner(); CoreClassifier returnType = getJmiOperation().getReturnType(); if (getName().Equals("collect")) { CoreClassifier elementType = (CoreClassifier)argumentTypes.iterator().next(); if (elementType.GetType() == typeof(CollectionType)) { elementType = ((CollectionTypeImpl)elementType).getInnerMostElementType(); } CoreClassifier type = collection.getFactory().createCollectionType(collection.getReturnTypeForCollect(), elementType); return(type); } else if (getName().Equals("collectNested")) { return(collection.getFactory().createCollectionType(returnType.getName(), (CoreClassifier)argumentTypes.iterator().next())); } else if (returnType.getName().Equals("<T>")) { return(collection.getElementType()); } else if (OclTypesDefinition.isOclGenericCollectionType(returnType.getName())) { if (returnType.getName().IndexOf("<T>") >= 0) { if (((CollectionType)getFeatureOwner()).getElementType().getName().Equals("OclVoid")) { CoreClassifier argumentElementType; if (argumentTypes.Count == 0) { argumentElementType = collection.getElementType(); } else if (argumentTypes.iterator().next().GetType() == typeof(CollectionType)) { argumentElementType = ((CollectionType)argumentTypes.iterator().next()).getElementType(); } else { argumentElementType = (CoreClassifier)argumentTypes.iterator().next(); } return(collection.getFactory().createCollectionType(returnType.getName(), argumentElementType)); } else { return(collection.getFactory().createCollectionType(returnType.getName(), collection.getElementType())); } } else if (returnType.getName().IndexOf("<T2>") >= 0) { return(collection.getFactory().createCollectionType(returnType.getName(), collection.getInnerMostElementType())); } else { return(null); } } else if (returnType.getName().StartsWith("Set(Tuple")) { if (argumentTypes.Count > 0) { CollectionType collectionParameter = (CollectionType)argumentTypes[0]; TupleTypeImpl tupleType = (TupleTypeImpl)collection.getFactory().createTupleType(); tupleType.addElement("first", collection.getElementType()); tupleType.addElement("second", collectionParameter.getElementType()); return(collection.getFactory().createCollectionType("Set", tupleType)); } else { return(null); } } else { return(returnType); } }