示例#1
0
        protected void updateSupplierDependency(CoreClassifier owner, Dependency newConnection)
        {
            List <Dependency> supplierDependency = owner.getSupplierDependency();

            supplierDependency.Add(newConnection);
            owner.setSupplierDependency(supplierDependency);
        }
示例#2
0
 public CollectionType createCollectionType(
     String name,
     CoreClassifier elementType)
 {
     if (name.StartsWith("Bag"))
     {
         return(createBagType(elementType));
     }
     else if (name.StartsWith("Set"))
     {
         return(createSetType(elementType));
     }
     else if (name.StartsWith("Sequence"))
     {
         return(createSequenceType(elementType));
     }
     else if (name.StartsWith("OrderedSet"))
     {
         return(createOrderedSetType(elementType));
     }
     else if (name.StartsWith("Collection"))
     {
         return(createCollectionType(elementType));
     }
     else
     {
         return(null);
     }
 }
        public override bool conformsTo(CoreClassifier type)
        {
            if (!(type is CollectionTypeImpl))
            {
                return(false);
            }

            if (((CollectionTypeImpl)type).getCollectionKind() == CollectionKindEnum.COLLECTION ||
                ((CollectionTypeImpl)type).getCollectionKind() == this.getKind())
            {
                CoreClassifier targetType = ((CollectionType)type).getElementType();

                foreach (CollectionLiteralPartImpl collectionItem in getParts())
                {
                    if (!collectionItem.conformsTo(targetType))
                    {
                        return(false);
                    }
                }
            }
            else
            {
                return(false);
            }

            return(true);
        }
示例#4
0
        private void createAbstraction(XElement xabstraction)
        {
            CoreModelElement client   = null;
            CoreModelElement supplier = null;

            XAttribute xattributeclient = xabstraction.Attribute("client");

            if (xattributeclient != null)
            {
                string xclientidref = xattributeclient.Value;
                lookup.TryGetValue(xclientidref, out client);
            }

            XAttribute xattributesupplier = xabstraction.Attribute("supplier");

            if (xattributesupplier != null)
            {
                string xsupplieridref = xattributesupplier.Value;
                lookup.TryGetValue(xsupplieridref, out supplier);
            }

            CoreClassifier coreClassifier = (CoreClassifier)client;
            CoreInterface  coreInterface  = (CoreInterface)supplier;

            Dependency dependency = new DependencyImpl();

            updateClient(dependency, coreClassifier);
            updateSupplier(dependency, coreInterface);

            updateClientDependency(coreInterface, dependency);
            updateSupplierDependency(coreClassifier, dependency);
        }
示例#5
0
 public CoreClassifier getExpressionType(CoreClassifier sourceType, CoreAssociationEnd associationEnd, CoreClassifier elementType)
 {
     if (sourceType is CollectionTypeImpl)
     {
         if ((sourceType is SetTypeImpl || sourceType is BagTypeImpl) && (!associationEnd.isOrdered())
             )
         {
             return(getFactory().createBagType(elementType));
         }
         else
         {
             return(getFactory().createSequenceType(elementType));
         }
     }
     else
     {
         if (isSingleElementAccess(sourceType, associationEnd))
         {
             return(elementType);
         }
         else if (associationEnd.isOrdered())
         {
             return(getFactory().createOrderedSetType(elementType));
         }
         else
         {
             return(getFactory().createSetType(elementType));
         }
     }
 }
示例#6
0
 private bool isSingleElementAccess(CoreClassifier sourceType, CoreAssociationEnd associationEnd)
 {
     return
         ((sourceType is CoreAssociationClassImpl) ||
          (associationEnd.isOneMultiplicity() && !associationEndHasQualifiers(associationEnd)) ||
          (associationEnd.isOneMultiplicity() && associationEndHasQualifiers(associationEnd) && getQualifiers().Count > 0));
 }
示例#7
0
        public VariableDeclaration lookupSourceForImplicitProperty(
            string simpleName,
            List <object> parms)
        {
            List <object> variables = this.getVariableElements();

            if (variables.Count > 0)
            {
                foreach (NamedElement element  in variables)
                {
                    VariableDeclaration variable   = (VariableDeclaration)element.getReferredElement();
                    CoreClassifier      classifier = variable.getType();

                    if (element.isMayBeImplicit() &&
                        isFeatureDefinedInClassifier(classifier, simpleName,
                                                     parms))
                    {
                        return(variable);
                    }
                }
            }

            if (this.hasParent())
            {
                return(this.getParent()
                       .lookupSourceForImplicitFeature(simpleName));
            }

            return(null);
        }
示例#8
0
        /* (non-Javadoc)
         * @see br.cos.ufrj.lens.odyssey.tools.psw.metamodels.core.interfaces.CoreClassifier#conformsTo(br.cos.ufrj.lens.odyssey.tools.psw.metamodels.core.interfaces.CoreClassifier)
         */
        public override bool conformsTo(CoreClassifier c)
        {
            if (c.getName().Equals("OclAny"))
            {
                return(true);
            }

            if (!(c is TupleTypeImpl))
            {
                return(false);
            }

            TupleType typeToMatch = (TupleType)c;

            if (this.getTupleParts().Count != typeToMatch.getTupleParts().Count)
            {
                return(false);
            }

            List <object> tupleTypes = new List <object>(getTupleParts());

            for (int i = 0; i < tupleTypes.Count; i++)
            {
                TuplePartType element      = (TuplePartType)tupleTypes[i];
                CoreAttribute elementFound = typeToMatch.lookupAttribute(element.getName());
                if (elementFound == null || !element.getFeatureType().conformsTo(elementFound.getFeatureType()))
                {
                    return(false);
                }
            }
            return(true);
        }
示例#9
0
        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);
        }
示例#10
0
        private Generalization createGeneralization(XNamespace xnamespace, XElement xgeneralization)
        {
            Generalization generalization = new GeneralizationImpl();

            XAttribute xattributechild = xgeneralization.Attribute("child");

            if (xattributechild != null)
            {
                fillGeneralizationMode1(xgeneralization, generalization, xattributechild);
            }
            else
            {
                XElement xchild = xgeneralization.Element(xnamespace + "Generalization.child");
                if (xchild != null)
                {
                    fillGeneralizationMode2(xnamespace, xgeneralization, generalization, xchild);
                }
            }

            CoreClassifier child = generalization.getChild();

            updateChildGeneralizations(child, generalization);

            CoreClassifier parent = generalization.getParent();

            updateParentSpecializations(parent, generalization);

            lookup.Add(xgeneralization.Attribute("xmi.id").Value, generalization);

            return(generalization);
        }
示例#11
0
        protected void updateChildGeneralizations(CoreClassifier owner, Generalization newGeneralization)
        {
            List <Generalization> generalizations = owner.getGeneralization();

            generalizations.Add(newGeneralization);
            owner.setGeneralization(generalizations);
        }
        //	private void getAllInvariants(Map allInvariants) {
        //		InvariantsCollector collector = new InvariantsCollector(this.getJmiClassifier(), allInvariants);
        //		collector.traverseAllAncestors();
        //	}
        public CoreModelElement addDefinedElement(
            string source,
            string name,
            CoreClassifier type)
        {
            List <object> allSubClasses = classifier.getAllSubClasses();

            foreach (CoreClassifier subClass in allSubClasses)
            {
                Environment env = subClass.getEnvironmentWithoutParents();

                if (env.lookup(name) != null)
                {
                    string errorMessage = "<{0}> already defined in a derived classifier";
                    throw new NameClashException(string.Format(errorMessage, new object[] { name }));
                }
            }

            CoreFeature element = createOclDefinedAttribute(source, name, type);

            element.setFeatureOwner(classifier);
            element.setElemOwner(classifier);

            this.definedFeatures.Add(name, element);
            addElementToDefinedFeaturesBySource(source, element);

            return(element);
        }
        public CoreOperation createSpecificOperation(CoreClassifier classifier, String name, List <object> paramNames, List <object> paramTypes, CoreClassifier returnType)
        {
            UmlPackage mainPackage = (UmlPackage)classifier.getModel().getMainPackage();

            Operation operation = mainPackage.getFoundation().getCore().getOperation();

            operation.setName(name);
            operation.setNamespace((Classifier)this);

            for (int i = 0; i < paramNames.Count; i++)
            {
                String    paramName    = (String)paramNames[i];
                Parameter newParameter = mainPackage.getFoundation().getCore().getParameter();

                newParameter.setBehavioralFeature(operation);
                newParameter.setName(paramName);
                newParameter.setType((Classifier)paramTypes[i]);
                newParameter.setKind(ParameterDirectionKindEnum.PDK_IN);
            }

            Parameter returnParameter = mainPackage.getFoundation().getCore().getParameter();

            returnParameter.setBehavioralFeature(operation);
            returnParameter.setName("return");
            returnParameter.setType((Classifier)returnType);
            returnParameter.setKind(ParameterDirectionKindEnum.PDK_RETURN);

            return((CoreOperation)operation);
        }
        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);
            }
        }
示例#15
0
        public CollectionType createSpecificCollectionType(
            CollectionKind collectionKind,
            CoreClassifier elementType)
        {
            if (collectionKind.Equals(CollectionKindEnum.BAG))
            {
                return(createBagType(elementType));
            }

            if (collectionKind.Equals(CollectionKindEnum.SET))
            {
                return(createSetType(elementType));
            }

            if (collectionKind.Equals(CollectionKindEnum.SEQUENCE))
            {
                return(createSequenceType(elementType));
            }

            if (collectionKind.Equals(CollectionKindEnum.ORDERED_SET))
            {
                return(createOrderedSetType(elementType));
            }

            if (collectionKind.Equals(CollectionKindEnum.COLLECTION))
            {
                return(createCollectionType(elementType));
            }


            return(null);
        }
示例#16
0
        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);
        }
示例#17
0
        /* (non-Javadoc)
         * @see ocl20.CoreClassifier#getMostSpecificCommonSuperType(ocl20.CoreClassifier)
         */

        public virtual CoreClassifier getMostSpecificCommonSuperType(
            CoreClassifier otherClassifier)
        {
            List <object> myAncestors    = this.getAllAncestors();
            List <object> otherAncestors = otherClassifier.getAllAncestors();

            if ((this == otherClassifier) || otherAncestors.Contains(this) ||
                OCLVOID.Equals(otherClassifier.getName()) ||
                OCLINVALID.Equals(otherClassifier.getName()))
            {
                return(this);
            }
            else if (myAncestors.Contains(otherClassifier))
            {
                return(otherClassifier);
            }
            else if (OCLVOID.Equals(this.getName()) ||
                     OCLINVALID.Equals(this.getName()))
            {
                return(otherClassifier);
            }
            else
            {
                foreach (CoreClassifier aSuperClass in otherAncestors)
                {
                    if (myAncestors.Contains(aSuperClass) || (aSuperClass == this))
                    {
                        return(aSuperClass);
                    }
                }
            }

            return((CoreClassifier)getGlobalEnvironment().lookup(OCLANY));
        }
示例#18
0
        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");
        }
示例#19
0
        protected void updateParentSpecializations(CoreClassifier owner, Generalization newSpecialization)
        {
            List <Generalization> specializations = owner.getSpecialization();

            specializations.Add(newSpecialization);
            owner.setSpecialization(specializations);
        }
        public void visitAttributeCallExp(AttributeCallExp exp)
        {
            if (exp.getSource() is AssociationEndCallExpImpl)
            {
                string typeName, name;
                getTableReference(exp, 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);
            }
            else
            {
                string typeName, name;
                getTableReference(exp, out name, out typeName);

                // format table_name[column_name] (same of classifier.attribute)
                formula += string.Format("{0}[{1}]", typeName, name);

                if (currentClassifier == null)
                {
                    currentClassifier = (CoreClassifier)exp.getReferredAttribute().getElemOwner();
                }
            }
        }
示例#21
0
        /* (non-Javadoc)
         * @see AstOclModelElementFactory#createNullLiteralExp(CoreClassifier)
         */
        public NullLiteralExp createNullLiteralExp(CoreClassifier type)
        {
            NullLiteralExp exp = new NullLiteralExpImpl();

            exp.setFactory(this);
            exp.setType(type);
            return(exp);
        }
示例#22
0
        /* (non-Javadoc)
         * @see AstOclModelElementFactory#createInvalidLiteralExp(CoreClassifier)
         */
        public InvalidLiteralExp createInvalidLiteralExp(CoreClassifier type)
        {
            InvalidLiteralExp exp = new InvalidLiteralExpImpl();

            exp.setFactory(this);
            exp.setType(type);
            return(exp);
        }
示例#23
0
        private XWorkbook createXFormulas(string expressionText, XWorkbook xWorkbook)
        {
            PSWOclCompiler oclCompiler = new PSWOclCompiler(environment, tracker);
            List <object>  nodes       = oclCompiler.compileOclStream(expressionText, "",
                                                                      new StreamWriter(Console.OpenStandardOutput()), typeof(CSTContextDeclarationCS));
            CSTOperationContextCS operationContextCS = ((CSTOperationContextCS)nodes[0]);
            var constraints = operationContextCS.getConstraintsNodesCS();
            CSTOperationConstraintCS operationConstraint = (CSTOperationConstraintCS)constraints[0];
            ExpressionInOcl          expressionInOcl     = operationConstraint.getExpressionInOCL();
            OclExpressionImpl        bodyExpression      = (OclExpressionImpl)expressionInOcl.getBodyExpression();

            XFormulaCreatorVisitor visitor = new XFormulaCreatorVisitor();

            bodyExpression.accept(visitor);
            string formula = visitor.getFormula();

            CoreClassifier classifier  = (CoreClassifier)expressionInOcl.getContextualElement();
            XDataTable     targetTable = getTargetTable(xWorkbook, classifier);

            var operation = operationContextCS.getOperationNodeCS();
            var name      = operation.getOperationName();
            XDataTableColumn targetColumn =
                targetTable.getDataTableColumns().FirstOrDefault(c => c.getName().Equals(name));

            if (targetColumn == null)
            {
                throw new Exception("Coluna não encontrada!");
            }

            XTextExp xtext = new XTextExp();

            xtext.setTextSymbol(formula);
            targetColumn.setDataContent(xtext);

            MessageBox.Show(formula);

            var extraColumns = visitor.getExtraColumns();

            foreach (KeyValuePair <string, string> pair in extraColumns)
            {
                string columnName    = pair.Key;
                string columnFormula = pair.Value;

                targetTable = getTargetTable(xWorkbook, visitor.getCurrentClassifier());

                var newTableColumn = new XDataTableColumn();
                newTableColumn.setName(columnName);
                newTableColumn.setDataTable(targetTable);
                updateDataTable(targetTable, newTableColumn);

                XTextExp xColumnFormula = new XTextExp();
                xColumnFormula.setTextSymbol(columnFormula);
                newTableColumn.setDataContent(xColumnFormula);
            }

            return(xWorkbook);
        }
        public static bool typeNeedsToBeParsed(CoreClassifier classifier)
        {
            if (!(classifier is CollectionTypeImpl))
            {
                return(typeNeedsToBeParsed(classifier.getName()));
            }

            return(false);
        }
        protected bool elementTypesConformance(CoreClassifier c)
        {
            if (!(this.getElementType() is CollectionTypeImpl) && (((CollectionType)c).getElementType() is CollectionTypeImpl))
            {
                return(false);
            }

            return(this.getElementType().conformsTo(((CollectionType)c).getElementType()) || isVoidType(((CollectionType)c).getElementType()));
        }
示例#26
0
        public void test_09()
        {
            String         stream = "Tuple(a : Film,  b : String, c : Integer)";
            CoreClassifier c      = doParseTestOK(stream, this.getCurrentMethodName(), "Tuple(a : Film, b : String, c : Integer)", typeof(TupleType));
            TupleType      tuple  = (TupleType)c;
            List <object>  parts  = tuple.getTupleParts();

            Assert.AreEqual(3, parts.Count);
        }
        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 createSpecificStereotype(CoreClassifier classifier, CoreFeature feature, String stereotypeName)
        {
            UmlPackage mainPackage = (UmlPackage)classifier.getModel().getMainPackage();

            //verificar
            Stereotype stereotype = mainPackage.getFoundation().getExtensionMechanisms().getStereotype();

            stereotype.setName(stereotypeName);
            mainPackage.getFoundation().getExtensionMechanisms().getAStereotypeExtendedElement().add(stereotype, (Feature)feature);
        }
示例#29
0
        public CoreAttribute addDefinedElement(
            String source,
            String name,
            CoreClassifier type)
        {
            CoreModelElement element = constraintsHolder.addDefinedElement(source, name, type);

            setDirty(true);
            return((CoreAttribute)element);
        }
示例#30
0
        protected String getParameterAsString(String parameterName, CoreClassifier parameterType)
        {
            StringBuilder result = new StringBuilder();

            result.Append(parameterName);
            result.Append(" : ");
            result.Append(parameterType.getName());

            return(result.ToString());
        }