コード例 #1
0
        /// <summary>
        ///     Provides the type of this expression
        /// </summary>
        /// <returns></returns>
        public override Type GetExpressionType()
        {
            Type retVal = null;

            Type iteratorType = IteratorExpression.GetExpressionType();

            if (iteratorType != null)
            {
                Collection collection = (Collection)acceptor.getFactory().createCollection();
                collection.Enclosing = EfsSystem.Instance;
                collection.Type      = iteratorType;
                Collection originalListType = ListExpression.GetExpressionType() as Collection;
                if (originalListType != null)
                {
                    collection.setMaxSize(originalListType.getMaxSize());
                }

                retVal = collection;
            }
            else
            {
                AddError("Cannot evaluate iterator type for " + ToString(), RuleChecksEnum.SemanticAnalysisError);
            }

            return(retVal);
        }
コード例 #2
0
        /// <summary>
        ///     Creates a colleciton in the namespace provided
        /// </summary>
        /// <param name="enclosing"></param>
        /// <param name="name">The name of the collection</param>
        /// <param name="typeName">The name of the type of the elements in the collection</param>
        /// <param name="maxSize">The maximum collection size</param>
        /// <returns></returns>
        protected Collection CreateCollection(NameSpace enclosing, string name, string typeName, int maxSize)
        {
            Collection retVal = (Collection)Factory.createCollection();

            enclosing.appendCollections(retVal);
            retVal.Name     = name;
            retVal.TypeName = typeName;
            retVal.setMaxSize(maxSize);

            return(retVal);
        }
コード例 #3
0
        public void TestCollectionConcatenation()
        {
            Dictionary dictionary = CreateDictionary("Test");
            NameSpace  nameSpace  = CreateNameSpace(dictionary, "NameSpace");

            Structure        structure  = CreateStructure(nameSpace, "ModelElement");
            StructureElement structElem = CreateStructureElement(structure, "Value", "Boolean");

            structElem.setDefault("True");

            Collection collection = CreateCollection(nameSpace, "Coll", "ModelElement", 10);

            collection.Type = structure;
            collection.setMaxSize(3);
            collection.Default = "[]";

            Variable variable = CreateVariable(nameSpace, "V", "Coll");

            RuleCondition ruleCondition = CreateRuleAndCondition(nameSpace, "Test");
            Action        action        = CreateAction(ruleCondition, "V <- V + [ModelElement{Value => True}] ");

            RuleCheckerVisitor visitor = new RuleCheckerVisitor(dictionary);

            visitor.visit(nameSpace);

            Util.IsThereAnyError isThereAnyError = new Util.IsThereAnyError();
            Assert.AreEqual(0, isThereAnyError.ErrorsFound.Count);
            Assert.AreEqual("[]", variable.Value.LiteralName);

            Runner runner = new Runner(false);

            runner.Cycle();
            Assert.AreEqual("[" + structure.DefaultValue.LiteralName + "]", variable.Value.LiteralName);

            runner.Cycle();
            Assert.AreEqual("[" + structure.DefaultValue.LiteralName + ", " + structure.DefaultValue.LiteralName + "]", variable.Value.LiteralName);

            runner.Cycle();
            Assert.AreEqual("[" + structure.DefaultValue.LiteralName + ", " + structure.DefaultValue.LiteralName + ", " + structure.DefaultValue.LiteralName + "]", variable.Value.LiteralName);

            // In this case, the new collection cannot be placed in the variable
            runner.Cycle();
            Assert.AreEqual(1, action.Messages.Count);
            Assert.AreEqual(ElementLog.LevelEnum.Error, action.Messages[0].Level);
        }