コード例 #1
0
        internal static TSyntax AddLeadingTrivia <TSyntax>(this TSyntax node, SyntaxList <SyntaxNode> trivia) where TSyntax : SyntaxNode
        {
            if (node == null)
            {
                throw new ArgumentNullException("node");
            }

            if (!trivia.Any())
            {
                return(node);
            }

            var     tk = (node as SyntaxToken);
            TSyntax result;

            if (tk != null)
            {
                // Cannot add unexpected tokens as leading trivia on a missing token since
                // if the unexpected tokens end with a statement terminator, the missing
                // token would follow the statement terminator. That would result in an
                // incorrect syntax tree and if this missing token is the end of an expression,
                // and the expression represents a transition between VB and XML, the
                // terminator will be overlooked (see ParseXmlEmbedded for instance).
                if (IsMissingToken(tk))
                {
                    var leadingTrivia  = trivia.GetStartOfTrivia();
                    var trailingTrivia = trivia.GetEndOfTrivia();
                    tk = SyntaxToken.AddLeadingTrivia(tk, leadingTrivia).AddTrailingTrivia(trailingTrivia);
                }
                else
                {
                    tk = SyntaxToken.AddLeadingTrivia(tk, trivia);
                }

                result = ((TSyntax)((object)tk));
            }
            else
            {
                result = FirstTokenReplacer.Replace(node, t => SyntaxToken.AddLeadingTrivia(t, trivia));
            }

            return(result);
        }
コード例 #2
0
 internal static SyntaxList <SyntaxNode> GetEndOfTrivia(this SyntaxList <SyntaxNode> trivia)
 {
     return(trivia.GetEndOfTrivia(trivia.GetIndexOfEndOfTrivia()));
 }