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); }
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"); }
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 override void Visit(OperationCallExp node) { if (node.ReferredOperation != null && node.ReferredOperation.Tag is NextOperationTag) { node.Source.Accept(this); TranslationOption option = new TranslationOption(); option.FormatString = "oclX:apply-templates({0})"; SubexpressionTranslations.AddTranslationOption(node, option, node.Source); return; } base.Visit(node); if (OperationRewritings.IsEmpty()) { OperationRewritings[OperationHelper.firstOperationInfo] = AddFirstRewritings; OperationRewritings[OperationHelper.lastOperationInfo] = AddLastRewritings; OperationRewritings[OperationHelper.atOperationInfo] = AddAtRewritings; } { TranslationOption standardTranslation = SubexpressionTranslations.GetSubexpressionTranslation(node); OperationInfo? operationInfo = OperationHelper.LookupOperation(node, standardTranslation.OptionsContainer.SubExpressions.ToArray()); if (operationInfo != null && OperationRewritings.ContainsKey(operationInfo.Value)) { OperationRewritings[operationInfo.Value](node, operationInfo.Value); } } }
private IExpression GetExpression(SelectContext context, OperationCallExp callExpression) { switch (callExpression.ReferredOperation) { case Operator.AllInstances: return(GetAllInstances(context, (callExpression.Source as TypeExp).ReferredType)); case Operator.Size: return(GetSize(context, callExpression.Source, null, false)); case Operator.AND: return(new AndExpression { LeftExp = GetExpression(context, (dynamic)callExpression.Source), RightExp = GetExpression(context, (dynamic)callExpression.Argument[0]) }); default: return(new EqualsToExpression { LeftExp = GetExpression(context, (dynamic)callExpression.Source), RightExp = GetExpression(context, (dynamic)callExpression.Argument[0]) }); } }
private string SkipHandler(OperationCallExp operationExpression, OperationInfo operationInfo, OclExpression[] arguments) { Debug.Assert(operationExpression.ReferredOperation != null && operationExpression.ReferredOperation.Tag is SkipOperationTag); SkipOperationTag tag = (SkipOperationTag)operationExpression.ReferredOperation.Tag; Func <PSMAttribute, PSMAttribute> findAttribute = a => ((PSMClass)tag.Target.PSMSource).PSMAttributes.Single(ta => ta.Interpretation == a.Interpretation); //let $i := //intern[1] return //employee[./id = $i/id] System.Text.StringBuilder sb = new System.Text.StringBuilder(); string varNameLetter = tag.Source.PSMSource.Name.Substring(0, 1).ToLower(); string varName = varNameLetter; int i = 1; while (operationExpression.Environment.LookupLocal(varName) != null) { i++; varName = varNameLetter + i; } string allInstances = ((PSMClass)tag.Target.PSMSource).GetXPathFull().ToString(); sb.AppendFormat("(let ${0} := {{0}} return {1}[", varName, allInstances); ((PSMClass)tag.Source.PSMSource).PSMAttributes.ConcatWithSeparator( a => sb.AppendFormat("./{0}{1} = ${2}/{0}{1}", findAttribute(a).Element ? string.Empty : "@", findAttribute(a).Name, varName), " and ", sb); sb.Append("])"); return(sb.ToString()); }
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); }
private string InfixAtomicHandler(OperationCallExp operationExpression, OperationInfo operationInfo, OclExpression[] arguments) { string leftOp = WrapAtomicOperand(arguments[0], operationInfo, 0); string rightOp = WrapAtomicOperand(arguments[1], operationInfo, 1); return(string.Format("{1} {0} {2}", operationInfo.XPathName, leftOp, rightOp)); }
private string FunctionAtomicHandler(OperationCallExp operationExpression, OperationInfo operationInfo, OclExpression[] arguments) { IEnumerable <string> wrappedSequence = from ind in Enumerable.Range(0, arguments.Count()) select WrapAtomicOperand(arguments[ind], operationInfo, ind); //IEnumerable<string> withoutDataCall = convertedArguments.Select(a => a.RawString); //IEnumerable<string> withDataCall = convertedArguments.Select(a => a.GetString()); //IEnumerable<string> stringifiedArguments = !operationInfo.CanOmitDataCall ? withDataCall : withoutDataCall; if (!string.IsNullOrEmpty(operationInfo.CustomXPathSyntaxFormatString)) { return(string.Format(operationInfo.CustomXPathSyntaxFormatString, wrappedSequence.ToArray())); //if (operationInfo.TypeDependent) //{ // return string.Format(operationInfo.CustomXPathSyntaxFormatString, wrappedSequence.ToArray()); //} //else //{ // return string.Format(operationInfo.CustomXPathSyntaxFormatString, stringifiedArguments.ToArray()); //} } else { return(string.Format("{0}({1})", operationInfo.XPathName, wrappedSequence.ConcatWithSeparator(", "))); //if (operationInfo.TypeDependent) //{ // return string.Format("{0}({1})", operationInfo.XPathName, wrappedSequence.ConcatWithSeparator(", ")); //} //else //{ // return string.Format("{0}({1})", operationInfo.XPathName, stringifiedArguments.ConcatWithSeparator(", ")); //} } }
private string ToStringWithArgsStandard(OperationCallExp operationExpression, Operation referredOperation, OperationInfo info, OclExpression[] arguments) { if (info.UseCustomTranslateHandler) { Debug.Assert(info.CustomTranslateHandler != null); return(info.CustomTranslateHandler(operationExpression, info, arguments)); } else if (info.UseCustomXPathSyntaxFormatString) { Debug.Assert(!string.IsNullOrEmpty(info.CustomXPathSyntaxFormatString)); return(string.Format(info.CustomXPathSyntaxFormatString)); } else { if (info.IsXPathInfix) { Debug.Assert(arguments.Length == 2 && info.Arity == 2); string leftOp = WrapAtomicOperand(arguments[0], info, 0); string rightOp = WrapAtomicOperand(arguments[1], info, 1); return(string.Format("{0} {1} {2}", leftOp, info.XPathName, rightOp)); } else if (info.IsXPathPrefix) { Debug.Assert(arguments.Length == 1 && info.Arity == 1); string op = WrapAtomicOperand(arguments[0], info, 0); return(string.Format("{0} {1}", info.XPathName, op)); } else { return(string.Format("{0}({1})", info.XPathName, arguments.ConcatWithSeparator(a => WrapAtomicOperand(a, info, Array.IndexOf(arguments, a)), ", "))); } } }
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 void Visit(OperationCallExp node) { if (node.Source != null) { node.Source.Accept(this); } if (node.Source != null && node.Source.Type is CollectionType) { sb.Append("->"); } else { sb.Append("."); } sb.Append(node.ReferredOperation.Name); sb.Append("("); foreach (var arg in node.Arguments) { arg.Accept(this); sb.Append(","); } sb.Append(")"); }
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); }
private string AllInstancesHandler(OperationCallExp operationExpression, OperationInfo operationInfo, OclExpression[] arguments) { var type = arguments[0] is TypeExp ? ((TypeExp)arguments[0]).ReferredType : arguments[0].Type; PSMBridgeClass psmBridgeClass = (PSMBridgeClass)type; PSMClass psmClass = (PSMClass)psmBridgeClass.PSMSource; Path allInstancesXPath = psmClass.GetXPathFull(); return(allInstancesXPath.ToString()); }
public OperationInfo?LookupOperation(OperationCallExp operationExpression, OclExpression[] arguments) { Operation referredOperation = operationExpression.ReferredOperation; if (referredOperation.Tag is SkipOperationTag) { return(skipOperationInfo); } var nameMatch = this.Where(i => i.OclName == referredOperation.Name); if (nameMatch.IsEmpty()) { Log.AddError(string.Format(XPathTranslationLogMessages.OperationHelper_OperationNotFound_1, referredOperation.Name), operationExpression); return(null); } int argCountMinus1 = arguments.Count() - 1; var arityMatch = nameMatch.Where(i => i.Arity == arguments.Count()); if (arityMatch.IsEmpty()) { Log.AddError(string.Format(XPathTranslationLogMessages.OperationHelper_OperationNotFound_2, referredOperation.Name, argCountMinus1), operationExpression); return(null); } var typedArityMatch = arityMatch.Where(i => i.TypeDependent && (i.ArgumentCondition == null || arguments.All(a => i.ArgumentCondition(a.Type))) && (i.ArgumentTypes == null || i.TypesConform(arguments)) ); if (typedArityMatch.Count() > 1) { Log.AddError(string.Format(XPathTranslationLogMessages.OperationHelper_OperationCallAmbiguous_2, referredOperation.Name, argCountMinus1), operationExpression); return(typedArityMatch.Single()); } if (typedArityMatch.Count() == 1) { return(typedArityMatch.Single()); } var untypedArityMatch = arityMatch.Where(i => !i.TypeDependent); if (untypedArityMatch.Count() > 1) { Log.AddError(string.Format("Call of operation {0} with {1} {2} is ambiguous. ", referredOperation.Name, argCountMinus1, argCountMinus1 == 1 ? "argument" : "arguments"), operationExpression); return(typedArityMatch.Single()); } if (untypedArityMatch.IsEmpty()) { Log.AddError(string.Format("Operation named {0} with {1} {2} not found. ", referredOperation.Name, argCountMinus1, argCountMinus1 == 1 ? "argument" : "arguments"), operationExpression); return(null); } return(untypedArityMatch.Single()); }
public void testOperationCall_06() { List <object> constraints = doTestContextOK("context Tape inv: self.theFilm.getRentalFee(1) = self.theFilm.getRentalFee(1)", getCurrentMethodName()); OclExpression oclExpression = getConstraintExpression(constraints); OperationCallExp exp = checkOperationCallExp(((OperationCallExp)oclExpression).getSource(), "getRentalFee", "Real"); checkAssociationEndCallExp(exp.getSource(), "theFilm", "Film"); }
protected OperationCallExp checkOperationCallExp(OclExpression oclExpression, String opName, String returnTypeName) { Assert.IsTrue(oclExpression is OperationCallExp); OperationCallExp opExp = (OperationCallExp)oclExpression; Assert.AreEqual(opName, opExp.getReferredOperation() != null ? opExp.getReferredOperation().getName() : opExp.getName()); // Assert.AreEqual(returnTypeName, opExp.getReferredOperation() != null? opExp.getReferredOperation().getReturnType().getName() : opExp.getType().getName()); Assert.AreEqual(returnTypeName, opExp.getType().getName()); return(opExp); }
public void Visit(OperationCallExp node) { Expressions.Add(node.Source); node.Source.Accept(this); foreach (OclExpression argExp in node.Arguments) { Expressions.Add(argExp); argExp.Accept(this); } }
public void testOperationCall_05() { List <object> constraints = doTestContextOK("context Film inv: self.getRentalFee(1) = self.getRentalFee(1)", getCurrentMethodName()); OclExpression oclExpression = getConstraintExpression(constraints); OperationCallExp exp = checkOperationCallExp(((OperationCallExp)oclExpression).getSource(), "getRentalFee", "Real"); checkImplicitSource(exp, "self", "Film"); }
public void testOperationCall_04() { List <object> constraints = doTestContextOK("context SpecialFilm inv: getTapes() = getTapes()", getCurrentMethodName()); OclExpression oclExpression = getConstraintExpression(constraints); OperationCallExp exp = checkOperationCallExp(((OperationCallExp)oclExpression).getSource(), "getTapes", "Set(Tape)"); checkImplicitSource(exp, "self", "SpecialFilm"); }
public void testSize_05() { List <object> constraints = doTestContextOK("context Film inv: Set{1, 2}->size() > 10", getCurrentMethodName()); OclExpression oclExpression = getConstraintExpression(constraints); OperationCallExp finalExp = (OperationCallExp)oclExpression; OperationCallExp exp = checkOperationCallExp(finalExp.getSource(), "size", "Integer"); checkCollectionLiteralExp(exp.getSource(), "Set(Integer)"); }
public void testSize_08() { List <object> constraints = doTestContextOK("context Film inv: self.name->asOrderedSet()->isEmpty()", getCurrentMethodName()); OclExpression oclExpression = getConstraintExpression(constraints); OperationCallExp finalExp = (OperationCallExp)oclExpression; OperationCallExp exp = checkOperationCallExp(finalExp, "isEmpty", "Boolean"); checkOperationCallExp(exp.getSource(), "asOrderedSet", "OrderedSet(String)"); }
public void testProduct_03() { List <object> constraints = doTestContextOK("context Film inv: self.Reservation->product(self.tapes)->isEmpty()", getCurrentMethodName()); OclExpression oclExpression = getConstraintExpression(constraints); OperationCallExp finalExp = (OperationCallExp)oclExpression; OperationCallExp exp = checkOperationCallExp(finalExp, "isEmpty", "Boolean"); checkOperationCallExp(exp.getSource(), "product", "Set(Tuple(first : Reservation, second : Tape))"); }
public void testSize_03() { List <object> constraints = doTestContextOK("context Film inv: self.getTapes()->size() > 10", getCurrentMethodName()); OclExpression oclExpression = getConstraintExpression(constraints); OperationCallExp finalExp = (OperationCallExp)oclExpression; OperationCallExp exp = checkOperationCallExp(finalExp.getSource(), "size", "Integer"); checkOperationCallExp(exp.getSource(), "getTapes", "Set(Tape)"); }
public void visitOperationCalllExpEnd(OperationCallExp exp) { // put parenthesis in the end of operation formula var operation = exp.getReferredOperation(); if (operation != null && !(exp.getSource() is VariableExpImpl)) { formula += ")"; navigationLevel = 0; } }
public void testSize_04B() { List <object> constraints = doTestContextOK("context Film inv: (self.getTapes()).theFilm->size() > 10", getCurrentMethodName()); OclExpression oclExpression = getConstraintExpression(constraints); OperationCallExp finalExp = (OperationCallExp)oclExpression; OperationCallExp exp = checkOperationCallExp(finalExp.getSource(), "size", "Integer"); checkIteratorExp(exp.getSource(), "Bag(Film)", "collect", "Tape", "iterator"); }
public void testIterate_03() { List <object> constraints = doTestContextOK("context Film inv: self.tapes->iterate(x : Tape; result : Set(Tape) = Set{} | if x.number > 5 then result->including(x) else result endif)->size() > 5", getCurrentMethodName()); OclExpression oclExpression = getConstraintExpression(constraints); Assert.IsTrue(oclExpression is OperationCallExp); OperationCallExp opCallExp = (OperationCallExp)oclExpression; checkIterateExp(((OperationCallExp)(opCallExp.getSource())).getSource(), "Set(Tape)", "result", "x", "Tape", "Set(Tape)", 1); }
public void testIterateWithError_03() { List <object> constraints = doTestContextOK("context Film inv: self.tapes->iterate(x : Tape, y : Tape; total : Integer = 0 | total + x.number) > 5", getCurrentMethodName()); OclExpression oclExpression = getConstraintExpression(constraints); Assert.IsTrue(oclExpression is OperationCallExp); OperationCallExp opCallExp = (OperationCallExp)oclExpression; checkIterateExp(opCallExp.getSource(), "Integer", "total", "x", "Tape", "Integer", 2); }
private static bool IsEvolutionPrevStep(PropertyCallExp node) { OperationCallExp operationCallExp = node.Source as OperationCallExp; if (operationCallExp != null) { if (operationCallExp.ReferredOperation.Tag is PrevOperationTag) { return(true); } } return(false); }