internal static TSyntax AddLeadingTrivia <TSyntax>(this TSyntax node, InternalSyntax.SyntaxList <GreenNode> trivia) where TSyntax : GreenNode { if (node == null) { throw new ArgumentNullException("node"); } if (!trivia.Any()) { return(node); } var tk = (node as SyntaxToken.Green); 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.Green.AddLeadingTrivia(tk, leadingTrivia).AddTrailingTrivia(trailingTrivia); } else { tk = SyntaxToken.Green.AddLeadingTrivia(tk, trivia); } result = ((TSyntax)((object)tk)); } else { result = FirstTokenReplacer.Replace(node, t => SyntaxToken.Green.AddLeadingTrivia(t, trivia)); } return(result); }
internal static InternalSyntax.SyntaxList <GreenNode> GetEndOfTrivia(this InternalSyntax.SyntaxList <GreenNode> trivia) { return(trivia.GetEndOfTrivia(trivia.GetIndexOfEndOfTrivia())); }