예제 #1
0
 private void    removeAllLinks()
 {
     appliedProperty     = null;
     initializedVariable = null;
     loopExp             = null;
     navigationCallExp   = null;
     parentOperation     = null;
     ifExp           = null;
     thenClause      = null;
     elseClause      = null;
     letExp          = null;
     collectionRange = null;
     collectionItem  = null;
 }
        public void testCollectionLiteralExp()
        {
            AstOclModelElementFactory factory1 = AstOclModelElementFactoryManager.getInstance(umlModel.getOclPackage());

            CollectionLiteralExp exp = factory1.createCollectionLiteralExp(createCollectionParts(),
                                                                           factory1.createSetType(
                                                                               getClassifier("Integer")));

            Assert.AreEqual("Set{ 100, 200, 300 }", exp.ToString());
            Assert.AreEqual("Set(Integer)", exp.getType().getName());

            CollectionLiteralExp exp2 = factory1.createCollectionLiteralExp(createCollectionParts(),
                                                                            factory1.createSetType(
                                                                                getClassifier("Integer")));

            Assert.AreEqual("Set{ 100, 200, 300 }", exp2.ToString());
            Assert.AreEqual("Set(Integer)", exp2.getType().getName());

            exp = factory1.createCollectionLiteralExp(createCollectionParts(),
                                                      factory1.createBagType(getClassifier("Integer")));
            Assert.AreEqual("Bag{ 100, 200, 300 }", exp.ToString());
            Assert.AreEqual("Bag(Integer)", exp.getType().getName());

            exp = factory1.createCollectionLiteralExp(createCollectionParts(),
                                                      factory1.createSequenceType(getClassifier("Integer")));
            Assert.AreEqual("Sequence{ 100, 200, 300 }", exp.ToString());
            Assert.AreEqual("Sequence(Integer)", exp.getType().getName());

            exp = factory1.createCollectionLiteralExp(createCollectionParts(),
                                                      factory1.createOrderedSetType(getClassifier("Integer")));
            Assert.AreEqual("OrderedSet{ 100, 200, 300 }", exp.ToString());
            Assert.AreEqual("OrderedSet(Integer)", exp.getType().getName());

            OclExpression   elem1 = factory1.createIntegerLiteralExp(100, getClassifier("Integer"));
            OclExpression   elem2 = factory1.createIntegerLiteralExp(200, getClassifier("Integer"));
            CollectionRange range = factory1.createCollectionRange(elem1, elem2);
            List <object>   parts = new List <object> ();

            parts.Add(range);
            exp = factory1.createCollectionLiteralExp(parts, factory1.createSetType(getClassifier("Integer")));
            Assert.AreEqual("Set{ 100 .. 200 }", exp.ToString());
            Assert.AreEqual("Set(Integer)", exp.getType().getName());
        }
예제 #3
0
        public void Visit(CollectionLiteralExp node)
        {
            foreach (CollectionLiteralPart collectionLiteralPart in node.Parts)
            {
                CollectionItem item = collectionLiteralPart as CollectionItem;
                if (item != null)
                {
                    Expressions.Add(item.Item);
                    item.Item.Accept(this);
                }

                CollectionRange range = collectionLiteralPart as CollectionRange;
                if (range != null)
                {
                    Expressions.Add(range.First);
                    Expressions.Add(range.Last);
                    range.First.Accept(this);
                    range.Last.Accept(this);
                }
            }
        }
예제 #4
0
        public void Visit(CollectionLiteralExp node)
        {
            CollectionType col = (CollectionType)node.Type;

            sb.AppendFormat("{0}  ", col.Name);
            PrintArgs(node.Parts, ",", part => {
                if (part is CollectionRange)
                {
                    CollectionRange range = (CollectionRange)part;
                    range.First.Accept(this);
                    sb.Append("..");
                    range.Last.Accept(this);
                }
                else if (part is CollectionItem)
                {
                    CollectionItem item = (CollectionItem)part;
                    item.Item.Accept(this);
                }
            });
            sb.Append("}");
        }
예제 #5
0
        public virtual void Visit(CollectionLiteralExp node)
        {
            AssignIsPartOfIteratorBody(node);
            StringBuilder        formatBuilder  = new StringBuilder();
            List <OclExpression> subExpressions = new List <OclExpression>();

            // opening parenthesis of xpath sequence literal
            formatBuilder.Append("(");
            foreach (CollectionLiteralPart clp in node.Parts)
            {
                #region helper function
                Action <OclExpression> appendOne = delegate(OclExpression exp)
                {
                    if (exp is LiteralExp)
                    {
                        formatBuilder.Append("{");
                        formatBuilder.Append(subExpressions.Count);
                        formatBuilder.Append("}");
                    }
                    else
                    {
                        formatBuilder.Append("{(");
                        formatBuilder.Append(subExpressions.Count);
                        formatBuilder.Append(")}");
                    }
                };
                #endregion

                if (clp is CollectionRange)
                {
                    CollectionRange range = ((CollectionRange)clp);
                    range.First.Accept(this);
                    range.Last.Accept(this);

                    appendOne(range.First);
                    subExpressions.Add(range.First);
                    formatBuilder.Append(" to ");
                    appendOne(range.Last);
                    subExpressions.Add(range.Last);
                }

                if (clp is CollectionItem)
                {
                    CollectionItem collectionItem = (CollectionItem)clp;
                    collectionItem.Item.Accept(this);
                    appendOne(collectionItem.Item);
                    subExpressions.Add(collectionItem.Item);
                }
                formatBuilder.Append(", ");
            }

            if (formatBuilder.Length > 1) // remove last comma
            {
                formatBuilder.Length = formatBuilder.Length - 2;
            }

            // closing parenthesis of xpath sequence literal
            formatBuilder.Append(")");

            TranslationOption option = new TranslationOption();
            option.FormatString = formatBuilder.ToString();
            SubexpressionTranslations.AddTranslationOption(node, option, subExpressions.ToArray());
        }
예제 #6
0
 /**
  * @param collectionRange The collectionRange to set.
  */
 public void setCollectionRange(CollectionRange collectionRange)
 {
     removeAllLinks();
     this.collectionRange = collectionRange;
 }