private static GreenNode CreateNode(SyntaxToken[] tokens) { if (tokens == null) { return(null); } // TODO: we could remove the unnecessary builder allocations here and go directly // from the array to the List nodes. var builder = new SyntaxTokenListBuilder(tokens.Length); for (int i = 0; i < tokens.Length; i++) { builder.Add(tokens[i].Node); } return(builder.ToList().Node); }
/// <summary> /// Insert one or more tokens in the list at the specified index. /// </summary> /// <returns>A new list with the tokens inserted.</returns> public static SyntaxTokenList Insert(this SyntaxTokenList list, int index, params SyntaxToken[] items) { if (index < 0 || index > list.Count) { throw new ArgumentOutOfRangeException(nameof(index)); } if (items == null) { throw new ArgumentNullException(nameof(items)); } if (items.Length == 0) { return(list); } if (list.Count == 0) { var first = (Syntax.InternalSyntax.InternalSyntaxToken)items[0].Node; return(first.Language.SyntaxFactory.TokenList(items)); } else { var builder = new SyntaxTokenListBuilder(list.Count + items.Length); if (index > 0) { builder.Add(list, 0, index); } builder.Add(items); if (index < list.Count) { builder.Add(list, index, list.Count - index); } return(builder.ToList()); } }