public void AddAnchorIndentationOperation(AnchorIndentationOperation operation) { // don't add stuff if it is empty if (operation.TextSpan.IsEmpty || _anchorMap.Contains(operation.TextSpan) || _anchorBaseTokenMap.ContainsKey(operation.AnchorToken)) { return; } // If the indentation changes on a line which other code is anchored to, adjust those other lines to reflect // the same change in indentation. Note that we anchor to the first token on a line to account for common // cases like the following code, where the `{` token is anchored to the `(` token of `()`: // // ↓ this space can be removed, which moves `(` one character to the left // var x = Method( () => // { // ↑ this `{` anchors to `var` instead of `(`, which prevents it from moving when `(` is moved // }); // // The calculation of true anchor token (which is always the first token on a line) is delayed to account // for cases where the original anchor token is moved to a new line during a formatting operation. var anchorToken = _tokenStream.FirstTokenOfBaseTokenLine(operation.AnchorToken); var originalSpace = _tokenStream.GetOriginalColumn(anchorToken); var data = new AnchorData(operation, anchorToken, originalSpace); _anchorTree.AddIntervalInPlace(data); _anchorBaseTokenMap.Add(operation.AnchorToken, data); _anchorMap.Add(operation.TextSpan); }
public void Dictionary_Generic_RemoveKey_ValidKeyContainedInDictionary(int count) { SegmentedDictionary <TKey, TValue> dictionary = (SegmentedDictionary <TKey, TValue>)GenericIDictionaryFactory(count); TKey missingKey = GetNewKey(dictionary); TValue outValue; TValue inValue = CreateTValue(count); dictionary.Add(missingKey, inValue); Assert.True(dictionary.Remove(missingKey, out outValue)); Assert.Equal(count, dictionary.Count); Assert.Equal(inValue, outValue); Assert.False(dictionary.TryGetValue(missingKey, out outValue)); }
public void Dictionary_Generic_ContainsValue_DefaultValuePresent(int count) { SegmentedDictionary <TKey, TValue> dictionary = (SegmentedDictionary <TKey, TValue>)GenericIDictionaryFactory(count); int seed = 4315; TKey notPresent = CreateTKey(seed++); while (dictionary.ContainsKey(notPresent)) { notPresent = CreateTKey(seed++); } dictionary.Add(notPresent, default(TValue)); Assert.True(dictionary.ContainsValue(default(TValue))); }
public void Dictionary_Generic_ContainsValue_Present(int count) { SegmentedDictionary <TKey, TValue> dictionary = (SegmentedDictionary <TKey, TValue>)GenericIDictionaryFactory(count); int seed = 4315; KeyValuePair <TKey, TValue> notPresent = CreateT(seed++); while (dictionary.Contains(notPresent)) { notPresent = CreateT(seed++); } dictionary.Add(notPresent.Key, notPresent.Value); Assert.True(dictionary.ContainsValue(notPresent.Value)); }
public void AddAnchorIndentationOperation(AnchorIndentationOperation operation) { // don't add stuff if it is empty if (operation.TextSpan.IsEmpty || _anchorMap.Contains(operation.TextSpan) || _anchorBaseTokenMap.ContainsKey(operation.AnchorToken)) { return; } var originalSpace = _tokenStream.GetOriginalColumn(operation.StartToken); var data = new AnchorData(operation, originalSpace); _anchorTree.AddIntervalInPlace(data); _anchorBaseTokenMap.Add(operation.AnchorToken, data); _anchorMap.Add(operation.TextSpan); }
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)); }