private static GreenNode CreateNode(SyntaxTrivia[] trivias) { if (trivias == null) { return(null); } var builder = new SyntaxTriviaListBuilder(trivias.Length); builder.Add(trivias); return(builder.ToList().Node); }
/// <summary> /// Creates a new <see cref="SyntaxTriviaList"/> with the specified trivia inserted at the index. /// </summary> /// <param name="index">The index in the list to insert the trivia at.</param> /// <param name="trivia">The trivia to insert.</param> public SyntaxTriviaList InsertRange(int index, IEnumerable <SyntaxTrivia> trivia) { int thisCount = this.Count; if (index < 0 || index > thisCount) { throw new ArgumentOutOfRangeException(nameof(index)); } if (trivia == null) { throw new ArgumentNullException(nameof(trivia)); } // Just return ourselves if we're not being asked to add anything. ICollection <SyntaxTrivia> triviaCollection = trivia as ICollection <SyntaxTrivia>; if (triviaCollection != null && triviaCollection.Count == 0) { return(this); } SyntaxTriviaListBuilder builder = GetBuilder(); try { for (int i = 0; i < index; i++) { builder.Add(this[i]); } builder.AddRange(trivia); for (int i = index; i < thisCount; i++) { builder.Add(this[i]); } return(builder.Count == thisCount ? this : builder.ToList()); } finally { ClearAndFreeBuilder(builder); } }
public override SyntaxToken VisitToken(SyntaxToken token) { SyntaxToken result = token; // only bother visiting trivia if we are removing a node in structured trivia if (this.VisitIntoStructuredTrivia) { result = base.VisitToken(token); } // the next token gets the accrued trivia. if (result.GetKind() != SyntaxKind.None && _residualTrivia != null && _residualTrivia.Count > 0) { _residualTrivia.Add(result.LeadingTrivia); result = result.WithLeadingTrivia(_residualTrivia.ToList()); _residualTrivia.Clear(); } return(result); }