public XmlElementSyntax(XmlElementStartTagSyntax start, SyntaxNode content, XmlElementEndTagSyntax end) : base(SyntaxKind.XmlElement)
 {
     StartTag = start;
     Content = content;
     EndTag = end;
     SlotCount = 3;
 }
 public XmlElementSyntaxBase(
     SyntaxKind syntaxKind,
     XmlNameSyntax name,
     SyntaxNode attributes)
     : base(syntaxKind)
 {
     this.NameNode = name;
     this.AttributesNode = attributes;
 }
        public virtual SyntaxNode Visit(SyntaxNode node)
        {
            if (node != null)
            {
                return node.Accept(this);
            }

            return null;
        }
 /*  <summary>
 ''' Represents the start tag of an XML element of the form &lt;element&gt;.
 ''' </summary> */
 public static XmlElementStartTagSyntax XmlElementStartTag(
     PunctuationSyntax lessThanToken,
     XmlNameSyntax name,
     SyntaxNode attributes,
     PunctuationSyntax greaterThanToken)
 {
     Debug.Assert(lessThanToken != null && lessThanToken.Kind == SyntaxKind.LessThanToken);
     Debug.Assert(name != null);
     Debug.Assert(greaterThanToken != null && greaterThanToken.Kind == SyntaxKind.GreaterThanToken);
     return new XmlElementStartTagSyntax(SyntaxKind.XmlElementStartTag, lessThanToken, name, attributes, greaterThanToken);
 }
 public XmlEmptyElementSyntax(
     PunctuationSyntax lessThanToken,
     XmlNameSyntax name,
     SyntaxNode attributes,
     PunctuationSyntax slashGreaterThanToken) : base(SyntaxKind.XmlEmptyElement)
 {
     this.LessThanToken = lessThanToken;
     this.NameNode = name;
     this.AttributesNode = attributes;
     this.SlashGreaterThanToken = slashGreaterThanToken;
     this.SlotCount = 4;
 }
        internal static SyntaxList List(SyntaxNode[] nodes, int count)
        {
            var array = new ArrayElement<SyntaxNode>[count];
            Debug.Assert(array.Length == count);
            for (var i = 0; i < count; i++)
            {
                array[i].Value = nodes[i];
                Debug.Assert(array[i].Value != null);
            }

            return List(array);
        }
 public XmlElementStartTagSyntax(
     SyntaxKind kind,
     PunctuationSyntax lessThanToken,
     XmlNameSyntax name,
     SyntaxNode attributes,
     PunctuationSyntax greaterThanToken)
     : base(kind)
 {
     this.LessThanToken = lessThanToken;
     this.NameNode = name;
     this.Attributes = attributes;
     this.GreaterThanToken = greaterThanToken;
     SlotCount = 4;
 }
 public XmlDocumentSyntax(
     SyntaxKind kind,
     XmlDeclarationSyntax prologue,
     SyntaxNode precedingMisc,
     XmlNodeSyntax body,
     SyntaxNode followingMisc,
     SyntaxToken eof) : base(kind)
 {
     this.Prologue = prologue;
     this.PrecedingMisc = precedingMisc;
     this.Body = body;
     this.FollowingMisc = followingMisc;
     this.Eof = eof;
     SlotCount = 5;
 }
 private static bool ShouldCacheTriviaInfo(SyntaxNode leadingTrivia, SyntaxNode trailingTrivia)
 {
     Debug.Assert(leadingTrivia != null);
     if (trailingTrivia == null)
     {
         return false;
     }
     else
     {
         return leadingTrivia.Kind == SyntaxKind.WhitespaceTrivia &&
             trailingTrivia.Kind == SyntaxKind.WhitespaceTrivia &&
             trailingTrivia.FullWidth == 1 &&
             trailingTrivia.ToFullString() == " " &&
             leadingTrivia.FullWidth <= maximumCachedTriviaWidth;
     }
 }
        internal static SyntaxNode Concat(SyntaxNode left, SyntaxNode right)
        {
            if ((left == null))
            {
                return right;
            }

            if ((right == null))
            {
                return left;
            }

            ArrayElement<SyntaxNode>[] tmp;
            SyntaxList leftList = (left as SyntaxList);
            SyntaxList rightList = (right as SyntaxList);
            if (leftList != null)
            {
                if (rightList != null)
                {
                    tmp = new ArrayElement<SyntaxNode>[left.SlotCount + right.SlotCount];
                    leftList.CopyTo(tmp, 0);
                    rightList.CopyTo(tmp, left.SlotCount);
                    return SyntaxList.List(tmp);
                }

                tmp = new ArrayElement<SyntaxNode>[(left.SlotCount + 1)];
                leftList.CopyTo(tmp, 0);
                tmp[left.SlotCount].Value = right;
                return SyntaxList.List(tmp);
            }

            if (rightList != null)
            {
                tmp = new ArrayElement<SyntaxNode>[(rightList.SlotCount + 1)];
                tmp[0].Value = left;
                rightList.CopyTo(tmp, 1);
                return SyntaxList.List(tmp);
            }

            return SyntaxList.List(left, right);
        }
 public XmlTextSyntax(SyntaxKind kind, SyntaxNode textTokens) : base(kind)
 {
     this.TextTokens = textTokens;
     this.SlotCount = 1;
 }
 public static SyntaxToken Token(SyntaxNode leadingTrivia, SyntaxKind kind, SyntaxNode trailingTrivia, string text)
 {
     return new PunctuationSyntax(kind, text, leadingTrivia, trailingTrivia);
 }
        private static int VisitChildren(
            SyntaxNode syntaxNode,
            int windowStart,
            int windowLength,
            Action<int, int, SyntaxNode, XmlClassificationTypes> resultCollector,
            int start,
            XmlClassificationTypes[] childTypes)
        {
            int visitedCount = 0;
            int windowEnd = windowStart + windowLength;
            var targetOffset = windowStart - start;

            int offset;
            int index;
            syntaxNode.GetIndexAndOffset(targetOffset, out index, out offset);
            start += offset;

            for (int i = index; i < syntaxNode.SlotCount; i++)
            {
                if (start > windowEnd)
                {
                    break;
                }

                var child = syntaxNode.GetSlot(i);
                visitedCount++;
                if (child == null)
                {
                    continue;
                }

                var currentStart = Math.Max(start, windowStart);
                var currentLength = Math.Min(windowEnd, start + child.FullWidth) - currentStart;
                if (currentLength >= 0)
                {
                    var childType = childTypes == null ? XmlClassificationTypes.None : childTypes[i];

                    if (childType == XmlClassificationTypes.None)
                    {
                        if (child.Kind == SyntaxKind.XmlTextLiteralToken)
                        {
                            childType = XmlClassificationTypes.XmlText;
                        }
                        else if (child.Kind == SyntaxKind.XmlEntityLiteralToken)
                        {
                            childType = XmlClassificationTypes.XmlEntityReference;
                        }
                    }

                    if (childType == XmlClassificationTypes.None)
                    {
                        visitedCount += Visit(child, windowStart, windowLength, resultCollector, start);
                    }
                    else
                    {
                        if (currentLength > 0)
                        {
                            resultCollector(currentStart, currentLength, child, childType);
                        }
                    }
                }

                start += child.FullWidth;
            }

            return visitedCount;
        }
        public static int Visit(
            SyntaxNode node,
            int windowStart,
            int windowLength,
            Action<int, int, SyntaxNode, XmlClassificationTypes>
            resultCollector,
            int start = 0)
        {
            if (node == null)
            {
                return 0;
            }

            XmlClassificationTypes[] childTypes = null;
            kindMap.TryGetValue(node.Kind, out childTypes);
            return VisitChildren(node, windowStart, windowLength, resultCollector, start, childTypes);
        }
 // Add a trivia to the triva we are accumulating.
 private void AddTrivia(SyntaxNode trivia)
 {
     FinishInProgressTokens();
     triviaListBuilder.AddRange(trivia);
 }
 internal static XmlTextTokenSyntax XmlTextLiteralToken(string text, string value, SyntaxNode leadingTrivia, SyntaxNode trailingTrivia)
 {
     return new XmlTextTokenSyntax(SyntaxKind.XmlTextLiteralToken, text, leadingTrivia, trailingTrivia, value);
 }
 /*  <summary>
   ''' Represents character data in Xml content also known as PCData or in an Xml
   ''' attribute value. All text is here for now even text that does not need
   ''' normalization such as comment, pi and cdata text.
   ''' </summary>
   ''' <param name="text">
   ''' The actual text of this token.
   ''' </param>
 */
 internal static XmlTextTokenSyntax XmlEntityLiteralToken(string text, string value, SyntaxNode leadingTrivia, SyntaxNode trailingTrivia)
 {
     Debug.Assert(text != null);
     return new XmlTextTokenSyntax(SyntaxKind.XmlEntityLiteralToken, text, leadingTrivia, trailingTrivia, value);
 }
 public static XmlNameTokenSyntax XmlNameToken(string text, SyntaxNode precedingTrivia, SyntaxNode followingTrivia)
 {
     return new XmlNameTokenSyntax(text, precedingTrivia, followingTrivia);
 }
        private void AddDescendants(SyntaxNode node, List<IXmlElement> resultList)
        {
            if (node is IXmlElement)
            {
                resultList.Add((IXmlElement)this);
            }

            foreach (var child in node.ChildNodes)
            {
                AddDescendants(child, resultList);
            }
        }
 public virtual SyntaxNode WithTrailingTrivia(SyntaxNode trivia)
 {
     return this;
 }
 internal WithTwoChildren(SyntaxNode child0, SyntaxNode child1) : base()
 {
     base.SlotCount = 2;
     this._child0 = child0;
     this._child1 = child1;
 }
 internal static WithThreeChildren List(SyntaxNode child0, SyntaxNode child1, SyntaxNode child2)
 {
     var result = new WithThreeChildren(child0, child1, child2);
     return result;
 }
 internal static WithTwoChildren List(SyntaxNode child0, SyntaxNode child1)
 {
     var result = new WithTwoChildren(child0, child1);
     return result;
 }
 internal WithThreeChildren(SyntaxNode child0, SyntaxNode child1, SyntaxNode child2) : base()
 {
     base.SlotCount = 3;
     this._child0 = child0;
     this._child1 = child1;
     this._child2 = child2;
 }
 internal static SyntaxNode List(SyntaxNode child)
 {
     return child;
 }
 protected virtual void AdjustWidth(SyntaxNode node)
 {
     this.fullWidth = FullWidth + node.FullWidth;
 }
 public virtual SyntaxNode VisitSyntaxNode(SyntaxNode node)
 {
     return node;
 }
 internal static SyntaxList List(SyntaxNode[] nodes)
 {
     return List(nodes, nodes.Length);
 }
 public static PunctuationSyntax MissingPunctuation(SyntaxKind kind, SyntaxNode leadingTrivia = null)
 {
     return new PunctuationSyntax(kind, "", leadingTrivia, null);
 }
Esempio n. 30
0
 private XmlNameTokenSyntax XmlMakeXmlNCNameToken(SyntaxNode precedingTrivia, int tokenWidth)
 {
     Debug.Assert(tokenWidth > 0);
     var text = GetText(tokenWidth);
     var followingTrivia = ScanXmlWhitespace();
     return SyntaxFactory.XmlNameToken(text, precedingTrivia, followingTrivia);
 }
Esempio n. 31
0
 public SyntaxListBuilder Add(SyntaxNode item)
 {
     EnsureAdditionalCapacity(1);
     return(this.AddUnsafe(item));
 }