public void testCollectionType_01() { AstOclModelElementFactory factory1 = AstOclModelElementFactoryManager.getInstance(umlModel.getOclPackage()); CollectionTypeImpl type1 = (CollectionTypeImpl)factory1.createSetType(getClassifier("Integer")); CollectionTypeImpl type2 = (CollectionTypeImpl)factory1.createSetType(getClassifier("Real")); CollectionTypeImpl type3 = (CollectionTypeImpl)factory1.createSetType(factory1.createSetType(getClassifier("Real"))); CollectionTypeImpl type4 = (CollectionTypeImpl)factory1.createBagType(getClassifier("Integer")); CollectionTypeImpl type5 = (CollectionTypeImpl)factory1.createBagType(getClassifier("Real")); CollectionTypeImpl type6 = (CollectionTypeImpl)factory1.createBagType(getClassifier("Boolean")); CollectionTypeImpl type7 = (CollectionTypeImpl)factory1.createOrderedSetType(getClassifier("Integer")); CollectionTypeImpl type8 = (CollectionTypeImpl)factory1.createSetType(getClassifier("Film")); CollectionTypeImpl type9 = (CollectionTypeImpl)factory1.createSetType(getClassifier("SpecialFilm")); CollectionTypeImpl type10 = (CollectionTypeImpl)factory1.createCollectionType(getClassifier("OclAny")); Assert.AreEqual("Integer", type1.getInnerMostElementType().getName()); Assert.AreEqual("Real", type3.getInnerMostElementType().getName()); Assert.AreEqual("Set(Real)", type1.getMostSpecificCommonSuperType(type2).getName()); Assert.AreEqual("Collection(Integer)", type1.getMostSpecificCommonSuperType(type4).getName()); Assert.AreEqual("Set(OclAny)", type1.getMostSpecificCommonSuperType(type3).getName()); Assert.AreEqual("OclAny", type1.getMostSpecificCommonSuperType(getClassifier("Integer")).getName()); Assert.AreEqual("Collection(Real)", type1.getMostSpecificCommonSuperType(type5).getName()); Assert.AreEqual("Collection(OclAny)", type1.getMostSpecificCommonSuperType(type6).getName()); Assert.IsTrue(getClassifier("Integer").conformsTo(getClassifier("Real"))); Assert.IsTrue(getClassifier("Integer").conformsTo(getClassifier("OclAny"))); Assert.IsTrue(type1.conformsTo(type2)); Assert.IsFalse(type2.conformsTo(type1)); Assert.IsFalse(type1.conformsTo(type3)); Assert.IsFalse(type1.conformsTo(type4)); Assert.IsTrue(type1.conformsTo(type1.getMostSpecificCommonSuperType(type2))); Assert.IsTrue(type1.conformsTo(type1.getMostSpecificCommonSuperType(type5))); Assert.IsTrue(type1.conformsTo(type1.getMostSpecificCommonSuperType(type6))); Assert.IsFalse(type1.conformsTo(getClassifier("Integer"))); Assert.IsTrue(type1.conformsTo(getClassifier("OclAny"))); type1.setInnerMostElementType(getClassifier("Real")); Assert.AreEqual("Real", type1.getInnerMostElementType().getName()); Assert.AreEqual("Set(Real)", type1.getName()); Assert.IsTrue(type7.conformsTo(type1)); Assert.IsFalse(type1.conformsTo(type7)); Assert.IsTrue(type7.conformsTo(type7.createGenericCollectionType(type7.getInnerMostElementType()))); Assert.IsTrue(type9.conformsTo(type8)); Assert.IsTrue(type9.conformsTo(type10)); Assert.IsFalse(type8.conformsTo(type9)); }
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); } }