Пример #1
0
        public IteratorExp createIteratorExp(
            String name,
            CoreClassifier type,
            OclExpression source,
            OclExpression body,
            List <object> iterators)
        {
            IteratorExp exp = new IteratorExpImpl();

            exp.setFactory(this);

            exp.setType(type);
            exp.setSource(source);
            exp.setBody(body);
            exp.setName(name);

            if (iterators != null)
            {
                foreach (VariableDeclaration var in iterators)
                {
                    var.setLoopExp(exp);
                    ((IteratorExpImpl)exp).addIterator(var);
                }
            }
            if (body != null)
            {
                ((OclExpressionImpl)body).setLoopExp(exp);
            }
            if (source != null)
            {
                ((OclExpressionImpl)source).setAppliedProperty(exp);
            }

            return(exp);
        }
        protected PrimitiveLiteralExp   checkPrimitiveLiteralExp(OclExpression oclExpression)
        {
            Assert.IsTrue(oclExpression is PrimitiveLiteralExp);
            PrimitiveLiteralExp exp = (PrimitiveLiteralExp)oclExpression;

            return(exp);
        }
Пример #3
0
        public void testClassifierAttribute_05()
        {
            CoreClassifier film      = (CoreClassifier)environment.lookup("Film");
            CoreOperation  operation = film.lookupOperation("getTapes", null);

            Assert.AreEqual(0, operation.getSpecifications().Count);

            List <object> constraints =
                doTestManyContextOK("context Film::getTapes() : Set(Tape) post: self.rentalFee@pre = 10 ",
                                    getCurrentMethodName());

            film      = (CoreClassifier)environment.lookup("Film");
            operation = film.lookupOperation("getTapes", null);
            Assert.AreEqual(1, operation.getSpecifications().Count);
            OclPrePostConstraint constraint = (OclPrePostConstraint)operation.getSpecifications()[0];
            OclPostConstraint    post       = (OclPostConstraint)constraint.getPostConditions()[0];

            OclExpression oclExpression = ((ExpressionInOclImpl)post.getExpression()).getBodyExpression();

            this.checkOperationCallExp(((OperationCallExp)oclExpression), "=", "Boolean");
            OperationCallExp opCall = (OperationCallExp)((OperationCallExp)oclExpression);
            AttributeCallExp attExp = checkAttributeCallExp(opCall.getSource(), "rentalFee", "Integer");

            opCall = (OperationCallExp)((AttributeCallExp)opCall.getSource()).getSource();
            this.checkOperationCallExp(opCall, "atPre", "Film");
            checkImplicitSource(opCall, "self", "Film");
        }
 public override bool Visit(ClassLiteralExp node)
 {
     /* Class literals we can't handle yet */
     isSuitable          = false;
     violatingExpression = node;
     return(false);
 }
        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);
            }
        }
 public override bool Visit(EnumLiteralExp node)
 {
     /* For simplicity we do not allow this yet */
     violatingExpression = node;
     isSuitable          = false;
     return(false);
 }
Пример #7
0
        public virtual void Visit(OperationCallExp node)
        {
            AssignIsPartOfIteratorBody(node);
            OclExpression[] arguments = new OclExpression[node.Arguments.Count + 1];
            if (node.Source is PropertyCallExp)
            {
                this.Visit((PropertyCallExp)node.Source, true);
            }
            else
            {
                node.Source.Accept(this);
            }

            arguments[0] = node.Source;
            for (int i = 0; i < node.Arguments.Count; i++)
            {
                if (node.Arguments[i] is PropertyCallExp)
                {
                    this.Visit((PropertyCallExp)node.Arguments[i], true);
                }
                else
                {
                    node.Arguments[i].Accept(this);
                }
                arguments[i + 1] = node.Arguments[i];
            }

            TranslationOption option = new TranslationOption();

            option.FormatString = OperationHelper.CreateBasicFormatString(node, arguments);
            this.SubexpressionTranslations.AddTranslationOption(node, option, arguments);
        }
Пример #8
0
        protected void checkOperationCallType(OclExpression oclExpression, String typeName, String operationName, Type sourceClass, String sourceType, Object[] argTypes)
        {
            Assert.IsTrue(oclExpression is OperationCallExp);
            OperationCallExp exp = (OperationCallExp)oclExpression;

            Assert.AreEqual(typeName, exp.getType().getName());
            Assert.IsTrue(exp.getReferredOperation().operationNameMatches(operationName));

            if (sourceClass != null)
            {
                Assert.IsTrue(sourceClass.IsInstanceOfType(exp.getSource()));
                Assert.AreEqual(exp.getSource().getType().getName(), sourceType);
            }
            else
            {
                Assert.IsFalse(exp.getReferredOperation().isInstanceScope());
            }
            if (argTypes == null)
            {
                Assert.AreEqual(0, exp.getArguments().Count);
            }
            else
            {
                Assert.AreEqual(argTypes.Length, exp.getArguments().Count);
            }
        }
Пример #9
0
        public AssociationClassCallExp createAssociationClassCallExp(
            OclExpression source,
            CoreAssociationClass referredAssociationClass,
            CoreAssociationEnd navigationSource,
            List <object> qualifiers,
            bool isMarkedPre)
        {
            AssociationClassCallExpImpl exp = new AssociationClassCallExpImpl();

            exp.setFactory(this);

            exp.setReferredAssociationClass(referredAssociationClass);
            exp.setNavigationSource(navigationSource);
            exp.setSource(isMarkedPre ? createAtPreOperation(source) : source);
            if (qualifiers != null)
            {
                foreach (OclExpression qualifier in qualifiers)
                {
                    ((OclExpressionImpl)qualifier).setNavigationCallExp(exp);
                    ((AssociationClassCallExpImpl)exp).addQualifier(qualifier);
                }
            }
            CoreAssociationEnd assocEnd = navigationSource != null ? navigationSource : referredAssociationClass.lookupAssociationEnd(source.getType());

            exp.setType(((AssociationClassCallExpImpl)exp).getExpressionType(source, assocEnd, referredAssociationClass));

            ((OclExpressionImpl)source).setAppliedProperty(exp);
            return(exp);
        }
Пример #10
0
        private void ResolveChildParm(OclExpression node, int fatherPriority)
        {
            if (node is OperationCallExp == false)
            {
                node.Accept(this);
                return;
            }
            OperationCallExp op = (OperationCallExp)node;
            int opPriority;

            if (isInfixOp(op, out opPriority) == false)
            {
                node.Accept(this);
                return;
            }

            bool needParenthesis = fatherPriority < opPriority;

            if (needParenthesis)
            {
                sb.Append("(");
            }
            node.Accept(this);
            if (needParenthesis)
            {
                sb.Append(")");
            }
        }
Пример #11
0
        public AttributeCallExp createAttributeCallExp(
            OclExpression source,
            CoreAttribute attribute,
            bool isMarkedPre)
        {
            AttributeCallExp exp = new AttributeCallExpImpl();

            exp.setFactory(this);

            exp.setSource(isMarkedPre ? createAtPreOperation(source) : source);
            exp.setReferredAttribute(attribute);

            CoreClassifier expType;

            if (attribute.isOclDefined())
            {
                expType = attribute.getFeatureType();
            }
            else
            {
                expType = attribute.getModel() != null?attribute.getModel().toOclType(attribute.getFeatureType()) : attribute.getFeatureType();
            }
            exp.setType(((AttributeCallExpImpl)exp).getExpressionType(source, expType));

            if (source != null)
            {
                ((OclExpressionImpl)source).setAppliedProperty(exp);
            }

            return(exp);
        }
Пример #12
0
        public OperationCallExp createOperationCallExp(
            OclExpression source,
            CoreOperation operation,
            List <object> arguments,
            CoreClassifier returnType,
            bool isMarkedPre)
        {
            OperationCallExp exp = new OperationCallExpImpl();

            exp.setFactory(this);

            exp.setReferredOperation(operation);
            exp.setType(returnType);
            exp.setSource((isMarkedPre ? createAtPreOperation(source) : source));
            if (arguments != null)
            {
                foreach (OclExpression argument in arguments)
                {
                    ((OclExpressionImpl)argument).setParentOperation(exp);
                    ((OperationCallExpImpl)exp).addArgument(argument);
                }
            }
            ((OclExpressionImpl)source).setAppliedProperty(exp);

            return(exp);
        }
 public override bool Visit(TypeExp node)
 {
     /* Types we can't handle yet */
     isSuitable          = false;
     violatingExpression = node;
     return(false);
 }
        public String  getArgumentsAsString()
        {
            StringBuilder result = new StringBuilder();

            int length = getArguments().Count;
            int index  = 0;

            foreach (OclExpression argument in getArguments())
            {
                result.Append(argument.ToString());
                if (index < length - 1)
                {
                    result.Append(", ");
                }
                index++;
            }

            if (isBasicOperator(this.getReferredOperation().getName()) && this.getArguments().Count == 1)
            {
                OclExpression argument = (OclExpression)this.getArguments()[0];
                if (argument is OperationCallExpImpl && isBasicOperator(((OperationCallExp)argument).getReferredOperation().getName()))
                {
                    return("(" + result.ToString() + ")");
                }
            }

            return(result.ToString());
        }
Пример #15
0
        public void testAssociationEndCallExp_01()
        {
            List <object>         constraints   = doTestContextOK("context Empregado inv: area = area ", getCurrentMethodName());
            OclExpression         oclExpression = getConstraintExpression(constraints);
            AssociationEndCallExp exp           = checkAssociationEndCallExp(((OperationCallExp)oclExpression).getSource(), "area", "Area");

            checkImplicitSource(exp, "self", "Empregado");
        }
Пример #16
0
        protected CollectionLiteralExp  checkCollectionLiteralExp(OclExpression oclExpression, String type)
        {
            Assert.IsTrue(oclExpression is CollectionLiteralExp);
            CollectionLiteralExp exp = (CollectionLiteralExp)oclExpression;

            Assert.AreEqual(type, exp.getType().getName());
            return(exp);
        }
Пример #17
0
        public void testAssociationEndCallExp_07()
        {
            List <object> constraints = doTestContextOK("context RentalItem inv: self.Rental.Client = self.Rental.Client",
                                                        getCurrentMethodName());

            OclExpression         oclExpression = getConstraintExpression(constraints);
            AssociationEndCallExp exp           = checkAssociationEndCallExp(((OperationCallExp)oclExpression).getSource(), "Client", "Client");
        }
Пример #18
0
        private CoreClassifier checkResult(CSTNode rootNode, String expectedTypeName)
        {
            CSTArgumentCS argument = (CSTArgumentCS)rootNode;
            OclExpression ast      = argument.getAst();

            Assert.AreEqual(expectedTypeName, ast.getType().getName());
            return(ast.getType());
        }
Пример #19
0
        public void testAddExp_01()
        {
            List <object>         constraints   = doTestContextOK("context Empregado inv: salario + 1000.0 < 2000.0", getCurrentMethodName());
            OclExpression         oclExpression = getConstraintExpression(constraints);
            AssociationEndCallExp exp           = checkAssociationEndCallExp(((OperationCallExp)oclExpression).getSource(), "empregados", "Set(Empregado)");

            checkImplicitSource(exp, "self", "Area");
        }
Пример #20
0
        public void testAssociationEndCallExp_10()
        {
            List <object> constraints = doTestContextOK("context SpecialFilm inv: self.tapes[1] = tapes[2]",
                                                        getCurrentMethodName());

            OclExpression         oclExpression = getConstraintExpression(constraints);
            AssociationEndCallExp exp           = checkAssociationEndCallExp(((OperationCallExp)oclExpression).getSource(), "tapes", "Tape");
        }
Пример #21
0
        public void testAttributeCallExp_02()
        {
            List <object>    constraints   = doTestContextOK("context Empregado inv: self.nome = nome", getCurrentMethodName());
            OclExpression    oclExpression = getConstraintExpression(constraints);
            AttributeCallExp attExp        = checkAttributeCallExp(((OperationCallExp)oclExpression).getSource(), "nome", "String");

            checkImplicitSource(attExp, "self", "Empregado");
        }
Пример #22
0
        public OperationCallExp createAsSetOperation(OclExpression source)
        {
            OperationCallExp exp = createOperationCallExp(createSpecificCollectionType(CollectionKindEnum.SET, source.getType()),
                                                          source, "asSet", new List <object>(), false);

            exp.setFactory(this);
            return(exp);
        }
Пример #23
0
        public OperationCallExp createAtPreOperation(OclExpression source)
        {
            OperationCallExp exp = createOperationCallExp(source.getType(), source, "atPre",
                                                          new List <object>(), false);

            exp.setFactory(this);
            return(exp);
        }
Пример #24
0
        public void testAssocClass_04()
        {
            List <object> constraints = doTestContextOK("context Distributor inv: self.Allocation = self.Allocation",
                                                        getCurrentMethodName());

            OclExpression oclExpression = getConstraintExpression(constraints);

            checkAssociationClassCallExp(((OperationCallExp)oclExpression).getSource(), "Allocation", "Set(Allocation)");
        }
Пример #25
0
        public void testSetDifference_01()
        {
            List <object> constraints = doTestContextOK("context Film inv: Set{1, 2, 3} - Set { 2, 3 } = Set { 1, 2 }",
                                                        getCurrentMethodName());

            OclExpression oclExpression = ((OperationCallExp)getConstraintExpression(constraints)).getSource();

            checkOperationCallType(oclExpression, "Set(Integer)", "-", typeof(CollectionLiteralExp), "Set(Integer)", new Object[] { "Set(Integer)" });
        }
Пример #26
0
        public void testExists_07()
        {
            List <object> constraints = doTestContextOK("context Film inv: " +
                                                        "Set{ 1, 2, 3}->forAll(i | i > 0)", getCurrentMethodName());

            OclExpression oclExpression = getConstraintExpression(constraints);

            checkIteratorExp(oclExpression, "Boolean", "forAll", "Integer", "i");
        }
Пример #27
0
        protected AssociationClassCallExp checkAssociationClassCallExp(OclExpression oclExpression, String roleName, String typeName)
        {
            Assert.IsTrue(oclExpression is AssociationClassCallExp);
            AssociationClassCallExp exp = (AssociationClassCallExp)oclExpression;

            Assert.AreEqual(roleName, exp.getReferredAssociationClass().getName());
            Assert.AreEqual(typeName, exp.getType().getName());
            return(exp);
        }
Пример #28
0
        protected AttributeCallExp checkAttributeCallExp(OclExpression oclExpression, String attName, String attType)
        {
            Assert.IsTrue(oclExpression is AttributeCallExp);
            AttributeCallExp attExp = (AttributeCallExp)oclExpression;

            Assert.AreEqual(attName, attExp.getReferredAttribute().getName());
            Assert.AreEqual(attType, attExp.getType().getName());
            return(attExp);
        }
Пример #29
0
        public void testAssocClass_03()
        {
            List <object> constraints = doTestContextOK("context Allocation inv: self.dist= self.dist",
                                                        getCurrentMethodName());

            OclExpression oclExpression = getConstraintExpression(constraints);

            checkAssociationEndCallExp(((OperationCallExp)oclExpression).getSource(), "dist", "Distributor");
        }
Пример #30
0
        public void testAssocClass_06()
        {
            List <object> constraints = doTestContextOK("context Person inv: EmployeeRanking[bosses] = EmployeeRanking[employees]",
                                                        getCurrentMethodName());

            OclExpression oclExpression = getConstraintExpression(constraints);

            checkAssociationClassCallExp(((OperationCallExp)oclExpression).getSource(), "EmployeeRanking", "Set(EmployeeRanking)");
        }