private void AddResidualTrivia(SyntaxTriviaList trivia, bool requiresNewLine = false) { if (requiresNewLine) { this.AddEndOfLine(GetEndOfLine(trivia) ?? SyntaxFactory.CarriageReturnLineFeed); } _residualTrivia.Add(trivia); }
public virtual SyntaxTriviaList VisitList(SyntaxTriviaList list) { var count = list.Count; if (count != 0) { SyntaxTriviaListBuilder alternate = null; var index = -1; foreach (var item in list) { index++; var visited = this.VisitListElement(item); //skip the null check since SyntaxTrivia is a value type if (visited != item && alternate == null) { alternate = new SyntaxTriviaListBuilder(count); alternate.Add(list, 0, index); } if (alternate != null && visited.CSharpKind() != SyntaxKind.None) { alternate.Add(visited); } } if (alternate != null) { return(alternate.ToList()); } } return(list); }
/// <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); } }
private static GreenNode CreateNode(SyntaxTrivia[] trivias) { if (trivias == null) { return(null); } var builder = new SyntaxTriviaListBuilder(trivias.Length); builder.Add(trivias); return(builder.ToList().Node); }