public CoreOperation createOclDefinedOperation(string source, string name, List <object> paramNames, List <object> paramTypes, CoreClassifier returnType)
        {
            CoreOperation oclDefinedOperation = classifier.getModel().getOclPackage().getConstraints().getOclDefinedOperation().createOclDefinedOperation();

            ((OclDefinedOperationImpl)oclDefinedOperation).setName(name);
            ((OclDefinedOperationImpl)oclDefinedOperation).setParamNames(paramNames);
            ((OclDefinedOperationImpl)oclDefinedOperation).setParamTypes(paramTypes);
            ((OclDefinedOperationImpl)oclDefinedOperation).setReturnType(returnType);
            ((OclDefinedOperationImpl)oclDefinedOperation).setSource(source);

            createdFeatures.Add(oclDefinedOperation);

            return(oclDefinedOperation);
        }
示例#2
0
        public void testPost_01()
        {
            doTestManyContextOK("context Film::getTapes() : Set(Tape) post myPost: result = tapes->select(rentalFee > 10)  ",
                                getCurrentMethodName());

            CoreClassifier film      = (CoreClassifier)environment.lookup("Film");
            CoreOperation  operation = film.lookupOperation("getTapes", null);

            Assert.AreEqual(1, new List <object>(operation.getSpecifications()).Count);
            OclPrePostConstraint constraint = (OclPrePostConstraint) new List <object>(operation.getSpecifications())[0];

            Assert.AreEqual(1, new List <object>(constraint.getPostConditions()).Count);
            Assert.AreEqual("myPost", ((OclPostConstraint) new List <object>(constraint.getPostConditions())[0]).getName());
        }
示例#3
0
        public OclBodyConstraint       createBodyConstraint(string source, CoreOperation contextualOperation, ExpressionInOcl body, List <string> parameterNames)
        {
            OclBodyConstraint constraint = new OclBodyConstraintImpl();

            constraint.setSource(source);
            constraint.setContextualOperation(contextualOperation);
            constraint.setExpression(body);
            constraint.setParameterNames(parameterNames);

            contextualOperation.setBodyDefinition(constraint);

//		cachedObjects.add(constraint);

            return(constraint);
        }
示例#4
0
        private CoreOperation operationOwnerMatchingDesiredOwner(
            List <object> matchingOperations,
            CoreClassifier desiredOwner)
        {
            for (int i = 0; i < matchingOperations.Count; i++)
            {
                CoreOperation oper = (CoreOperation)matchingOperations[i];
                if (oper.getElemOwner() == desiredOwner)
                {
                    return(oper);
                }
            }

            return(null);
        }
示例#5
0
        private int deleteAllDefinedElements(string sourceName)
        {
            List <object> namesToBeRemovedFromEnvironment = new List <object>();
            int           result = 0;

            List <CoreFeature> elementsToBeRemoved;

            this.definedFeaturesBySource.TryGetValue(sourceName, out elementsToBeRemoved);
            if (elementsToBeRemoved != null)
            {
                foreach (CoreFeature modelElement in elementsToBeRemoved)
                {
                    if (modelElement is CoreAttributeImpl)
                    {
                        CoreAttribute attr = (CoreAttribute)modelElement;
                        namesToBeRemovedFromEnvironment.Add(attr.getName());
                    }
                    else
                    {
                        CoreOperation oper = (CoreOperation)modelElement;
                        namesToBeRemovedFromEnvironment.Add(
                            CoreModelElementNameGeneratorImpl.getInstance().generateNameForOperation(oper.getName(),
                                                                                                     new List <object>(oper.getParametersTypesExceptReturn())));
                    }
                }

                result = elementsToBeRemoved.Count;

                foreach (string element in namesToBeRemovedFromEnvironment)
                {
                    CoreFeature coreFeature;
                    bool        foudbefore = this.definedFeatures.TryGetValue(element, out coreFeature);
                    this.definedFeatures.Remove(element);
                    bool foundafter = this.definedFeatures.TryGetValue(element, out coreFeature);
                }

                if (this.definedFeaturesBySource.ContainsKey(sourceName))
                {
                    this.definedFeaturesBySource[sourceName] = new List <CoreFeature>();
                }
                else
                {
                    this.definedFeaturesBySource.Add(sourceName, new List <CoreFeature>());
                }
            }

            return(result);
        }
示例#6
0
        /* (non-Javadoc)
         * @see ocl20.CoreClassifier#lookupOperation(java.lang.String, java.util.Collection)
         */

        public virtual CoreOperation lookupOperation(String name, List <object> paramTypes)
        {
            Environment   env        = this.getEnvironmentWithoutParents();
            List <object> operations = env.lookupOperationLocal(name);

            if (operations != null)
            {
                List <object> matchingOperations = new List <object>();

                foreach (CoreOperation operation in operations)
                {
                    if (operation.hasMatchingSignature(paramTypes))
                    {
                        matchingOperations.Add(operation);
                    }
                }

                if (matchingOperations.Count == 1)
                {
                    return((CoreOperation)matchingOperations[0]);
                }
                else
                {
                    CoreOperation result = operationOwnerMatchingDesiredOwner(matchingOperations,
                                                                              this);

                    if (result == null)
                    {
                        List <object> ancestors = getAllAncestors();

                        foreach (CoreClassifier ancestor in ancestors)
                        {
                            result = operationOwnerMatchingDesiredOwner(matchingOperations, ancestor);
                            if (result != null)
                            {
                                break;
                            }
                        }
                    }

                    return(result);
                }
            }

            return(null);
        }
        public void testNewOperation_01()
        {
            doTestContextOK("context SpecialFilm def: isSpecialFilm() : Boolean = name = \"Special\"",
                            getCurrentMethodName());
            CoreClassifier classifier = (CoreClassifier)environment.lookup("SpecialFilm");
            List <object>  paramTypes = new List <object>();
            CoreClassifier returnType = (CoreClassifier)environment.lookup("Boolean");

            CoreOperation definedOperation = classifier.lookupSameSignatureOperation("isSpecialFilm", paramTypes, returnType);

            Assert.IsNotNull(definedOperation);
            Assert.IsNotNull(definedOperation.getBodyDefinition());
            OclBodyConstraint constraint = definedOperation.getBodyDefinition();

            Assert.IsNotNull(constraint);
            Assert.AreEqual("Boolean", ((ExpressionInOclImpl)constraint.getExpression()).getBodyExpression().getType().getName());
        }
示例#8
0
        public void testPrePost_03()
        {
            doTestManyContextOK("context Film::getTapes() : Set(Tape) pre myPre0: tapes->size() > 0   pre anotherPre0: tapes->size() < 10   post myPost0: result = tapes->select(rentalFee > 10)   post anotherPost0: result = tapes->select(rentalFee > 10)  " +
                                "context Film::getTapes() : Set(Tape) pre myPre1: tapes->size() > 0 pre anotherPre1: tapes->size() < 10 post myPost1: result = tapes->select(rentalFee > 10)  post anotherPost1: result = tapes->select(rentalFee > 10)  ",
                                getCurrentMethodName());

            CoreClassifier film      = (CoreClassifier)environment.lookup("Film");
            CoreOperation  operation = film.lookupOperation("getTapes", null);

            Assert.AreEqual(2, new List <object>(operation.getSpecifications()).Count);
            for (int i = 0; i < 2; i++)
            {
                OclPrePostConstraint constraint = (OclPrePostConstraint) new List <object>(new List <object>(operation.getSpecifications()))[i];
                Assert.AreEqual(2, constraint.getPreConditions().Count);
                Assert.AreEqual("myPre" + i, ((OclPreConstraint) new List <object>(constraint.getPreConditions())[0]).getName());
                Assert.AreEqual("anotherPre" + i, ((OclPreConstraint) new List <object>(constraint.getPreConditions())[1]).getName());
                Assert.AreEqual(2, new List <object>(constraint.getPostConditions()).Count);
                Assert.AreEqual("myPost" + i, ((OclPostConstraint) new List <object>(constraint.getPostConditions())[0]).getName());
                Assert.AreEqual("anotherPost" + i, ((OclPostConstraint) new List <object>(constraint.getPostConditions())[1]).getName());
            }
        }
示例#9
0
        /* (non-Javadoc)
         * @see AstOclModelElementFactory#createCollectionOperation(CoreOperation, CoreClassifier)
         */
        public CollectionOperation createCollectionOperation(
            CoreOperation jmiOperation, CoreClassifier owner)
        {
//          String key = owner.getFullPathName() + jmiOperation.getName();

            String key = owner.getFullPathName() + CoreModelElementNameGeneratorImpl.getInstance().generateName(jmiOperation);
            CollectionOperation operation;

            allCollectionOperations.TryGetValue(key, out operation);

            if (operation == null)
            {
                operation = oclPackage.getTypes().getCollectionOperation();
                operation.setFeatureOwner(owner);
                operation.setJmiOperation(jmiOperation);
                allCollectionOperations.Add(key, operation);
            }

            operation.setFeatureOwner(owner);

            return(operation);
        }
示例#10
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 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());
        }
示例#12
0
        public void testBody()
        {
            AstOclConstraintFactory   factory1 = AstOclConstraintFactoryManager.getInstance(umlModel.getOclPackage());
            AstOclModelElementFactory factory2 = AstOclModelElementFactoryManager.getInstance(umlModel.getOclPackage());

            RealLiteralExp  exp1     = factory2.createRealLiteralExp("200.50", getClassifier("Real"));
            ExpressionInOcl expInOcl = factory1.createExpressionInOcl("name", getClassifier("Film"), exp1);

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

            parms.Add(getClassifier("Integer"));
            CoreOperation oper = getClassifier("Film").lookupOperation("getRentalFee", parms);

            OclBodyConstraint constraint = (OclBodyConstraint)factory1.createBodyConstraint("test.ocl", oper, expInOcl, null);

            Assert.AreEqual("body: 200.50", constraint.ToString());

            Assert.AreEqual(constraint, oper.getBodyDefinition());
            Assert.AreEqual(expInOcl, oper.getBodyDefinition().getExpression());

            oper.deleteAllConstraintsForSource("test.ocl");
            Assert.IsNull(oper.getBodyDefinition());
        }
示例#13
0
        public void testPrePost_DefLocalVar_01()
        {
            doTestManyContextOK("context Film::getTapes() : Set(Tape) \r\n" +
                                "def: theSize : Integer = tapes->size() \r\n" +
                                "def: abc : Integer = theSize + 10 \r\n" +
                                "pre myPre: theSize > 0 \r\n" +
                                "post myPost: result = tapes->select(rentalFee > 10) \r\n" +
                                "pre anotherPre: theSize < 10 and abc > 20",
                                getCurrentMethodName());

            CoreClassifier film      = (CoreClassifier)environment.lookup("Film");
            CoreOperation  operation = film.lookupOperation("getTapes", null);

            Assert.AreEqual(1, new List <object>(operation.getSpecifications()).Count);
            OclPrePostConstraint constraint = (OclPrePostConstraint) new List <object>(operation.getSpecifications())[0];

            Assert.AreEqual(2, constraint.getPreConditions().Count);
            Assert.AreEqual("myPre", ((OclPreConstraint) new List <object>(constraint.getPreConditions())[0]).getName());
            Assert.AreEqual("anotherPre", ((OclPreConstraint) new List <object>(constraint.getPreConditions())[1]).getName());
            Assert.AreEqual(1, new List <object>(constraint.getPostConditions()).Count);
            Assert.AreEqual("myPost", ((OclPostConstraint) new List <object>(constraint.getPostConditions())[0]).getName());
            Assert.IsNotNull(operation.lookupLocalVariable("theSize"));
        }
        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());
        }
示例#15
0
        /* (non-Javadoc)
         * @see br.cos.ufrj.lens.odyssey.tools.psw.parser.environment.Environment#lookupLocal(string)
         */
        public List <object> lookupOperationLocal(string name)
        {
            List <object> operationsFound = new List <object>();

            foreach (KeyValuePair <string, NamedElement> entry in namedElements)
            {
                if (entry.Key.StartsWith(name))
                {
                    NamedElement element;
                    this.namedElements.TryGetValue(entry.Key, out element);

                    if (element != null && element.getReferredElement().GetType() == typeof(CoreOperation))
                    {
                        CoreOperation operation = (CoreOperation)element.getReferredElement();
                        if (operation.operationNameMatches(name))
                        {
                            operationsFound.Add(operation);
                        }
                    }
                }
            }

            return(operationsFound);
        }
示例#16
0
        public void testDefOperation()
        {
            List <object> paramNames = new List <object>();

            paramNames.Add("param1");

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

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

            getClassifier("Film").addDefinedOperation("test.ocl", "myNewOper", paramNames, paramTypes, getClassifier("Integer"));

            CoreOperation oper = getClassifier("Film").lookupOperation("myNewOper", paramTypes);

            Assert.AreEqual("Integer", oper.getReturnType().getName());
            Assert.IsTrue(oper.isOclDefined());
            List <object> args = new List <object>();

            args.Add(getClassifier("Integer"));
            Assert.IsTrue(oper.hasMatchingSignature(args));

            getClassifier("Film").deleteAllConstraintsForSource("test.ocl");
            Assert.IsNull(getClassifier("Film").lookupOperation("myNewOper", paramTypes));
        }
        public void testLetExp()
        {
            AstOclModelElementFactory factory1 = AstOclModelElementFactoryManager.getInstance(umlModel.getOclPackage());

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

            OclExpression varExp     = factory1.createVariableExp(variable);
            OclExpression intLiteral = factory1.createIntegerLiteralExp(200, getClassifier("Integer"));
            List <object> paramTypes = new List <object>();

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

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

            args.Add(intLiteral);
            OclExpression inExp = factory1.createOperationCallExp(varExp, oper, args, getClassifier("Integer"), false);

            LetExp exp = factory1.createLetExp(variable, inExp);

            Assert.AreEqual("let abc : Integer = 100 in abc + 200", exp.ToString());
            Assert.AreEqual("Integer", exp.getType().getName());
        }
 public abstract void setJmiOperation(CoreOperation newValue);
示例#19
0
 /**
  * @param contextualOperation The contextualOperation to set.
  */
 public void setContextualOperation(CoreOperation contextualOperation)
 {
     this.contextualOperation = contextualOperation;
 }
 /**
  * @param referredOperation The referredOperation to set.
  */
 public void setReferredOperation(CoreOperation referredOperation)
 {
     this.referredOperation = referredOperation;
 }
示例#21
0
        private String generateNameForOperation(CoreOperation operation)
        {
            List <object> parametersNames = operation.getParametersTypesNamesExceptReturn();

            return(generateOperationName(operation.getName(), parametersNames));
        }
示例#22
0
        public OclPostConstraint               createPostConstraint(OclPrePostConstraint owner, string source, string name, CoreOperation contextualOperation, ExpressionInOcl postCondition)
        {
            OclPostConstraint constraint = new OclPostConstraintImpl();

            constraint.setSource(source);
            constraint.setContextualOperation(contextualOperation);
            constraint.setExpression(postCondition);
            constraint.setName(name);
            constraint.setOwner(owner);
            owner.addPostCondition(constraint);

//		cachedObjects.add(constraint);

            return(constraint);
        }
示例#23
0
        public CoreOperationView(CoreOperation operation, long accountId) : base("CoreOperationView")
        {
            AddRow("Type", Tr.Get("CoreOperation." + operation.CoreOperationType.ToString()));

            switch (operation.CoreOperationType)
            {
            case CoreOperationTypes.Account:
                var ao = operation as AccountOperation;
                AddRow("AccountId", ao.AccountId.ToString());
                AddRow("PublicKey", ao.PublicKey.HexString);
                break;

            case CoreOperationTypes.AccountUpdate:
                var bo = operation as AccountUpdateOperation;

                var balanceChanged = false;
                foreach (var account in bo.Updates)
                {
                    foreach (var transfer in account.Value.Transfers)
                    {
                        if (transfer.ReceiverId == accountId)
                        {
                            balanceChanged = true;
                        }
                    }
                }

                if (bo.Updates.TryGetValue(accountId, out var update))
                {
                    if (update.Purchases.Count > 0 || update.Transfers.Count > 0)
                    {
                        balanceChanged = true;
                    }

                    if (balanceChanged)
                    {
                        AddRow("NewBalance", Currency.ToString(update.Balance));
                    }

                    foreach (var purchase in update.Purchases)
                    {
                        AddRow("Purchased", Tr.Get("CoreOperationView.PurchasedInfo", purchase.PurchaseItemId, purchase.ChainId, Currency.ToString(purchase.Price)));
                    }

                    foreach (var join in update.Joins)
                    {
                        AddRow("Joined", Tr.Get("CoreOperationView.JoinInfo", join.ChainId, join.KeyIndex));
                    }

                    foreach (var transfer in update.Transfers)
                    {
                        AddRow("Sent", Tr.Get("CoreOperationView.SentInfo", Currency.ToString(transfer.Amount), transfer.ReceiverId, transfer.Reason ?? "-"));
                    }
                }

                foreach (var account in bo.Updates)
                {
                    foreach (var transfer in account.Value.Transfers)
                    {
                        if (transfer.ReceiverId == accountId)
                        {
                            AddRow("Received", Tr.Get("CoreOperationView.ReceivedInfo", Currency.ToString(transfer.Amount), account.Value.AccountId, transfer.Reason ?? "-"));
                        }
                    }
                }

                break;

            case CoreOperationTypes.ChainInfo:
                var co = operation as ChainInfoOperation;
                AddRow("ChainId", co.ChainId.ToString());
                break;
            }

            AddRow("Id", operation.OperationId.ToString());
            AddLastRow("Date", Time.DateTimeString(operation.Timestamp));
        }
 public void setJmiOperation(CoreOperation newValue)
 {
     jmiOperation = newValue;
 }