Exemple #1
0
            public CurrentNodes(SyntaxNode root)
            {
                // there could be multiple nodes with same annotation if a tree is rewritten with
                // same node injected multiple times.
                var map = new SegmentedDictionary <SyntaxAnnotation, List <SyntaxNode> >();

                foreach (var node in root.GetAnnotatedNodesAndTokens(IdAnnotationKind).Select(n => n.AsNode() !))
                {
                    Debug.Assert(node is object);
                    foreach (var id in node.GetAnnotations(IdAnnotationKind))
                    {
                        List <SyntaxNode>?list;
                        if (!map.TryGetValue(id, out list))
                        {
                            list = new List <SyntaxNode>();
                            map.Add(id, list);
                        }

                        list.Add(node);
                    }
                }

                _idToNodeMap = map.ToImmutableSegmentedDictionary(kv => kv.Key, kv => (IReadOnlyList <SyntaxNode>)ImmutableArray.CreateRange(kv.Value));
            }