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); }
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); }
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); }
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); } }
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); }
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(")"); } }
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); }
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()); }
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"); }
protected CollectionLiteralExp checkCollectionLiteralExp(OclExpression oclExpression, String type) { Assert.IsTrue(oclExpression is CollectionLiteralExp); CollectionLiteralExp exp = (CollectionLiteralExp)oclExpression; Assert.AreEqual(type, exp.getType().getName()); return(exp); }
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"); }
private CoreClassifier checkResult(CSTNode rootNode, String expectedTypeName) { CSTArgumentCS argument = (CSTArgumentCS)rootNode; OclExpression ast = argument.getAst(); Assert.AreEqual(expectedTypeName, ast.getType().getName()); return(ast.getType()); }
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"); }
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"); }
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"); }
public OperationCallExp createAsSetOperation(OclExpression source) { OperationCallExp exp = createOperationCallExp(createSpecificCollectionType(CollectionKindEnum.SET, source.getType()), source, "asSet", new List <object>(), false); exp.setFactory(this); return(exp); }
public OperationCallExp createAtPreOperation(OclExpression source) { OperationCallExp exp = createOperationCallExp(source.getType(), source, "atPre", new List <object>(), false); exp.setFactory(this); return(exp); }
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)"); }
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)" }); }
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"); }
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); }
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); }
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"); }
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)"); }