提交 4d46f050 编写于 作者: J Jared Parsons

PR feedback

上级 35a265cd
......@@ -38,7 +38,8 @@ internal sealed class SmallDictionary<K, V> : IEnumerable<KeyValuePair<K, V>>
private AvlNode? _root;
public readonly IEqualityComparer<K> Comparer;
public static readonly SmallDictionary<K, V> Empty = new SmallDictionary<K, V>(EqualityComparer<K>.Default);
// https://github.com/dotnet/roslyn/issues/40344
public static readonly SmallDictionary<K, V> Empty = new SmallDictionary<K, V>(null!);
public SmallDictionary() : this(EqualityComparer<K>.Default) { }
......@@ -71,7 +72,7 @@ public bool TryGetValue(K key, [MaybeNullWhen(returnValue: false)] out V value)
{
if (_root != null)
{
return TryGetValue(GetHashCode(key), key, out value);
return TryGetValue(GetHashCode(key), key, out value!);
}
value = default!;
......@@ -88,7 +89,7 @@ public void Add(K key, V value)
get
{
V value;
if (!TryGetValue(key, out value))
if (!TryGetValue(key, out value!))
{
throw new KeyNotFoundException($"Could not find key {key}");
}
......@@ -105,7 +106,7 @@ public void Add(K key, V value)
public bool ContainsKey(K key)
{
V value;
return TryGetValue(key, out value);
return TryGetValue(key, out value!);
}
[Conditional("DEBUG")]
......@@ -228,7 +229,7 @@ private bool TryGetValue(int hashCode, K key, [MaybeNullWhen(returnValue: false)
return true;
}
return GetFromList(b.Next, key, out value);
return GetFromList(b.Next, key, out value!);
}
private bool GetFromList(Node? next, K key, [MaybeNullWhen(returnValue: false)] out V value)
......@@ -527,7 +528,7 @@ public Enumerator(SmallDictionary<K, V> dict)
// left == right only if both are nulls
if (root.Left == root.Right)
{
_next = dict._root;
_next = root;
}
else
{
......@@ -645,7 +646,7 @@ public Enumerator(SmallDictionary<K, V> dict)
// left == right only if both are nulls
if (root.Left == root.Right)
{
_next = dict._root;
_next = root;
}
else
{
......
......@@ -31,7 +31,7 @@ internal enum ConstantValueTypeDiscriminator : byte
DateTime,
}
internal abstract partial class ConstantValue : IEquatable<ConstantValue>
internal abstract partial class ConstantValue : IEquatable<ConstantValue?>
{
public abstract ConstantValueTypeDiscriminator Discriminator { get; }
internal abstract SpecialType SpecialType { get; }
......
......@@ -40,10 +40,10 @@ public override string Id
get { return Descriptor.Id; }
}
public override string? GetMessage(IFormatProvider? formatProvider = null)
public override string GetMessage(IFormatProvider? formatProvider = null)
=> _originalUnsuppressedDiagnostic.GetMessage(formatProvider);
internal override IReadOnlyList<object>? Arguments
internal override IReadOnlyList<object?>? Arguments
{
get { return _originalUnsuppressedDiagnostic.Arguments; }
}
......
......@@ -36,7 +36,7 @@ public abstract partial class Diagnostic : IEquatable<Diagnostic?>, IFormattable
public static Diagnostic Create(
DiagnosticDescriptor descriptor,
Location location,
params object[] messageArgs)
params object?[] messageArgs)
{
return Create(descriptor, location, null, null, messageArgs);
}
......@@ -57,7 +57,7 @@ public abstract partial class Diagnostic : IEquatable<Diagnostic?>, IFormattable
DiagnosticDescriptor descriptor,
Location location,
ImmutableDictionary<string, string>? properties,
params object[]? messageArgs)
params object?[] messageArgs)
{
return Create(descriptor, location, null, properties, messageArgs);
}
......@@ -78,7 +78,7 @@ public abstract partial class Diagnostic : IEquatable<Diagnostic?>, IFormattable
DiagnosticDescriptor descriptor,
Location location,
IEnumerable<Location>? additionalLocations,
params object[]? messageArgs)
params object?[] messageArgs)
{
return Create(descriptor, location, additionalLocations, properties: null, messageArgs: messageArgs);
}
......@@ -105,7 +105,7 @@ public abstract partial class Diagnostic : IEquatable<Diagnostic?>, IFormattable
Location location,
IEnumerable<Location>? additionalLocations,
ImmutableDictionary<string, string>? properties,
params object[]? messageArgs)
params object?[] messageArgs)
{
return Create(descriptor, location, effectiveSeverity: descriptor.DefaultSeverity, additionalLocations, properties, messageArgs);
}
......@@ -134,7 +134,7 @@ public abstract partial class Diagnostic : IEquatable<Diagnostic?>, IFormattable
DiagnosticSeverity effectiveSeverity,
IEnumerable<Location>? additionalLocations,
ImmutableDictionary<string, string>? properties,
params object[]? messageArgs)
params object?[] messageArgs)
{
if (descriptor == null)
{
......@@ -300,7 +300,7 @@ internal static Diagnostic Create(DiagnosticInfo info)
/// <summary>
/// Get the culture specific text of the message.
/// </summary>
public abstract string? GetMessage(IFormatProvider? formatProvider = null);
public abstract string GetMessage(IFormatProvider? formatProvider = null);
/// <summary>
/// Gets the default <see cref="DiagnosticSeverity"/> of the diagnostic's <see cref="DiagnosticDescriptor"/>.
......@@ -466,9 +466,9 @@ internal Diagnostic WithProgrammaticSuppression(ProgrammaticSuppressionInfo prog
// compatibility
internal virtual int Code { get { return 0; } }
internal virtual IReadOnlyList<object>? Arguments
internal virtual IReadOnlyList<object?>? Arguments
{
get { return SpecializedCollections.EmptyReadOnlyList<object>(); }
get { return SpecializedCollections.EmptyReadOnlyList<object?>(); }
}
/// <summary>
......
......@@ -23,7 +23,7 @@ internal sealed class SimpleDiagnostic : Diagnostic
private readonly int _warningLevel;
private readonly Location _location;
private readonly IReadOnlyList<Location> _additionalLocations;
private readonly object[] _messageArgs;
private readonly object?[] _messageArgs;
private readonly ImmutableDictionary<string, string> _properties;
private readonly bool _isSuppressed;
......@@ -33,7 +33,7 @@ internal sealed class SimpleDiagnostic : Diagnostic
int warningLevel,
Location location,
IEnumerable<Location>? additionalLocations,
object[]? messageArgs,
object?[]? messageArgs,
ImmutableDictionary<string, string>? properties,
bool isSuppressed)
{
......@@ -48,7 +48,7 @@ internal sealed class SimpleDiagnostic : Diagnostic
_warningLevel = warningLevel;
_location = location ?? Location.None;
_additionalLocations = additionalLocations?.ToImmutableArray() ?? SpecializedCollections.EmptyReadOnlyList<Location>();
_messageArgs = messageArgs ?? Array.Empty<object>();
_messageArgs = messageArgs ?? Array.Empty<object?>();
_properties = properties ?? ImmutableDictionary<string, string>.Empty;
_isSuppressed = isSuppressed;
}
......@@ -59,7 +59,7 @@ internal sealed class SimpleDiagnostic : Diagnostic
int warningLevel,
Location location,
IEnumerable<Location>? additionalLocations,
object[]? messageArgs,
object?[]? messageArgs,
ImmutableDictionary<string, string>? properties,
bool isSuppressed = false)
{
......@@ -87,7 +87,7 @@ public override string Id
get { return _descriptor.Id; }
}
public override string? GetMessage(IFormatProvider? formatProvider = null)
public override string GetMessage(IFormatProvider? formatProvider = null)
{
if (_messageArgs.Length == 0)
{
......@@ -107,7 +107,7 @@ public override string Id
}
}
internal override IReadOnlyList<object> Arguments
internal override IReadOnlyList<object?> Arguments
{
get { return _messageArgs; }
}
......
......@@ -11,7 +11,7 @@ namespace Microsoft.CodeAnalysis
/// <summary>
/// A program location in source code.
/// </summary>
internal sealed class ExternalFileLocation : Location, IEquatable<ExternalFileLocation>
internal sealed class ExternalFileLocation : Location, IEquatable<ExternalFileLocation?>
{
private readonly TextSpan _sourceSpan;
private readonly FileLinePositionSpan _lineSpan;
......
......@@ -21,7 +21,7 @@ public abstract partial class LocalizableString : IFormattable, IEquatable<Local
/// <summary>
/// Formats the value of the current instance using the optionally specified format.
/// </summary>
public string? ToString(IFormatProvider? formatProvider)
public string ToString(IFormatProvider? formatProvider)
{
try
{
......@@ -90,7 +90,7 @@ public bool Equals(LocalizableString? other)
/// Provides the implementation of ToString. ToString will provide a default value
/// if this method throws an exception.
/// </summary>
protected abstract string? GetText(IFormatProvider? formatProvider);
protected abstract string GetText(IFormatProvider? formatProvider);
/// <summary>
/// Provides the implementation of GetHashCode. GetHashCode will provide a default value
......
......@@ -113,8 +113,7 @@ public void Free()
#endregion // Poolable
[return: MaybeNull]
internal T FindItem(char[] chars, int start, int len, int hashCode)
internal T? FindItem(char[] chars, int start, int len, int hashCode)
{
// get direct element reference to avoid extra range checks
ref var localSlot = ref _localTable[LocalIdxFromHash(hashCode)];
......
......@@ -111,7 +111,7 @@ private void DoDumpCompact(TreeDumperNode node, string indent)
public static string DumpXML(TreeDumperNode root, string? indent = null)
{
var dumper = new TreeDumper();
dumper.DoDumpXML(root, string.Empty, string.IsNullOrEmpty(indent) ? string.Empty : indent!);
dumper.DoDumpXML(root, string.Empty, indent ?? string.Empty);
return dumper._sb.ToString();
}
......@@ -216,7 +216,7 @@ public TreeDumperNode(string text, object? value, IEnumerable<TreeDumperNode>? c
public TreeDumperNode(string text) : this(text, null, null) { }
public object? Value { get; }
public string? Text { get; }
public string Text { get; }
public IEnumerable<TreeDumperNode> Children { get; }
public TreeDumperNode this[string child]
{
......
......@@ -346,7 +346,7 @@ internal async Task<ImmutableArray<ActiveStatementExceptionRegions>> GetBaseActi
case CommittedSolution.DocumentState.OutOfSync:
var descriptor = EditAndContinueDiagnosticDescriptors.GetDescriptor(EditAndContinueErrorCode.DocumentIsOutOfSyncWithDebuggee);
outOfSyncDiagnostics.Add(Diagnostic.Create(descriptor, Location.Create(document.FilePath!, textSpan: default, lineSpan: default), new[] { document.FilePath! }));
outOfSyncDiagnostics.Add(Diagnostic.Create(descriptor, Location.Create(document.FilePath!, textSpan: default, lineSpan: default), new[] { document.FilePath }));
continue;
default:
......
......@@ -3,22 +3,29 @@
#nullable enable
using System.Threading;
using Roslyn.Utilities;
namespace Microsoft.CodeAnalysis.Shared.Extensions
{
internal static class LocationExtensions
{
public static SyntaxTree GetSourceTreeOrThrow(this Location location)
{
Contract.ThrowIfNull(location.SourceTree);
return location.SourceTree;
}
public static SyntaxToken FindToken(this Location location, CancellationToken cancellationToken)
=> location.SourceTree!.GetRoot(cancellationToken).FindToken(location.SourceSpan.Start);
=> location.GetSourceTreeOrThrow().GetRoot(cancellationToken).FindToken(location.SourceSpan.Start);
public static SyntaxNode FindNode(this Location location, CancellationToken cancellationToken)
=> location.SourceTree!.GetRoot(cancellationToken).FindNode(location.SourceSpan);
=> location.GetSourceTreeOrThrow().GetRoot(cancellationToken).FindNode(location.SourceSpan);
public static SyntaxNode FindNode(this Location location, bool getInnermostNodeForTie, CancellationToken cancellationToken)
=> location.SourceTree!.GetRoot(cancellationToken).FindNode(location.SourceSpan, getInnermostNodeForTie: getInnermostNodeForTie);
=> location.GetSourceTreeOrThrow().GetRoot(cancellationToken).FindNode(location.SourceSpan, getInnermostNodeForTie: getInnermostNodeForTie);
public static SyntaxNode FindNode(this Location location, bool findInsideTrivia, bool getInnermostNodeForTie, CancellationToken cancellationToken)
=> location.SourceTree!.GetRoot(cancellationToken).FindNode(location.SourceSpan, findInsideTrivia, getInnermostNodeForTie);
=> location.GetSourceTreeOrThrow().GetRoot(cancellationToken).FindNode(location.SourceSpan, findInsideTrivia, getInnermostNodeForTie);
public static bool IsVisibleSourceLocation(this Location loc)
{
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册