// Local functions static void ProcessWildcardName(NameParts parts, PooledDictionary <SymbolKind, PooledDictionary <string, TValue> > wildcardNamesBuilder) { Debug.Assert(parts.SymbolName[parts.SymbolName.Length - 1] == WildcardChar); Debug.Assert(parts.SymbolName.Length >= 2); if (parts.SymbolName[1] != ':') { if (!wildcardNamesBuilder.ContainsKey(AllKinds)) { wildcardNamesBuilder.Add(AllKinds, PooledDictionary <string, TValue> .GetInstance()); } wildcardNamesBuilder[AllKinds].Add(parts.SymbolName.Substring(0, parts.SymbolName.Length - 1), parts.AssociatedValue); return; } var symbolKind = parts.SymbolName[0] switch { 'E' => (SymbolKind?)SymbolKind.Event, 'F' => SymbolKind.Field, 'M' => SymbolKind.Method, 'N' => SymbolKind.Namespace, 'P' => SymbolKind.Property, 'T' => SymbolKind.NamedType, _ => null, }; if (symbolKind != null) { if (!wildcardNamesBuilder.ContainsKey(symbolKind.Value)) { wildcardNamesBuilder.Add(symbolKind.Value, PooledDictionary <string, TValue> .GetInstance()); } wildcardNamesBuilder[symbolKind.Value].Add(parts.SymbolName.Substring(2, parts.SymbolName.Length - 3), parts.AssociatedValue); } }
public override BoundNode VisitGotoStatement(BoundGotoStatement node) { _labelsUsed.Add(node.Label); // check for illegal jumps across using declarations var sourceLocation = node.Syntax.Location; var sourceStart = sourceLocation.SourceSpan.Start; var targetStart = node.Label.Locations[0].SourceSpan.Start; foreach (var usingDecl in _usingDeclarations) { var usingStart = usingDecl.symbol.Locations[0].SourceSpan.Start; if (sourceStart < usingStart && targetStart > usingStart) { // No forward jumps Diagnostics.Add(ErrorCode.ERR_GoToForwardJumpOverUsingVar, sourceLocation); break; } else if (sourceStart > usingStart && targetStart < usingStart) { // Backwards jump, so we must have already seen the label Debug.Assert(_labelsDefined.ContainsKey(node.Label)); // Error if label and using are part of the same block if (_labelsDefined[node.Label] == usingDecl.block) { Diagnostics.Add(ErrorCode.ERR_GoToBackwardJumpOverUsingVar, sourceLocation); break; } } } return(base.VisitGotoStatement(node)); }
static void ProcessName(NameParts parts, PooledDictionary <string, TValue> namesBuilder) { if (!namesBuilder.ContainsKey(parts.SymbolName)) { namesBuilder.Add(parts.SymbolName, parts.AssociatedValue); } }
public void TestClear() { using var dict = new PooledDictionary <string, string>(); dict["one"] = "One"; dict.Clear(); Assert.False(dict.ContainsKey("one")); }
/// <summary> /// Try setting a user-declared variable (given by its accessing expression) to be /// used for a pattern-matching temporary variable. Returns true when not already /// assigned. The return value of this method is typically ignored by the caller as /// once we have made an assignment we can keep it (we keep the first assignment we /// find), but we return a success bool to emphasize that the assignment is not unconditional. /// </summary> public bool TrySetTemp(BoundDagTemp dagTemp, BoundExpression translation) { if (!_map.ContainsKey(dagTemp)) { _map.Add(dagTemp, translation); return(true); } return(false); }
static void AddPlatformsFromMsBuildOptions(PooledDictionary <string, int> knownPlatforms, ImmutableArray <string> msBuildPlatforms) { foreach (var platform in msBuildPlatforms) { if (!knownPlatforms.ContainsKey(platform)) { knownPlatforms.Add(platform, 4); // Default version count is 4 } } }
static void ProcessSymbolName(NameParts parts, Compilation compilation, string?optionalPrefix, PooledDictionary <ISymbol, TValue> symbolsBuilder) { var nameWithPrefix = (string.IsNullOrEmpty(optionalPrefix) || parts.SymbolName.StartsWith(optionalPrefix, StringComparison.Ordinal)) ? parts.SymbolName : optionalPrefix + parts.SymbolName; #pragma warning disable CA1307 // Specify StringComparison - https://github.com/dotnet/roslyn-analyzers/issues/1552 // Documentation comment ID for constructors uses '#ctor', but '#' is a comment start token for editorconfig. // We instead search for a '..ctor' in editorconfig and replace it with a '.#ctor' here. // Similarly, handle static constructors ".cctor" nameWithPrefix = nameWithPrefix.Replace("..ctor", ".#ctor"); nameWithPrefix = nameWithPrefix.Replace("..cctor", ".#cctor"); #pragma warning restore foreach (var symbol in DocumentationCommentId.GetSymbolsForDeclarationId(nameWithPrefix, compilation)) { if (symbol == null) { continue; } if (symbol is INamespaceSymbol namespaceSymbol && namespaceSymbol.ConstituentNamespaces.Length > 1) { foreach (var constituentNamespace in namespaceSymbol.ConstituentNamespaces) { if (!symbolsBuilder.ContainsKey(constituentNamespace)) { symbolsBuilder.Add(constituentNamespace, parts.AssociatedValue); } } } if (!symbolsBuilder.ContainsKey(symbol)) { symbolsBuilder.Add(symbol, parts.AssociatedValue); } } }
public void TestReplace() { using var dict = new PooledDictionary <string, string>(); dict["one"] = "One"; dict["one"] = "Two"; Assert.True(dict.ContainsKey("one")); #pragma warning disable xUnit2017 Assert.True(dict.Contains(new KeyValuePair <string, string>("one", "Two"))); #pragma warning restore Assert.Equal("Two", dict["one"]); }
public bool ContainsKey(TKey key) { Debug.Assert(!IsDisposed); return(_coreAnalysisData.ContainsKey(key)); }
public bool Contains(string hintName) => _sourcesAdded.ContainsKey(hintName);