示例#1
0
        public void testLetOK_03()
        {
            List <object> constraints = doTestContextOK("context Film inv: let x : Integer = 20, y : Real = 40.10 in x > 0 ",
                                                        getCurrentMethodName());

            foreach (CSTInvariantCS constraint in constraints)
            {
                CSTExpressionInOclCS expression    = constraint.getExpressionNodeCS();
                OclExpression        oclExpression = ((ExpressionInOclImpl)expression.getAst()).getBodyExpression();

                Assert.IsTrue(oclExpression is LetExp);
                LetExp exp = (LetExp)oclExpression;

                Assert.AreEqual("Boolean", exp.getType().getName());
            }
        }
        public void testLetExp()
        {
            AstOclModelElementFactory factory1 = AstOclModelElementFactoryManager.getInstance(umlModel.getOclPackage());

            OclExpression       initExp  = factory1.createIntegerLiteralExp(100, getClassifier("Integer"));
            VariableDeclaration variable = factory1.createVariableDeclaration("abc", getClassifier("Integer"), initExp);

            OclExpression varExp     = factory1.createVariableExp(variable);
            OclExpression intLiteral = factory1.createIntegerLiteralExp(200, getClassifier("Integer"));
            List <object> paramTypes = new List <object>();

            paramTypes.Add(getClassifier("Integer"));
            CoreOperation oper = getClassifier("Integer").lookupOperation("+", paramTypes);

            List <object> args = new List <object> ();

            args.Add(intLiteral);
            OclExpression inExp = factory1.createOperationCallExp(varExp, oper, args, getClassifier("Integer"), false);

            LetExp exp = factory1.createLetExp(variable, inExp);

            Assert.AreEqual("let abc : Integer = 100 in abc + 200", exp.ToString());
            Assert.AreEqual("Integer", exp.getType().getName());
        }