private void getTargetAssociationReference(AssociationEndCallExp exp, CoreAssociationEnd associationEnd, out string otherTypeName, out string otherKeyName, out string otherName, out string typeName, out string name)
        {
            var otherType = associationEnd.getType();

            otherTypeName = otherType.getName();

            var otherKeyAttribute =
                (CoreAttributeImpl)otherType.getAllAttributes().FirstOrDefault(a => ((CoreAttributeImpl)a).hasStereotype("Id")) ??
                (CoreAttributeImpl)otherType.getAllAttributes().FirstOrDefault();

            otherKeyName = otherKeyAttribute != null?otherKeyAttribute.getName() : "";

            var participant         = associationEnd.getTheParticipant();
            var association         = associationEnd.getAssociation();
            var otherAssociationEnd = (CoreAssociationEndImpl)association.getTheAssociationEnds(participant).FirstOrDefault();

            otherName = otherAssociationEnd != null?otherAssociationEnd.getName() : "";

            var expsource = (VariableExp)exp.getSource();
            var variable  = expsource.getReferredVariable();
            var type      = variable.getType();

            typeName = type.getName();

            var keyAttribute =
                (CoreAttributeImpl)type.getAllAttributes().FirstOrDefault(a => ((CoreAttributeImpl)a).hasStereotype("Id")) ??
                (CoreAttributeImpl)type.getAllAttributes().FirstOrDefault();

            name = keyAttribute != null?keyAttribute.getName() : "";
        }
Esempio n. 2
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");
        }
Esempio n. 3
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");
        }
Esempio n. 4
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");
        }
Esempio n. 5
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");
        }
        protected AssociationEndCallExp checkAssociationEndCallExp(OclExpression oclExpression, String roleName, String typeName)
        {
            Assert.IsTrue(oclExpression is AssociationEndCallExp);
            AssociationEndCallExp exp = (AssociationEndCallExp)oclExpression;

            Assert.AreEqual(roleName, exp.getReferredAssociationEnd().getName());
            Assert.AreEqual(typeName, exp.getType().getName());
            return(exp);
        }
Esempio n. 7
0
        public void testQualifier_01()
        {
            List <object> constraints = doTestContextOK("context Film inv: self.tapes[1] = self.tapes[2]",
                                                        getCurrentMethodName());

            OclExpression         oclExpression = getConstraintExpression(constraints);
            AssociationEndCallExp attExp        = checkAssociationEndCallExp(((OperationCallExp)oclExpression).getSource(), "tapes", "Tape");

            Assert.AreEqual(1, attExp.getQualifiers().Count);
        }
Esempio n. 8
0
        public void testAssociationEndCallExp_01()
        {
            List <object> constraints = doTestContextOK("context Tape inv: theFilm = theFilm ",
                                                        getCurrentMethodName());

            OclExpression         oclExpression = getConstraintExpression(constraints);
            AssociationEndCallExp exp           = checkAssociationEndCallExp(((OperationCallExp)oclExpression).getSource(), "theFilm", "Film");

            checkImplicitSource(exp, "self", "Tape");
        }
Esempio n. 9
0
        public void testAssociationEndCallExp_03()
        {
            List <object> constraints = doTestContextOK("context Rental inv: itens->size() > 0",
                                                        getCurrentMethodName());

            OclExpression         oclExpression = getConstraintExpression(constraints);
            AssociationEndCallExp exp           = checkAssociationEndCallExp(((OperationCallExp)((OperationCallExp)oclExpression).getSource()).getSource(), "itens", "OrderedSet(RentalItem)");

            checkImplicitSource(exp, "self", "Rental");
        }
Esempio n. 10
0
        public void testAssociationEndCallExp_05()
        {
            List <object> constraints = doTestContextOK("context Film inv: self.tapes = tapes",
                                                        getCurrentMethodName());

            OclExpression         oclExpression = getConstraintExpression(constraints);
            AssociationEndCallExp exp           = checkAssociationEndCallExp(((OperationCallExp)oclExpression).getSource(), "tapes", "Set(Tape)");

            checkImplicitSource(exp, "self", "Film");
        }
Esempio n. 11
0
        public void testAssociationEndCallExp_06()
        {
            List <object> constraints = doTestContextOK("context RentalItem inv: Rental = Rental",
                                                        getCurrentMethodName());

            OclExpression         oclExpression = getConstraintExpression(constraints);
            AssociationEndCallExp exp           = checkAssociationEndCallExp(((OperationCallExp)oclExpression).getSource(), "Rental", "Rental");

            checkImplicitSource(exp, "self", "RentalItem");
        }
Esempio n. 12
0
        public void testMoreThanOneNavigation_08()
        {
            List <object> constraints = doTestContextOK("context Tape inv: self.theFilm.name = self.theFilm.name",
                                                        getCurrentMethodName());

            OclExpression    oclExpression = getConstraintExpression(constraints);
            AttributeCallExp attExp        = checkAttributeCallExp(((OperationCallExp)oclExpression).getSource(), "name", "String");

            Assert.IsTrue(attExp.getSource() is AssociationEndCallExp);
            AssociationEndCallExp exp = (AssociationEndCallExp)attExp.getSource();

            Assert.AreEqual("Film", exp.getType().getName());
        }
        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 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());
        }
        private void getOneMultiplicityAssociationReference(AssociationEndCallExp exp, CoreAssociationEnd associationEnd, out string otherTypeName, out string otherKeyName, out string typeName, out string name)
        {
            var otherType = associationEnd.getType();

            otherTypeName = otherType.getName();

            var otherKeyAttribute =
                (CoreAttributeImpl)otherType.getAllAttributes().FirstOrDefault(a => ((CoreAttributeImpl)a).hasStereotype("Id")) ??
                (CoreAttributeImpl)otherType.getAllAttributes().FirstOrDefault();

            otherKeyName = otherKeyAttribute != null?otherKeyAttribute.getName() : "";

            var expsource = (VariableExp)exp.getSource();
            var variable  = expsource.getReferredVariable();
            var type      = variable.getType();

            typeName = type.getName();

            name = associationEnd.getName();
        }
Esempio n. 17
0
        public void testAssociationEndCallExp_12()
        {
            List <object> constraints = doTestManyContextOK("context Film::getTapes() : Set(Tape) post: self.tapes[1]@pre = 10 ",
                                                            getCurrentMethodName());

            CoreClassifier film      = (CoreClassifier)environment.lookup("Film");
            CoreOperation  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);
            AssociationEndCallExp exp    = checkAssociationEndCallExp(((OperationCallExp)oclExpression).getSource(), "tapes", "Tape");

            opCall = (OperationCallExp)((AssociationEndCallExp)opCall.getSource()).getSource();
            this.checkOperationCallExp(opCall, "atPre", "Film");
            checkImplicitSource(opCall, "self", "Film");
        }
        public void visitAssociationEndCallExp(AssociationEndCallExp exp)
        {
            var    associationEnd = exp.getReferredAssociationEnd();
            bool   isOneMultiplicity = associationEnd.isOneMultiplicity();
            string otherTypeName, otherKeyName, typeName, name;

            if (isOneMultiplicity)
            {
                getOneMultiplicityAssociationReference(exp, associationEnd,
                                                       out otherTypeName, out otherKeyName, out typeName, out name);
                otherFormula = string.Format("=INDEX({0},MATCH([{1}],{0}[{2}],0)", otherTypeName, name, otherKeyName);
            }
            else
            {
                string otherName;
                getTargetAssociationReference(exp, associationEnd,
                                              out otherTypeName, out otherKeyName, out otherName, out typeName, out name);

                if (navigationLevel == 0)
                {
                    // add reference to key column of associated table
                    formula += string.Format("{0}[{1}],{2}[{3}]", otherTypeName, otherName, typeName, name);
                }
                else
                {
                    // create new column on target table (where expression is based on)
                    var columnName = string.Format("{0}_{1}", typeName.ToLower(), name.ToLower());
                    formula     += string.Format("{0}[{1}],{2}[{3}]", currentClassifier.getName(), columnName, typeName, name);
                    otherFormula = string.Format("=INDEX({4},MATCH(INDEX({0},MATCH([{1}],{0}[{2}],0),COL({0}[{3}])),{4}[{5}],0),COL({4}[{5}]))",
                                                 otherTypeName, firstNavigationName, otherKeyName, otherName, typeName, name);
                    columnToFormula.Add(columnName, otherFormula);
                }
            }

            navigationLevel++;
        }