Exemplo n.º 1
0
        private void AddClosureOptions(IteratorExp node)
        {
            if (node.Iterator.Count == 1)
            {
                if (node.Body is PropertyCallExp)
                {
                    PSMPath path = PSMPathBuilder.BuildPSMPath((PropertyCallExp)node.Body, OclContext, VariableNamer, buildPathParams);

                    // oclX:closure(departments/department, function($c) { $c/subdepartments/department })/name
                    //              departments/department/descendant-or-self::department

                    /*
                     * departments/department + /subdepartments/department
                     */
                    if (PathsJoinable(path, node) && path.IsDownwards && path.Steps.Count > 0)
                    {
                        TranslationOption descendantOption = new TranslationOption();
                        string            lastStep         = path.Steps.Last().ToXPath();
                        if (lastStep.StartsWith("/"))
                        {
                            lastStep = lastStep.Substring(1);
                        }
                        descendantOption.FormatString = string.Format("{{0}}/descendant-or-self::{0}", lastStep);
                        SubexpressionTranslations.AddTranslationOption(node, descendantOption);
                    }
                }
            }
        }
Exemplo n.º 2
0
        public virtual void Visit(PropertyCallExp node, bool isOperationArgument)
        {
            AssignIsPartOfIteratorBody(node);
            PSMPath psmPath = PSMPathBuilder.BuildPSMPath(node, OclContext, VariableNamer, buildPathParams);
            string  xpath   = psmPath.ToXPath(delayFirstVariableStep: true);

            if (!isOperationArgument)
            {
                string wrapString = OperationHelper.WrapAtomicOperand(node, null, 0);
                xpath = string.Format(wrapString, xpath);
            }

            var steps = psmPath.Steps.OfType <IPSMPathStepWithCardinality>().Where(s => s.Lower == 0);

            if (steps.Any())
            {
                Log.AddWarningTaggedFormat("Navigation using '{0}' may result in 'null', which will be an empty sequence in XPath. ", node, steps.ConcatWithSeparator(s => s.ToXPath(), ","));
            }

            TranslationOption option = new TranslationOption();

            if (psmPath.StartingVariableExp != null)
            {
                option.ContextVariableSubstitution = true;
                option.StartingVariable            = psmPath.StartingVariableExp.referredVariable;
            }
            option.FormatString = xpath;
            SubexpressionTranslations.AddTranslationOption(node, option, psmPath.SubExpressions.ToArray());
        }
Exemplo n.º 3
0
        public void Visit(PropertyCallExp node)
        {
            PSMPath path = PSMPathBuilder.BuildPSMPath(node, null, VariableNamer,
                                                       new BuildPSMPathParams(TupleLiteralToXPathCallback, ClassLiteralToXPathCallback, GenericExpressionToXPathCallback, GetRelativeXPathEvolutionCallback));

            if (path.StartingVariableExp != null)
            {
                ReferredVariables.AddIfNotContained(path.StartingVariableExp.referredVariable);
            }
        }
Exemplo n.º 4
0
        public override void Visit(ClassLiteralExp node)
        {
            base.Visit(node);
            PSMPath psmPath = PSMPathBuilder.BuildPSMPath(node, OclContext, VariableNamer, buildPathParams);
            string  xpath   = psmPath.ToXPath();

            TranslationOption option = new TranslationOption();

            option.FormatString = xpath;
            SubexpressionTranslations.AddTranslationOption(node, option, psmPath.SubExpressions.ToArray());
        }
Exemplo n.º 5
0
        public virtual void Visit(VariableExp node)
        {
            AssignIsPartOfIteratorBody(node);
            PSMPath psmPath = PSMPathBuilder.BuildPSMPath(node, OclContext, VariableNamer, buildPathParams);
            string  xpath   = psmPath.ToXPath(delayFirstVariableStep: true);

            TranslationOption option = new TranslationOption();

            if (psmPath.StartingVariableExp != null)
            {
                option.ContextVariableSubstitution = true;
                option.StartingVariable            = psmPath.StartingVariableExp.referredVariable;
            }
            option.FormatString = xpath;
            SubexpressionTranslations.AddTranslationOption(node, option, psmPath.SubExpressions.ToArray());
        }
Exemplo n.º 6
0
        private void AddCollectOptions(IteratorExp node)
        {
            if (node.Iterator.Count == 1)
            {
                TranslationOption option = new TranslationOption();
                option.ParenthesisWhenNotTopLevel = true;
                option.FormatString = string.Format("for ${0} in {{0}} return {{1}}", node.Iterator[0].Name);
                SubexpressionTranslations.AddTranslationOption(node, option);

                /* when the body of collect is a navigation that can be chained, replace it */
                if (node.Body is PropertyCallExp)
                {
                    PSMPath path = PSMPathBuilder.BuildPSMPath((PropertyCallExp)node.Body, OclContext, VariableNamer, buildPathParams);
                    if (PathsJoinable(path, node))
                    {
                        TranslationOption option2 = new TranslationOption();
                        option2.FormatString = string.Format("{{0}}{0}", path.ToXPath(withoutFirstStep: true));
                        SubexpressionTranslations.AddTranslationOption(node, option2);
                    }
                }
            }
        }