예제 #1
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);
        }
예제 #2
0
        public void testSelect_08()
        {
            oclCompiler = new PSWOclCompiler(environment, tracker);
            CSTExpressionInOclCS rootNode = oclCompiler.compileOclExpression("Film::allInstances()->select(name.toInteger() > 10)",
                                                                             getCurrentMethodName(), new StreamWriter(Console.OpenStandardOutput()));

            source = getCurrentMethodName();
            Assert.IsNotNull(rootNode);
            Assert.AreEqual("Set(Film)", rootNode.getAst().getBodyExpression().getType().getName());
        }
예제 #3
0
 protected void parseWithError(String expression, String testName)
 {
     try {
         source      = testName;
         oclCompiler = new PSWOclCompiler(environment, tracker);
         List <object> nodes = oclCompiler.compileOclStream(expression, testName, new StreamWriter(Console.OpenStandardOutput()), getSpecificNodeClass());
         Assert.IsNull(nodes);
     } catch (Exception e) {
         Console.WriteLine(e.Message);
     }
 }
 protected void doTestManyContextNotOK(String expression, String testName)
 {
     try {
         source      = testName;
         oclCompiler = new PSWOclCompiler(environment, tracker);
         List <object> rootNode = oclCompiler.compileOclStream(expression, testName, new StreamWriter(Console.OpenStandardOutput()));
         if (oclCompiler.getErrorsCount() == 0)
         {
             throw new AssertFailedException();
         }
     } catch (Exception e) {
         Console.WriteLine(e.Message);
     }
 }
예제 #5
0
 protected CSTNode parseOK(String expression, String testName)
 {
     try {
         source      = testName;
         oclCompiler = new PSWOclCompiler(environment, tracker);
         List <object> nodes = oclCompiler.compileOclStream(expression, testName, new StreamWriter(Console.OpenStandardOutput()), getSpecificNodeClass());
         Assert.IsNotNull(nodes);
         Assert.IsTrue(nodes.Count >= 1);
         return((CSTNode)nodes[0]);
     } catch (Exception e) {
         Console.WriteLine(e.Message);
         throw new AssertFailedException();
     }
 }
        protected List <object> doTestManyContextOK(String expression, String testName)
        {
            try {
                source      = testName;
                oclCompiler = new PSWOclCompiler(environment, tracker);
                List <object> rootNode = oclCompiler.compileOclStream(expression, testName, new StreamWriter(Console.OpenStandardOutput()));
                Assert.IsNotNull(rootNode);
                Assert.IsTrue(rootNode.Count >= 1);
                return(rootNode);
            } catch (Exception e) {
                Console.WriteLine(e.Message);
            }

            return(null);
        }
예제 #7
0
        public static CoreClassifier createTypeFromString(String classifierName)
        {
            result = null;

            if (!OclTypesDefinition.isOclCollectionType(classifierName) &&
                !OclTypesDefinition.isOclTupleType(classifierName))
            {
                result = getType(classifierName);
            }

            if (result == null)
            {
                PSWOclCompiler oclCompiler = new PSWOclCompiler(environment, new ConstraintSourceTrackerImpl());
                result = oclCompiler.parseType(environment, classifierName);
                if (result.GetType() == typeof(CollectionType))
                {
                    ((CollectionTypeImpl)result).setInnerMostElementType(getType(((CollectionTypeImpl)result).getInnerMostElementType().getName()));
                }
            }

            return(result);
        }