Beispiel #1
0
        /* (non-Javadoc)
         * @see br.cos.ufrj.lens.odyssey.tools.psw.metamodels.ocl20.Factory#createOrderedSetType(br.cos.ufrj.lens.odyssey.tools.psw.metamodels.core.interfaces.CoreClassifier)
         */
        public OrderedSetType createOrderedSetType(
            CoreClassifier elementType)
        {
            OrderedSetType result = (OrderedSetType)getCollectionType("OrderedSet(" + elementType.getName() + ")");

            if (result == null)
            {
                result = oclPackage.getTypes().getOrderedSetType();
                result.setFactory(this);
                result.setElementType(elementType);
                allTypesCreated.Add(result.getName(), result);
            }

            return(result);
        }
Beispiel #2
0
        public CollectionType CreateCollection(CollectionKind kind, Classifier elementType,
                                               bool deferFullInitialization = false, List <CollectionType> deferredCollectionList = null)
        {
            CollectionType newType;
            var            tupleCacheKey = new Tuple <Classifier, CollectionKind>(elementType, kind);

            if (collectionTypeCache.ContainsKey(tupleCacheKey))
            {
                return(collectionTypeCache[tupleCacheKey]);
            }

            if (kind == CollectionKind.Collection)
            {
                newType = new CollectionType(TypeTable, elementType, Any);
            }
            else
            {
                CollectionType inheritFrom;                // = CreateCollection(CollectionKind.Collection, elementType, deferFullInitialization, deferredCollectionList);
                switch (kind)
                {
                case CollectionKind.Bag:
                    inheritFrom = CreateCollection(CollectionKind.Collection, elementType, deferFullInitialization, deferredCollectionList);
                    newType     = new BagType(TypeTable, elementType, inheritFrom);
                    break;

                case CollectionKind.Collection:
                    newType = null;
                    System.Diagnostics.Debug.Fail("Hups.");
                    break;

                case CollectionKind.OrderedSet:
                    inheritFrom = CreateCollection(CollectionKind.Collection, elementType, deferFullInitialization, deferredCollectionList);
                    newType     = new OrderedSetType(TypeTable, elementType, inheritFrom);
                    break;

                case CollectionKind.Sequence:
                    inheritFrom = CreateCollection(CollectionKind.Collection, elementType, deferFullInitialization, deferredCollectionList);
                    newType     = new SequenceType(TypeTable, elementType, inheritFrom);
                    break;

                case CollectionKind.Set:
                    inheritFrom = CreateCollection(CollectionKind.Collection, elementType, deferFullInitialization, deferredCollectionList);
                    newType     = new SetType(TypeTable, elementType, inheritFrom);
                    break;

                default:
                    newType = null;
                    System.Diagnostics.Debug.Fail("CreateCollectionType( ... ): missing case for CollectionKind.");
                    break;
                }
            }

            newType.DeferredFullInitialization = deferFullInitialization;

            if (!deferFullInitialization)
            {
                PerformDeferredInitialization(newType);
            }
            else
            {
                deferredCollectionList.Add(newType);
            }

            TypeTable.RegisterType(newType);
            collectionTypeCache[tupleCacheKey] = newType;
            return(newType);
        }
Beispiel #3
0
        public void CommonSuperTypeTest()
        {
            TypesTable             typesTable = new TypesTable();
            StandardLibraryCreator sl         = new StandardLibraryCreator();

            sl.CreateStandardLibrary(typesTable);

            Classifier integerType = typesTable.Library.Integer;
            Classifier realType    = typesTable.Library.Real;
            Classifier anyType     = typesTable.Library.Any;


            Classifier unlimitedType = typesTable.Library.UnlimitedNatural;
            Classifier stringType    = typesTable.Library.String;



            Assert.AreEqual(integerType.CommonSuperType(realType), realType);         //real,integer -> real
            Assert.AreEqual(realType.CommonSuperType(realType), realType);            //real,real -> real
            Assert.AreEqual(realType.CommonSuperType(integerType), realType);         //integer,real -> real
            Assert.AreEqual(unlimitedType.CommonSuperType(realType), realType);       //unlimited,real -> real
            Assert.AreEqual(integerType.CommonSuperType(unlimitedType), integerType); //integer,unlimited -> integer
            Assert.AreEqual(stringType.CommonSuperType(integerType), anyType);        // string,integer -> anytype


            //Collection
            BagType        bagIntegerType  = (BagType)typesTable.Library.CreateCollection(Exolutio.Model.OCL.CollectionKind.Bag, integerType);
            BagType        bagRealType     = (BagType)typesTable.Library.CreateCollection(Exolutio.Model.OCL.CollectionKind.Bag, realType);
            SetType        setType         = (SetType)typesTable.Library.CreateCollection(Exolutio.Model.OCL.CollectionKind.Set, integerType);
            SequenceType   seqType         = (SequenceType)typesTable.Library.CreateCollection(Exolutio.Model.OCL.CollectionKind.Sequence, integerType);
            OrderedSetType ordType         = (OrderedSetType)typesTable.Library.CreateCollection(Exolutio.Model.OCL.CollectionKind.OrderedSet, integerType);
            CollectionType collIntegerType = typesTable.Library.CreateCollection(Exolutio.Model.OCL.CollectionKind.Collection, integerType);
            CollectionType collRealType    = typesTable.Library.CreateCollection(Exolutio.Model.OCL.CollectionKind.Collection, realType);;


            Assert.AreEqual(setType.CommonSuperType(setType), setType);                         //set(integer),set(integer) -> set(integer)
            Assert.AreEqual(setType.CommonSuperType(ordType), collIntegerType);                 //set(integer),ord(integer) -> coll(integer)
            Assert.AreEqual(setType.CommonSuperType(collIntegerType), collIntegerType);         //set(integer),coll(Integer) -> coll(integer)
            Assert.AreEqual(collIntegerType.CommonSuperType(collIntegerType), collIntegerType); //coll(integer),coll(integer) -> coll(integer)
            Assert.AreEqual(collIntegerType.CommonSuperType(bagIntegerType), collIntegerType);  //coll(integer),bag(integer) -> coll(integer)
            Assert.AreEqual(collIntegerType.CommonSuperType(bagRealType), collRealType);        // coll(Integer),bag(real) -> coll(real)
            Assert.AreEqual(setType.CommonSuperType(bagRealType), collRealType);                // set(integer),bag(real) ->col(real)
            Assert.AreEqual(ordType.CommonSuperType(ordType), ordType);                         // ord(integer),ord(integer) -> ord(integer)
            Assert.AreEqual(seqType.CommonSuperType(seqType), seqType);                         // seq(integer),seq(integer) -> seq(integer)

            Assert.AreEqual(setType.CommonSuperType(realType), anyType);                        //set(integer),real -> any

            //void test
            Classifier voidType = typesTable.Library.Void;

            Assert.AreEqual(voidType.CommonSuperType(integerType), integerType);
            Assert.AreEqual(realType.CommonSuperType(voidType), realType);
            Assert.AreEqual(voidType.CommonSuperType(seqType), seqType);
            Assert.AreEqual(collIntegerType.CommonSuperType(voidType), collIntegerType);
            Assert.AreEqual(voidType.CommonSuperType(anyType), anyType);

            //any test
            Assert.AreEqual(integerType.CommonSuperType(anyType), anyType);
            Assert.AreEqual(anyType.CommonSuperType(stringType), anyType);
            Assert.AreEqual(anyType.CommonSuperType(setType), anyType);
            Assert.AreEqual(setType.CommonSuperType(anyType), anyType);

            //tuple test
            List <Property> tupleParts1 = new List <Property>();

            tupleParts1.Add(new Property("prop1", PropertyType.Many, integerType));
            tupleParts1.Add(new Property("prop2", PropertyType.Many, integerType));
            tupleParts1.Add(new Property("prop3", PropertyType.Many, realType));
            TupleType tuple1 = new TupleType(typesTable, tupleParts1);


            typesTable.RegisterType(tuple1);

            List <Property> tupleParts2 = new List <Property>();

            tupleParts2.Add(new Property("prop1", PropertyType.Many, integerType));
            tupleParts2.Add(new Property("prop4", PropertyType.Many, integerType));
            tupleParts2.Add(new Property("prop3", PropertyType.One, anyType));
            TupleType tuple2 = new TupleType(typesTable, tupleParts2);


            typesTable.RegisterType(tuple2);

            TupleType tupleCommon = (TupleType)tuple1.CommonSuperType(tuple2);

            Assert.AreEqual(tupleCommon.TupleParts.Count, 2);
            Assert.AreEqual(tupleCommon["prop1"].PropertyType, tuple1["prop1"].PropertyType);
            Assert.AreEqual(tupleCommon["prop1"].Type, tuple1["prop1"].Type);


            Assert.AreEqual(tupleCommon["prop3"].PropertyType, tuple1["prop3"].PropertyType);
            Assert.AreEqual(tupleCommon["prop3"].Type, tuple2["prop3"].Type);

            Assert.AreEqual(tuple1.CommonSuperType(voidType), tuple1);
            Assert.AreEqual(tuple1.CommonSuperType(anyType), anyType);

            Assert.AreEqual(voidType.CommonSuperType(tuple1), tuple1);
            Assert.AreEqual(anyType.CommonSuperType(tuple1), anyType);

            Assert.AreEqual(tuple2.CommonSuperType(integerType), anyType);
            Assert.AreEqual(realType.CommonSuperType(tuple2), anyType);
        }