// deal with separated lists and removal of associated separators public override SeparatedSyntaxList <TNode> VisitList <TNode>(SeparatedSyntaxList <TNode> list) { var withSeps = list.GetWithSeparators(); bool removeNextSeparator = false; SyntaxNodeOrTokenListBuilder alternate = null; for (int i = 0, n = withSeps.Count; i < n; i++) { var item = withSeps[i]; SyntaxNodeOrToken visited; if (item.IsToken) // separator { if (removeNextSeparator) { removeNextSeparator = false; visited = default(SyntaxNodeOrToken); } else { visited = this.VisitListSeparator(item.AsToken()); } } else { var node = (TNode)(SyntaxNode)item.AsNode(); if (this.IsForRemoval(node)) { if (alternate == null) { alternate = new SyntaxNodeOrTokenListBuilder(n); alternate.Add(withSeps, 0, i); } if (alternate.Count > 0 && alternate[alternate.Count - 1].IsToken) { // remove preceding separator if any var separator = alternate[alternate.Count - 1].AsToken(); this.AddTrivia(separator, node); alternate.RemoveLast(); } else if (i + 1 < n && withSeps[i + 1].IsToken) { // otherwise remove following separator if any var separator = withSeps[i + 1].AsToken(); this.AddTrivia(node, separator); removeNextSeparator = true; } else { this.AddTrivia(node); } visited = default(SyntaxNodeOrToken); } else { visited = this.VisitListElement((TNode)(SyntaxNode)item.AsNode()); } } if (item != visited && alternate == null) { alternate = new SyntaxNodeOrTokenListBuilder(n); alternate.Add(withSeps, 0, i); } if (alternate != null && visited.Kind() != SyntaxKind.None) { alternate.Add(visited); } } if (alternate != null) { return(alternate.ToList().AsSeparatedList <TNode>()); } return(list); }
// deal with separated lists and removal of associated separators public override SeparatedSyntaxList <TNode> VisitList <TNode>( SeparatedSyntaxList <TNode> list ) { var withSeps = list.GetWithSeparators(); bool removeNextSeparator = false; SyntaxNodeOrTokenListBuilder?alternate = null; for (int i = 0, n = withSeps.Count; i < n; i++) { var item = withSeps[i]; SyntaxNodeOrToken visited; if (item.IsToken) // separator { if (removeNextSeparator) { removeNextSeparator = false; visited = default(SyntaxNodeOrToken); } else { visited = this.VisitListSeparator(item.AsToken()); } } else { var node = (TNode)item.AsNode() !; if (this.IsForRemoval(node)) { if (alternate == null) { alternate = new SyntaxNodeOrTokenListBuilder(n); alternate.Add(withSeps, 0, i); } CommonSyntaxNodeRemover.GetSeparatorInfo( withSeps, i, (int)SyntaxKind.EndOfLineTrivia, out bool nextTokenIsSeparator, out bool nextSeparatorBelongsToNode ); if ( !nextSeparatorBelongsToNode && alternate.Count > 0 && alternate[alternate.Count - 1].IsToken ) { var separator = alternate[alternate.Count - 1].AsToken(); this.AddTrivia(separator, node); alternate.RemoveLast(); } else if (nextTokenIsSeparator) { var separator = withSeps[i + 1].AsToken(); this.AddTrivia(node, separator); removeNextSeparator = true; } else { this.AddTrivia(node); } visited = default; } else { visited = this.VisitListElement(node); } } if (item != visited && alternate == null) { alternate = new SyntaxNodeOrTokenListBuilder(n); alternate.Add(withSeps, 0, i); } if (alternate != null && visited.Kind() != SyntaxKind.None) { alternate.Add(visited); } } if (alternate != null) { return(alternate.ToList().AsSeparatedList <TNode>()); } return(list); }