Beispiel #1
0
        internal static bool TryConvertNodeToDPath(TexlBinding binding, DottedNameNode node, out DPath path)
        {
            Contracts.AssertValue(binding);
            Contracts.AssertValue(node);

            if (node.Left is DottedNameNode && TryConvertNodeToDPath(binding, node.Left as DottedNameNode, out path))
            {
                DName  rightNodeName = node.Right.Name;
                string possibleRename;
                if (binding.TryGetReplacedIdentName(node.Right, out possibleRename))
                {
                    rightNodeName = new DName(possibleRename);
                }

                path = path.Append(rightNodeName);
                return(true);
            }
            else if (node.Left is FirstNameNode firstName)
            {
                if (binding.GetInfo(firstName).Kind == BindKind.LambdaFullRecord)
                {
                    DName rightNodeName = node.Right.Name;
                    if (binding.TryGetReplacedIdentName(node.Right, out string rename))
                    {
                        rightNodeName = new DName(rename);
                    }

                    path = DPath.Root.Append(rightNodeName);
                    return(true);
                }

                // Check if the access was renamed:
                DName  leftNodeName = firstName.Ident.Name;
                string possibleRename;
                if (binding.TryGetReplacedIdentName(firstName.Ident, out possibleRename))
                {
                    leftNodeName = new DName(possibleRename);
                }

                path = DPath.Root.Append(leftNodeName).Append(node.Right.Name);
                return(true);
            }

            path = DPath.Root;
            return(false);
        }
Beispiel #2
0
            private DPath getReplacementPath(string alias, DPath currentColumnPath)
            {
                if (alias.Contains("/"))
                {
                    var fullPath = DPath.Root;

                    foreach (var name in alias.Split('/'))
                    {
                        fullPath = fullPath.Append(new DName(name));
                    }

                    return(fullPath);
                }
                else // Task 5593666: This is temporary to not cause regressions while sharepoint switches to using full query param
                {
                    return(currentColumnPath.Append(new DName(alias)));
                }
            }
Beispiel #3
0
        public DPath ToDPath()
        {
            Contracts.Assert(HasPossibleNamespaceQualifier);

            Stack <DName> names = new Stack <DName>(2);

            names.Push(Right.Name);

            // Traverse the DottedNameNode structure non-recursively, to account for the possibility
            // that it may be very deep. Accumulate all encountered names onto a stack.
            DottedNameNode pointer     = this;
            bool           reachedLeft = false;

            while (pointer != null)
            {
                TexlNode left = pointer.Left;

                switch (left)
                {
                case FirstNameNode firstNameNode:
                    names.Push(firstNameNode.Ident.Name);
                    reachedLeft = true;
                    break;

                case ParentNode parentNode:
                    names.Push(new DName(TexlLexer.KeywordParent));
                    reachedLeft = true;
                    break;

                case SelfNode selfNode:
                    names.Push(new DName(TexlLexer.KeywordSelf));
                    reachedLeft = true;
                    break;
                }

                if (reachedLeft)
                {
                    break;
                }

                pointer = left as DottedNameNode;
                if (pointer != null)
                {
                    names.Push(pointer.Right.Name);
                }
                else
                {
                    Contracts.Assert(false, "Can only do this for dotted names consisting of identifiers");
                }
            }

            // For the DPath by unwinding the names stack
            DPath path = DPath.Root;

            while (names.Count > 0)
            {
                path = path.Append(names.Pop());
            }

            return(path);
        }