public void testOperationCallExp()
        {
            AstOclModelElementFactory factory1 = AstOclModelElementFactoryManager.getInstance(umlModel.getOclPackage());

            VariableDeclaration variable = factory1.createVariableDeclaration("abc", getClassifier("Film"), null);
            VariableExp         source   = factory1.createVariableExp(variable);

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

            paramTypes.Add(getClassifier("Integer"));

            CoreOperation operation = getClassifier("Film").lookupOperation("getRentalFee", paramTypes);

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

            arguments.Add(factory1.createIntegerLiteralExp(100, getClassifier("Integer")));

            OperationCallExp exp = factory1.createOperationCallExp(source, operation, arguments,
                                                                   operation.getReturnType(), false);

            Assert.AreEqual("abc.getRentalFee(100)", exp.ToString());
            Assert.AreEqual("Real", exp.getType().getName());

            CollectionLiteralExp literalCollection = factory1.createCollectionLiteralExp(createCollectionParts(),
                                                                                         factory1.createSetType(
                                                                                             getClassifier("Integer")));
            CollectionTypeImpl type1          = (CollectionTypeImpl)factory1.createSetType(getClassifier("Integer"));
            CoreOperation      collectionOper = type1.lookupOperation("size", new List <object>());

            OperationCallExp exp1 = factory1.createOperationCallExp(literalCollection, collectionOper, new List <object>(),
                                                                    getClassifier("Integer"), false);

            Assert.IsNotNull(exp1);
        }
Exemple #2
0
 public override int GetHashCode()
 {
     unchecked
     {
         return((base.GetHashCode() * 397) ^ (VariableExp != null ? VariableExp.GetHashCode() : 0));
     }
 }
        protected void checkImplicitSource(PropertyCallExp exp, String varName, String varType)
        {
            Assert.IsTrue(exp.getSource() is VariableExp);
            VariableExp varExp = (VariableExp)exp.getSource();

            Assert.AreEqual(varType, exp.getSource().getType().getName());
            Assert.AreEqual(varName, varExp.getReferredVariable().getVarName());
        }
Exemple #4
0
        private OclExpression CreateExpressionFromPath(PSMPath psmPath)
        {
            VariableExp   startVarExp      = new VariableExp(psmPath.StartingVariableExp.referredVariable);
            OclExpression result           = startVarExp;
            Classifier    sourceClassifier = startVarExp.Type;

            foreach (PSMPathStep step in psmPath.Steps)
            {
                if (step is PSMPathVariableStep)
                {
                    continue;
                }
                Property referredProperty;
                if (step is PSMPathAssociationStep)
                {
                    PSMPathAssociationStep pathAssociationStep = ((PSMPathAssociationStep)step);
                    referredProperty = sourceClassifier.LookupProperty(pathAssociationStep.Association.Name);
                    if (referredProperty == null)
                    {
                        if (pathAssociationStep.IsUp)
                        {
                            referredProperty = sourceClassifier.LookupProperty(PSMBridgeAssociation.PARENT_STEP);
                        }
                        else
                        {
                            referredProperty = sourceClassifier.LookupProperty(string.Format(PSMBridgeAssociation.CHILD_N_STEP,
                                                                                             pathAssociationStep.From.ChildPSMAssociations.IndexOf(pathAssociationStep.Association)));
                        }
                    }
                }
                else if (step is PSMPathAttributeStep)
                {
                    referredProperty = sourceClassifier.LookupProperty(((PSMPathAttributeStep)step).Attribute.Name);
                }
                else
                {
                    throw new NotImplementedException();
                }

                Property        navigationSource = null;
                OclExpression   qualifier        = null;
                PropertyCallExp propertyCallExp  = new PropertyCallExp(result, false, navigationSource, qualifier, referredProperty);
                result = propertyCallExp;

                if (step is PSMPathAssociationStep)
                {
                    sourceClassifier = psmBridge.Find(((PSMPathAssociationStep)step).To);
                }
                // else => no other steps
            }
            return(result);
        }
        public void testAssociationEndCallExp_08()
        {
            AstOclModelElementFactory factory1 = AstOclModelElementFactoryManager.getInstance(umlModel.getOclPackage());

            VariableDeclaration variable = factory1.createVariableDeclaration("abc", getClassifier("Allocation"), null);
            VariableExp         source   = factory1.createVariableExp(variable);

            CoreAssociationEnd assocEnd = getClassifier("Allocation").lookupAssociationEnd("films");

            AssociationEndCallExp exp1 = factory1.createAssociationEndCallExp(source, assocEnd, null, null, false);

            Assert.AreEqual("abc.films", exp1.ToString());
            Assert.AreEqual("SpecialFilm", exp1.getType().getName());
        }
        public void testAssociationEndCallExp_07()
        {
            AstOclModelElementFactory factory1 = AstOclModelElementFactoryManager.getInstance(umlModel.getOclPackage());

            VariableDeclaration variable = factory1.createVariableDeclaration("abc", getClassifier("Reservation"), null);
            VariableExp         source   = factory1.createVariableExp(variable);

            CoreAssociationEnd assocEnd = getClassifier("Reservation").lookupAssociationEnd("Person");

            AssociationEndCallExp exp1 = factory1.createAssociationEndCallExp(source, assocEnd, null, null, true);

            Assert.AreEqual("abc.Person@pre", exp1.ToString());
            Assert.AreEqual("Person", exp1.getType().getName());
        }
        public void testIfExp()
        {
            AstOclModelElementFactory factory1 = AstOclModelElementFactoryManager.getInstance(umlModel.getOclPackage());

            VariableDeclaration variable  = factory1.createVariableDeclaration("abc", getClassifier("Boolean"), null);
            VariableExp         condition = factory1.createVariableExp(variable);

            IntegerLiteralExp thenExp = factory1.createIntegerLiteralExp(100, getClassifier("Integer"));
            RealLiteralExp    elseExp = factory1.createRealLiteralExp("247.49", getClassifier("Real"));

            IfExp exp = factory1.createIfExp(condition, thenExp, elseExp);

            Assert.AreEqual("if abc then 100 else 247.49 endif", exp.ToString());
            Assert.AreEqual("Real", exp.getType().getName());
        }
Exemple #8
0
        public void testVariableExp_01()
        {
            List <object> constraints = doTestContextOK("context Film inv: self = self",
                                                        getCurrentMethodName());

            OclExpression oclExpression = getConstraintExpression(constraints);

            Assert.IsTrue(((OperationCallExp)oclExpression).getSource() is VariableExp);
            VariableExp varExp = (VariableExp)((OperationCallExp)oclExpression).getSource();

            Assert.AreEqual("self", varExp.getReferredVariable().getVarName());
            Assert.AreEqual("Film", varExp.getType().getName());
            Assert.AreEqual("Film", varExp.getReferredVariable().getType().getName());
            Assert.IsNull(varExp.getReferredVariable().getInitExpression());
        }
Exemple #9
0
        public virtual void Visit(VariableExp node)
        {
            AssignIsPartOfIteratorBody(node);
            PSMPath psmPath = PSMPathBuilder.BuildPSMPath(node, OclContext, VariableNamer, buildPathParams);
            string  xpath   = psmPath.ToXPath(delayFirstVariableStep: true);

            TranslationOption option = new TranslationOption();

            if (psmPath.StartingVariableExp != null)
            {
                option.ContextVariableSubstitution = true;
                option.StartingVariable            = psmPath.StartingVariableExp.referredVariable;
            }
            option.FormatString = xpath;
            SubexpressionTranslations.AddTranslationOption(node, option, psmPath.SubExpressions.ToArray());
        }
        public void testAssociationEndCallExp_06()
        {
            AstOclModelElementFactory factory1 = AstOclModelElementFactoryManager.getInstance(umlModel.getOclPackage());

            VariableDeclaration variable = factory1.createVariableDeclaration("abc", getClassifier("Person"), null);
            VariableExp         source   = factory1.createVariableExp(variable);

            CoreAssociationEnd    bosses    = getClassifier("Person").lookupAssociationEnd("bosses");
            CoreAssociationEnd    employees = getClassifier("Person").lookupAssociationEnd("employees");
            AssociationEndCallExp sourceExp = factory1.createAssociationEndCallExp(source, bosses, employees, null,
                                                                                   false);

            CoreAssociationEnd    assocEnd = getClassifier("Person").lookupAssociationEnd("Reservation");
            AssociationEndCallExp exp      = factory1.createAssociationEndCallExp(sourceExp, assocEnd, null, null, false);

            Assert.AreEqual("abc.bosses.Reservation", exp.ToString());
            Assert.AreEqual("Sequence(Reservation)", exp.getType().getName());
        }
        public void testVariableExp()
        {
            AstOclModelElementFactory factory1 = AstOclModelElementFactoryManager.getInstance(umlModel.getOclPackage());

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

            VariableExp exp1 = factory1.createVariableExp(variable);
            VariableExp exp2 = factory1.createVariableExp(variable);

            Assert.AreEqual("abc", exp1.ToString());
            Assert.AreEqual("Integer", exp1.getType().getName());

            Assert.AreEqual("abc", exp2.ToString());
            Assert.AreEqual("Integer", exp2.getType().getName());

            Assert.AreEqual("100", variable.getInitExpression().ToString());
        }
        // (true and x) or (y and (not x))
        public void EvaluateExpression()
        {
            IBooleanExp expression;
            IContext    context = new Context();

            VariableExp x = new VariableExp("X");
            VariableExp y = new VariableExp("Y");

            expression = new OrExp(
                new AndExp(new Constant(true), x),
                new AndExp(y, new NotExp(x))
                );

            context.Assign(x, false);
            context.Assign(y, true);

            bool result = expression.Evaluate(context);
        }
        public void testAttributeCallExp()
        {
            AstOclModelElementFactory factory1 = AstOclModelElementFactoryManager.getInstance(umlModel.getOclPackage());

            VariableDeclaration variable = factory1.createVariableDeclaration("abc", getClassifier("Film"), null);
            VariableExp         source1  = factory1.createVariableExp(variable);
            VariableExp         source2  = factory1.createVariableExp(variable);

            CoreAttribute attribute = getClassifier("Film").lookupAttribute("name");

            AttributeCallExp exp1 = factory1.createAttributeCallExp(source1, attribute, false);
            AttributeCallExp exp2 = factory1.createAttributeCallExp(source2, attribute, true);

            Assert.AreEqual("abc.name", exp1.ToString());
            Assert.AreEqual("String", exp1.getType().getName());

            Assert.AreEqual("abc.name@pre", exp2.ToString());
            Assert.AreEqual("String", exp2.getType().getName());
        }
Exemple #14
0
 public override OclExpression Visit(VariableExp node)
 {
     if (!VariableTranslations.ContainsKey(node.referredVariable))
     {
         OclExpression value = null;
         if (node.referredVariable.Value != null)
         {
             value = node.referredVariable.Value.Accept(this);
         }
         PSMClass            psmClass     = VariableClassMappings[node.referredVariable].First();
         Classifier          variableType = psmBridge.Find(psmClass);
         VariableDeclaration vd           = new VariableDeclaration(node.referredVariable.Name, variableType, value);
         return(new VariableExp(vd));
     }
     else
     {
         return(new VariableExp(VariableTranslations[node.referredVariable]));
     }
 }
        public void fTest_01()
        {
            AstOclModelElementFactory factory1 = AstOclModelElementFactoryManager.getInstance(umlModel.getOclPackage());

            VariableDeclaration variable = factory1.createVariableDeclaration("abc", getClassifier("SpecialFilm"), null);
            VariableExp         source   = factory1.createVariableExp(variable);

            CoreClassifier c1 = getClassifier("SpecialFilm");

            CoreModel coreModel = c1.getModel();

            List <object> ass = coreModel.getAllAssociations();


            CoreClassifier c2    = getClassifier("Film");
            List <object>  core  = c1.getAllAssociationEnds();
            List <object>  core2 = c2.getAllAssociationEnds();

            var a = c2.lookupAssociationEnd("tapes");
        }
Exemple #16
0
        public static PSMPath BuildPSMPath(VariableExp variableExp, IConstraintsContext constraintsContext, VariableNamer variableNamer, BuildPSMPathParams buildPsmPathParams)
        {
            PSMPath path = new PSMPath();

            path.Context.ConstraintContext        = constraintsContext;
            path.Context.VariableNamer            = variableNamer;
            path.TupleLiteralToXPathCallback      = buildPsmPathParams.TupleLiteralToXPathCallback;
            path.GenericExpressionToXPathCallback = buildPsmPathParams.GenericExpressionToXPathCallback;
            path.ClassLiteralToXPathCallback      = buildPsmPathParams.ClassLiteralToXPathCallback;

            PSMPathVariableStep pathVariableStep = new PSMPathVariableStep(path)
            {
                VariableExp = variableExp
            };

            if (string.IsNullOrEmpty(variableExp.referredVariable.Name))
            {
                variableExp.referredVariable.Name = path.Context.VariableNamer.GetName(variableExp.referredVariable.PropertyType);
            }
            path.Steps.Insert(0, pathVariableStep);
            return(path);
        }
        public void testIterateExp()
        {
            AstOclModelElementFactory factory1 = AstOclModelElementFactoryManager.getInstance(umlModel.getOclPackage());

            VariableDeclaration variable = factory1.createVariableDeclaration("abc", getClassifier("Distributor"), null);
            VariableExp         source   = factory1.createVariableExp(variable);

            VariableDeclaration iter    = factory1.createVariableDeclaration("iter", getClassifier("SpecialFilm"), null);
            VariableExp         iterRef = factory1.createVariableExp(iter);

            CoreAttribute    attr    = getClassifier("SpecialFilm").lookupAttribute("lateReturnFee");
            AttributeCallExp attCall = factory1.createAttributeCallExp(iterRef, attr, false);

            IntegerLiteralExp   initExp = factory1.createIntegerLiteralExp(100, getClassifier("Integer"));
            VariableDeclaration result  = factory1.createVariableDeclaration("result", getClassifier("Integer"), initExp);


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

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

            VariableExp   resultExp = factory1.createVariableExp(result);
            List <object> args      = new List <object>();

            args.Add(attCall);
            OclExpression body = factory1.createOperationCallExp(resultExp, oper, args, getClassifier("Integer"), false);

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

            iterators.Add(iter);

            IterateExp exp = factory1.createIterateExp(getClassifier("Integer"), source, body, iterators, result);

            Assert.AreEqual("abc->iterate(iter : SpecialFilm ; result : Integer = 100 | result + iter.lateReturnFee)",
                            exp.ToString());
            Assert.AreEqual("Integer", exp.getType().getName());
        }
Exemple #18
0
        public void GetEvaluateExpValueTest()
        {
            var dic     = new Dictionary <char, int>();
            var varName = 'j';

            dic[varName] = 0;
            var exp = new VariableExp(varName, dic);

            // op act before evalution
            Assert.AreEqual(0, exp.GetEvaluateExpValue());

            // undeclared var exception pop out
            try
            {
                exp = new VariableExp('x', dic);
                var r = exp.GetEvaluateExpValue();
            }
            catch (Exception ex)
            {
                bool exType = ex is UndeclaredVariableException;
                Assert.IsTrue(exType);
            }
        }
        public void testOperationCallExpWithAtPre()
        {
            AstOclModelElementFactory factory1 = AstOclModelElementFactoryManager.getInstance(umlModel.getOclPackage());

            VariableDeclaration variable = factory1.createVariableDeclaration("abc", getClassifier("Film"), null);
            VariableExp         source   = factory1.createVariableExp(variable);

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

            paramTypes.Add(getClassifier("Integer"));

            CoreOperation operation = getClassifier("Film").lookupOperation("getRentalFee", paramTypes);

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

            arguments.Add(factory1.createIntegerLiteralExp(100, getClassifier("Integer")));

            OperationCallExp exp = factory1.createOperationCallExp(source, operation, arguments,
                                                                   operation.getReturnType(), true);

            Assert.AreEqual("abc.getRentalFee@pre(100)", exp.ToString());
            Assert.AreEqual("Real", exp.getType().getName());
        }
Exemple #20
0
        public IEvaluableExp BuildExp(string exp, Dictionary <char, int> envVars)
        {
            if (!isValid(exp))
            {
                throw new InvalidExpressionException();
            }

            bool   regularAss;
            OpEnum op;

            (Variable, regularAss, op) = ExtractVar(exp);
            var postExp = exp.Split('=')[1];

            // handle potential '+=' assignment
            if (!regularAss)
            {
                var leftexp = new VariableExp(Variable, envVars);

                // continue evalute next exp from the postfix of the string
                return(new RegularExp(leftexp, op, BuildExpAfterAss(postExp, envVars)));
            }

            return(BuildExpAfterAss(postExp, envVars));
        }
        public void testIteratorExp()
        {
            AstOclModelElementFactory factory1 = AstOclModelElementFactoryManager.getInstance(umlModel.getOclPackage());

            VariableDeclaration variable = factory1.createVariableDeclaration("abc", getClassifier("Distributor"), null);
            VariableExp         source   = factory1.createVariableExp(variable);

            VariableDeclaration iter    = factory1.createVariableDeclaration("iter", getClassifier("SpecialFilm"), null);
            VariableExp         iterRef = factory1.createVariableExp(iter);

            CoreAttribute    attr = getClassifier("SpecialFilm").lookupAttribute("name");
            AttributeCallExp body = factory1.createAttributeCallExp(iterRef, attr, false);

            CoreClassifier setSpecialFilm = factory1.createSetType(getClassifier("SpecialFilm"));

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

            iterators.Add(iter);

            IteratorExp exp = factory1.createIteratorExp("select", setSpecialFilm, source, body, iterators);

            Assert.AreEqual("abc->select(iter : SpecialFilm | iter.name)", exp.ToString());
            Assert.AreEqual("Set(SpecialFilm)", exp.getType().getName());
        }
Exemple #22
0
 private LoopExp GetLoopExpForVariable(VariableExp v)
 {
     return(loopStacks.LastOrDefault(l => l.Iterator.Any(vd => vd.Name == v.referredVariable.Name)));
 }
 public override bool Visit(VariableExp node)
 {
     /* hopefully no problem here */
     return(true);
 }
Exemple #24
0
 private IExpression GetExpression(SelectContext context, VariableExp variableExp)
 {
     return(CreateColumn(context.Variables[variableExp.ReferredVariable.Name], variableExp.ReferredVariable.Name));
 }
Exemple #25
0
 public void Visit(VariableExp node)
 {
     referredVariables.AddIfNotContained(node.referredVariable);
 }
 public void Assign(VariableExp variableExp, bool res)
 {
     // Some implementation
 }
Exemple #27
0
 public void removeVariableExp(VariableExp variableExp)
 {
     this.variableExp.Remove(variableExp);
 }
Exemple #28
0
 /**
  * @param variableExp The variableExp to set.
  */
 public void addVariableExp(VariableExp variableExp)
 {
     this.variableExp.Add(variableExp);
 }
Exemple #29
0
 public void Visit(VariableExp node)
 {
     sb.Append(node.referredVariable.Name);
 }
Exemple #30
0
 public abstract TType Visit(VariableExp node);