public void testExists_03() { List <object> constraints = doTestContextOK("context Film inv: self.tapes->exists(t | t.number = 1 and self.name = \"alex\")", getCurrentMethodName()); OclExpression oclExpression = getConstraintExpression(constraints); IteratorExp exp = checkIteratorExp(oclExpression, "Boolean", "exists", "Tape", "t"); Assert.IsTrue(exp.getBody() is OperationCallExp); checkOperationCallExp(exp.getBody(), "and", "Boolean"); }
public void testOperationCall_08() { List <object> constraints = doTestContextOK("context Film inv: self.getTapes().theFilm = self.getTapes().theFilm", getCurrentMethodName()); OclExpression oclExpression = ((OperationCallExp)getConstraintExpression(constraints)).getSource(); IteratorExp exp = checkIteratorExp(oclExpression, "Bag(Film)", "collect", "Tape", "iterator"); checkOperationCallExp(exp.getSource(), "getTapes", "Set(Tape)"); checkAssociationEndCallExp(exp.getBody(), "theFilm", "Film"); checkImplicitSource((PropertyCallExp)exp.getBody(), "iterator", "Tape"); }
public void testOperationCall_07() { List <object> constraints = doTestContextOK("context Film inv: self.getTapes().number = self.getTapes().number", getCurrentMethodName()); OclExpression oclExpression = getConstraintExpression(constraints); IteratorExp exp = checkIteratorExp(((OperationCallExp)oclExpression).getSource(), "Bag(Integer)", "collect", "Tape", "iterator"); checkOperationCallExp(exp.getSource(), "getTapes", "Set(Tape)"); checkAttributeCallExp(exp.getBody(), "number", "Integer"); checkImplicitSource((PropertyCallExp)exp.getBody(), "iterator", "Tape"); }
public void testCollectTuple_01() { List <object> constraints = doTestContextOK("context Film inv: self.Reservation.Person->collect(Tuple{a = age, b : Sequence(Integer) = bosses.age->asSequence()})->exists(x | x.a > 10)", getCurrentMethodName()); OclExpression oclExpression = getConstraintExpression(constraints); IteratorExp exp = checkIteratorExp(oclExpression, "Boolean", "exists", "Tuple(a : Integer, b : Sequence(Integer))", "x"); Assert.IsTrue(exp.getBody() is OperationCallExp); checkOperationCallExp(exp.getBody(), ">", "Boolean"); checkIteratorExp(exp.getSource(), "Bag(Tuple(a : Integer, b : Sequence(Integer)))", "collect", "Person", "iterator"); Assert.IsTrue(((IteratorExp)exp.getSource()).getBody() is TupleLiteralExp); }
public void testImplicitCollect_06() { List <object> constraints = doTestContextOK("context Film inv: self.Reservation.Person.EmployeeRanking[bosses]->exists( x | x.score > 5)", getCurrentMethodName()); OclExpression oclExpression = getConstraintExpression(constraints); IteratorExp exp = checkIteratorExp(oclExpression, "Boolean", "exists", "EmployeeRanking", "x"); Assert.IsTrue(exp.getBody() is OperationCallExp); checkOperationCallExp(exp.getBody(), ">", "Boolean"); checkIteratorExp(exp.getSource(), "Bag(EmployeeRanking)", "collect", "Person", "iterator"); Assert.IsTrue(((IteratorExp)exp.getSource()).getBody() is AssociationClassCallExp); }
public void testIteratorExp_02() { List <object> constraints = doTestContextOK("context Rental inv: self.itens.Rental = self.itens.Rental", getCurrentMethodName()); OclExpression oclExpression = getConstraintExpression(constraints); IteratorExp exp = checkIteratorExp(((OperationCallExp)oclExpression).getSource(), "Sequence(Rental)", "collect", "RentalItem", "iterator"); checkAssociationEndCallExp(exp.getBody(), "Rental", "Rental"); checkImplicitSource((PropertyCallExp)exp.getBody(), "iterator", "RentalItem"); checkAssociationEndCallExp(exp.getSource(), "itens", "OrderedSet(RentalItem)"); checkImplicitSource((PropertyCallExp)exp.getSource(), "self", "Rental"); }
public void testImplicitCollect_04() { List <object> constraints = doTestContextOK("context Tape inv: self.theFilm.getTapes().theFilm.getTapes()->exists( x | x.number > 5)", getCurrentMethodName()); OclExpression oclExpression = getConstraintExpression(constraints); IteratorExp exp = checkIteratorExp(oclExpression, "Boolean", "exists", "Tape", "x"); Assert.IsTrue(exp.getBody() is OperationCallExp); checkOperationCallExp(exp.getBody(), ">", "Boolean"); checkIteratorExp(exp.getSource(), "Bag(Tape)", "collect", "Film", "iterator"); Assert.IsTrue(((IteratorExp)exp.getSource()).getBody() is OperationCallExp); }
public void testImplicitCollect_02() { List <object> constraints = doTestContextOK("context Client inv : self.Rental.maxDaysToReturn->exists(x | x > 5)", getCurrentMethodName()); OclExpression oclExpression = getConstraintExpression(constraints); IteratorExp exp = checkIteratorExp(oclExpression, "Boolean", "exists", "Integer", "x"); Assert.IsTrue(exp.getBody() is OperationCallExp); checkOperationCallExp(exp.getBody(), ">", "Boolean"); checkIteratorExp(exp.getSource(), "Bag(Integer)", "collect", "Rental", "iterator"); Assert.IsTrue(((IteratorExp)exp.getSource()).getBody() is AttributeCallExp); }
public void testImplicitCollect_01() { List <object> constraints = doTestContextOK("context Client inv : self.Rental.itens->exists(i | i.number = 1)", getCurrentMethodName()); OclExpression oclExpression = getConstraintExpression(constraints); IteratorExp exp = checkIteratorExp(oclExpression, "Boolean", "exists", "RentalItem", "i"); Assert.IsTrue(exp.getBody() is OperationCallExp); checkOperationCallExp(exp.getBody(), "=", "Boolean"); checkIteratorExp(exp.getSource(), "Sequence(RentalItem)", "collect", "Rental", "iterator"); Assert.IsTrue(((IteratorExp)exp.getSource()).getBody() is AssociationEndCallExp); }
public void visitIteratorExpBegin(IteratorExp exp) { if (exp.getName() == "collect") { var body = exp.getBody(); if (body is AttributeCallExpImpl) { var bodyImpl = (AttributeCallExpImpl)body; currentClassifier = (CoreClassifier)bodyImpl.getReferredAttribute().getElemOwner(); bodyImpl.accept(this); formula += ","; } else if (body is AssociationEndCallExpImpl) { var bodyImpl = (AssociationEndCallExpImpl)body; var associationEnd = bodyImpl.getReferredAssociationEnd(); bool isOneMultiplicity = associationEnd.isOneMultiplicity(); if (!isOneMultiplicity) { string otherTypeName, otherKeyName, otherName, typeName, name; getTargetAssociationReference(bodyImpl, associationEnd, out otherTypeName, out otherKeyName, out otherName, out typeName, out name); otherFormula = string.Format("=INDEX({0},MATCH([{1}],{0}[{2}],0)", typeName, otherName, name); firstNavigationName = otherName; } navigationLevel++; } else if (body is OperationCallExpImpl) { var bodyImpl = (OperationCallExpImpl)body; // get referred operation name var operation = bodyImpl.getReferredOperation(); var name = operation.getName(); var expsource = (VariableExp)bodyImpl.getSource(); var variable = expsource.getReferredVariable(); var type = variable.getType(); var typeName = type.getName(); formula += string.Format("{0}[{1}]", typeName, name); formula += ","; if (currentClassifier == null) { currentClassifier = (CoreClassifier)operation.getElemOwner(); } } } else if (exp.getName() == "select") { processSelectExpression(exp); } }
public void testForAll_01() { List <object> constraints = doTestContextOK("context Film inv: self.tapes->forAll(t1 : Tape, t2 : Tape | t1 <> t2 and t1.number = 1 and self.name = \"alex\")", getCurrentMethodName()); OclExpression oclExpression = getConstraintExpression(constraints); Assert.IsTrue(oclExpression is IteratorExp); IteratorExp exp = (IteratorExp)oclExpression; Assert.AreEqual("Boolean", exp.getType().getName()); Assert.AreEqual("forAll", exp.getName()); Assert.AreEqual(2, exp.getIterators().Count); VariableDeclaration v1 = (VariableDeclaration)exp.getIterators()[0]; VariableDeclaration v2 = (VariableDeclaration)exp.getIterators()[1]; Assert.AreEqual("t1", v1.getName()); Assert.AreEqual("t2", v2.getName()); Assert.AreEqual("Tape", v1.getType().getName()); Assert.IsTrue(exp.getBody() is OperationCallExp); checkOperationCallExp(exp.getBody(), "and", "Boolean"); }
private void processSelectExpression(IteratorExp exp) { var body = exp.getBody(); var bodyImpl = body as OperationCallExpImpl; if (bodyImpl != null) { var operation = bodyImpl.getReferredOperation(); if (operation != null) { string operationName = operation.getName(); if (bodyImpl.isBasicOperator(operationName) && !bodyImpl.isBooleanOperator(operationName)) { var bodySource = bodyImpl.getSource(); var bodySourceImpl = bodySource as AttributeCallExpImpl; if (bodySourceImpl != null) { if (navigationLevel == 0) { bodySourceImpl.accept(this); } else { string typeName, name; getTableReference(bodySourceImpl, out name, out typeName); var columnName = string.Format("{0}_{1}", typeName.ToLower(), name.ToLower()); formula += string.Format("{0}[{1}]", currentClassifier.getName(), columnName); otherFormula += string.Format(",COL({0}[{1}]))", typeName, name); columnToFormula.Add(columnName, otherFormula); } formula += ","; var bodySourceOperation = bodyImpl.getReferredOperation(); if (bodySourceOperation.getName() != "=") { formula += string.Format("\"{0}\"&", operationName); } } else { var obodySourceImpl = bodySource as OperationCallExpImpl; if (obodySourceImpl != null && navigationLevel == 0) { // get referred operation name var bodySourceOperation = obodySourceImpl.getReferredOperation(); var name = bodySourceOperation.getName(); var expsource = (VariableExp)obodySourceImpl.getSource(); var variable = expsource.getReferredVariable(); var type = variable.getType(); var typeName = type.getName(); formula += string.Format("{0}[{1}]", typeName, name); formula += ","; } } var argument = (OclExpressionImpl)bodyImpl.getArguments().FirstOrDefault(); if (argument != null) { argument.accept(this); } } formula += ","; } } }