提交 2670cc6d 编写于 作者: J Jared Parsons

Diagnostics

上级 eddb34a7
......@@ -63,8 +63,8 @@ public override void LogDiagnostic(Diagnostic diagnostic)
_writer.Write("level", GetLevel(diagnostic.Severity));
string message = diagnostic.GetMessage(_culture);
if (!string.IsNullOrEmpty(message))
string? message = diagnostic.GetMessage(_culture);
if (!RoslynString.IsNullOrEmpty(message))
{
_writer.Write("message", message);
}
......@@ -149,14 +149,14 @@ private void WriteRules()
_writer.WriteObjectStart(pair.Key); // rule
_writer.Write("id", descriptor.Id);
string shortDescription = descriptor.Title.ToString(_culture);
if (!string.IsNullOrEmpty(shortDescription))
string? shortDescription = descriptor.Title.ToString(_culture);
if (!RoslynString.IsNullOrEmpty(shortDescription))
{
_writer.Write("shortDescription", shortDescription);
}
string fullDescription = descriptor.Description.ToString(_culture);
if (!string.IsNullOrEmpty(fullDescription))
string? fullDescription = descriptor.Description.ToString(_culture);
if (!RoslynString.IsNullOrEmpty(fullDescription))
{
_writer.Write("fullDescription", fullDescription);
}
......
......@@ -8,6 +8,7 @@
using System.Globalization;
using System.IO;
using System.Linq;
using Roslyn.Utilities;
namespace Microsoft.CodeAnalysis
{
......@@ -53,8 +54,8 @@ public override void LogDiagnostic(Diagnostic diagnostic)
_writer.Write("level", GetLevel(diagnostic.Severity));
string message = diagnostic.GetMessage(_culture);
if (!string.IsNullOrEmpty(message))
string? message = diagnostic.GetMessage(_culture);
if (!RoslynString.IsNullOrEmpty(message))
{
_writer.WriteObjectStart("message");
_writer.Write("text", message);
......@@ -177,16 +178,16 @@ private void WriteRules()
_writer.WriteObjectStart(); // rule
_writer.Write("id", descriptor.Id);
string shortDescription = descriptor.Title.ToString(_culture);
if (!string.IsNullOrEmpty(shortDescription))
string? shortDescription = descriptor.Title.ToString(_culture);
if (!RoslynString.IsNullOrEmpty(shortDescription))
{
_writer.WriteObjectStart("shortDescription");
_writer.Write("text", shortDescription);
_writer.WriteObjectEnd();
}
string fullDescription = descriptor.Description.ToString(_culture);
if (!string.IsNullOrEmpty(fullDescription))
string? fullDescription = descriptor.Description.ToString(_culture);
if (!RoslynString.IsNullOrEmpty(fullDescription))
{
_writer.WriteObjectStart("fullDescription");
_writer.Write("text", fullDescription);
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
#nullable enable
using System.Collections.Generic;
using Roslyn.Utilities;
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
#nullable enable
using System;
using System.Collections.Concurrent;
using System.Globalization;
......@@ -28,7 +30,7 @@ internal abstract class CommonMessageProvider
/// "fill-in" placeholders, those should be expressed in standard string.Format notation
/// and be in the string.
/// </summary>
public abstract string LoadMessage(int code, CultureInfo language);
public abstract string LoadMessage(int code, CultureInfo? language);
/// <summary>
/// Get an optional localizable title for the given diagnostic code.
......@@ -94,7 +96,7 @@ public Diagnostic CreateDiagnostic(int code, Location location)
/// Given a message identifier (e.g., CS0219), severity, warning as error and a culture,
/// get the entire prefix (e.g., "error CS0219: Warning as Error:" for C# or "error BC42024:" for VB) used on error messages.
/// </summary>
public abstract string GetMessagePrefix(string id, DiagnosticSeverity severity, bool isWarningAsError, CultureInfo culture);
public abstract string GetMessagePrefix(string id, DiagnosticSeverity severity, bool isWarningAsError, CultureInfo? culture);
/// <summary>
/// Convert given symbol to string representation.
......@@ -126,7 +128,7 @@ public string GetIdForErrorCode(int errorCode)
/// Filter a <see cref="DiagnosticInfo"/> based on the compilation options so that /nowarn and /warnaserror etc. take effect.options
/// </summary>
/// <returns>A <see cref="DiagnosticInfo"/> with effective severity based on option or null if suppressed.</returns>
public DiagnosticInfo FilterDiagnosticInfo(DiagnosticInfo diagnosticInfo, CompilationOptions options)
public DiagnosticInfo? FilterDiagnosticInfo(DiagnosticInfo diagnosticInfo, CompilationOptions options)
{
var report = this.GetDiagnosticReport(diagnosticInfo, options);
switch (report)
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
#nullable enable
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
......@@ -20,9 +22,9 @@ private sealed class DiagnosticWithProgrammaticSuppression : Diagnostic
Diagnostic originalUnsuppressedDiagnostic,
ProgrammaticSuppressionInfo programmaticSuppressionInfo)
{
Debug.Assert(!originalUnsuppressedDiagnostic.IsSuppressed);
Debug.Assert(originalUnsuppressedDiagnostic.ProgrammaticSuppressionInfo == null);
Debug.Assert(programmaticSuppressionInfo != null);
RoslynDebug.Assert(!originalUnsuppressedDiagnostic.IsSuppressed);
RoslynDebug.Assert(originalUnsuppressedDiagnostic.ProgrammaticSuppressionInfo == null);
RoslynDebug.Assert(programmaticSuppressionInfo != null);
_originalUnsuppressedDiagnostic = originalUnsuppressedDiagnostic;
_programmaticSuppressionInfo = programmaticSuppressionInfo;
......@@ -38,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; }
}
......@@ -81,7 +83,7 @@ public override IReadOnlyList<Location> AdditionalLocations
get { return _originalUnsuppressedDiagnostic.Properties; }
}
public override bool Equals(Diagnostic obj)
public override bool Equals(Diagnostic? obj)
{
var other = obj as DiagnosticWithProgrammaticSuppression;
if (other == null)
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
#nullable enable
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
......@@ -54,8 +56,8 @@ public abstract partial class Diagnostic : IEquatable<Diagnostic>, IFormattable
public static Diagnostic Create(
DiagnosticDescriptor descriptor,
Location location,
ImmutableDictionary<string, string> properties,
params object[] messageArgs)
ImmutableDictionary<string, string>? properties,
params object[]? messageArgs)
{
return Create(descriptor, location, null, properties, messageArgs);
}
......@@ -75,8 +77,8 @@ public abstract partial class Diagnostic : IEquatable<Diagnostic>, IFormattable
public static Diagnostic Create(
DiagnosticDescriptor descriptor,
Location location,
IEnumerable<Location> additionalLocations,
params object[] messageArgs)
IEnumerable<Location>? additionalLocations,
params object[]? messageArgs)
{
return Create(descriptor, location, additionalLocations, properties: null, messageArgs: messageArgs);
}
......@@ -101,9 +103,9 @@ public abstract partial class Diagnostic : IEquatable<Diagnostic>, IFormattable
public static Diagnostic Create(
DiagnosticDescriptor descriptor,
Location location,
IEnumerable<Location> additionalLocations,
ImmutableDictionary<string, string> properties,
params object[] messageArgs)
IEnumerable<Location>? additionalLocations,
ImmutableDictionary<string, string>? properties,
params object[]? messageArgs)
{
return Create(descriptor, location, effectiveSeverity: descriptor.DefaultSeverity, additionalLocations, properties, messageArgs);
}
......@@ -130,9 +132,9 @@ public abstract partial class Diagnostic : IEquatable<Diagnostic>, IFormattable
DiagnosticDescriptor descriptor,
Location location,
DiagnosticSeverity effectiveSeverity,
IEnumerable<Location> additionalLocations,
ImmutableDictionary<string, string> properties,
params object[] messageArgs)
IEnumerable<Location>? additionalLocations,
ImmutableDictionary<string, string>? properties,
params object[]? messageArgs)
{
if (descriptor == null)
{
......@@ -187,13 +189,13 @@ public abstract partial class Diagnostic : IEquatable<Diagnostic>, IFormattable
DiagnosticSeverity defaultSeverity,
bool isEnabledByDefault,
int warningLevel,
LocalizableString title = null,
LocalizableString description = null,
string helpLink = null,
Location location = null,
IEnumerable<Location> additionalLocations = null,
IEnumerable<string> customTags = null,
ImmutableDictionary<string, string> properties = null)
LocalizableString? title = null,
LocalizableString? description = null,
string? helpLink = null,
Location? location = null,
IEnumerable<Location>? additionalLocations = null,
IEnumerable<string>? customTags = null,
ImmutableDictionary<string, string>? properties = null)
{
return Create(id, category, message, severity, defaultSeverity, isEnabledByDefault, warningLevel, false,
title, description, helpLink, location, additionalLocations, customTags, properties);
......@@ -238,13 +240,13 @@ public abstract partial class Diagnostic : IEquatable<Diagnostic>, IFormattable
bool isEnabledByDefault,
int warningLevel,
bool isSuppressed,
LocalizableString title = null,
LocalizableString description = null,
string helpLink = null,
Location location = null,
IEnumerable<Location> additionalLocations = null,
IEnumerable<string> customTags = null,
ImmutableDictionary<string, string> properties = null)
LocalizableString? title = null,
LocalizableString? description = null,
string? helpLink = null,
Location? location = null,
IEnumerable<Location>? additionalLocations = null,
IEnumerable<string>? customTags = null,
ImmutableDictionary<string, string>? properties = null)
{
if (id == null)
{
......@@ -298,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"/>.
......@@ -332,14 +334,14 @@ internal static Diagnostic Create(DiagnosticInfo info)
/// Gets the <see cref="SuppressionInfo"/> for suppressed diagnostics, i.e. <see cref="IsSuppressed"/> = true.
/// Otherwise, returns null.
/// </summary>
public SuppressionInfo GetSuppressionInfo(Compilation compilation)
public SuppressionInfo? GetSuppressionInfo(Compilation compilation)
{
if (!IsSuppressed)
{
return null;
}
AttributeData attribute;
AttributeData? attribute;
var suppressMessageState = new SuppressMessageAttributeState(compilation);
if (!suppressMessageState.IsDiagnosticSuppressed(
this,
......@@ -453,18 +455,18 @@ private string GetDebuggerDisplay()
/// </summary>
internal Diagnostic WithProgrammaticSuppression(ProgrammaticSuppressionInfo programmaticSuppressionInfo)
{
Debug.Assert(this.ProgrammaticSuppressionInfo == null);
Debug.Assert(programmaticSuppressionInfo != null);
RoslynDebug.Assert(this.ProgrammaticSuppressionInfo == null);
RoslynDebug.Assert(programmaticSuppressionInfo != null);
return new DiagnosticWithProgrammaticSuppression(this, programmaticSuppressionInfo);
}
internal virtual ProgrammaticSuppressionInfo ProgrammaticSuppressionInfo { get { return null; } }
internal virtual ProgrammaticSuppressionInfo? ProgrammaticSuppressionInfo { get { return null; } }
// compatibility
internal virtual int Code { get { return 0; } }
internal virtual IReadOnlyList<object> Arguments
internal virtual IReadOnlyList<object>? Arguments
{
get { return SpecializedCollections.EmptyReadOnlyList<object>(); }
}
......@@ -506,7 +508,7 @@ private IEnumerable<Location> GetDiagnosticLocationsWithinTree(SyntaxTree tree)
}
}
internal Diagnostic WithReportDiagnostic(ReportDiagnostic reportAction)
internal Diagnostic? WithReportDiagnostic(ReportDiagnostic reportAction)
{
switch (reportAction)
{
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
#nullable enable
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
......@@ -28,7 +30,7 @@ namespace Microsoft.CodeAnalysis
internal class DiagnosticBag
{
// The lazyBag field is populated lazily -- the first time an error is added.
private ConcurrentQueue<Diagnostic> _lazyBag;
private ConcurrentQueue<Diagnostic>? _lazyBag;
/// <summary>
/// Return true if the bag is completely empty - not even containing void diagnostics.
......@@ -45,7 +47,7 @@ public bool IsEmptyWithoutResolution
// then a report phase, and we shouldn't be called during the "report" phase. We
// also never remove diagnostics, so the worst that happens is that we don't return
// an element that is added a split second after this is called.
ConcurrentQueue<Diagnostic> bag = _lazyBag;
ConcurrentQueue<Diagnostic>? bag = _lazyBag;
return bag == null || bag.IsEmpty;
}
}
......@@ -167,7 +169,7 @@ public void AddRangeAndFree(DiagnosticBag bag)
/// </summary>
public ImmutableArray<TDiagnostic> ToReadOnlyAndFree<TDiagnostic>() where TDiagnostic : Diagnostic
{
ConcurrentQueue<Diagnostic> oldBag = _lazyBag;
ConcurrentQueue<Diagnostic>? oldBag = _lazyBag;
Free();
return ToReadOnlyCore<TDiagnostic>(oldBag);
......@@ -180,7 +182,7 @@ public ImmutableArray<Diagnostic> ToReadOnlyAndFree()
public ImmutableArray<TDiagnostic> ToReadOnly<TDiagnostic>() where TDiagnostic : Diagnostic
{
ConcurrentQueue<Diagnostic> oldBag = _lazyBag;
ConcurrentQueue<Diagnostic>? oldBag = _lazyBag;
return ToReadOnlyCore<TDiagnostic>(oldBag);
}
......@@ -189,7 +191,7 @@ public ImmutableArray<Diagnostic> ToReadOnly()
return ToReadOnly<Diagnostic>();
}
private static ImmutableArray<TDiagnostic> ToReadOnlyCore<TDiagnostic>(ConcurrentQueue<Diagnostic> oldBag) where TDiagnostic : Diagnostic
private static ImmutableArray<TDiagnostic> ToReadOnlyCore<TDiagnostic>(ConcurrentQueue<Diagnostic>? oldBag) where TDiagnostic : Diagnostic
{
if (oldBag == null)
{
......@@ -285,7 +287,7 @@ private ConcurrentQueue<Diagnostic> Bag
{
get
{
ConcurrentQueue<Diagnostic> bag = _lazyBag;
ConcurrentQueue<Diagnostic>? bag = _lazyBag;
if (bag != null)
{
return bag;
......@@ -302,7 +304,7 @@ private ConcurrentQueue<Diagnostic> Bag
/// broken and we cannot do anything about it here.
internal void Clear()
{
ConcurrentQueue<Diagnostic> bag = _lazyBag;
ConcurrentQueue<Diagnostic>? bag = _lazyBag;
if (bag != null)
{
_lazyBag = null;
......@@ -347,7 +349,7 @@ public object[] Diagnostics
{
get
{
ConcurrentQueue<Diagnostic> lazyBag = _bag._lazyBag;
ConcurrentQueue<Diagnostic>? lazyBag = _bag._lazyBag;
if (lazyBag != null)
{
return lazyBag.ToArray();
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
#nullable enable
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
......@@ -81,8 +83,8 @@ public sealed class DiagnosticDescriptor : IEquatable<DiagnosticDescriptor>
string category,
DiagnosticSeverity defaultSeverity,
bool isEnabledByDefault,
string description = null,
string helpLinkUri = null,
string? description = null,
string? helpLinkUri = null,
params string[] customTags)
: this(id, title, messageFormat, category, defaultSeverity, isEnabledByDefault, description, helpLinkUri, customTags.AsImmutableOrEmpty())
{
......@@ -118,8 +120,8 @@ public sealed class DiagnosticDescriptor : IEquatable<DiagnosticDescriptor>
string category,
DiagnosticSeverity defaultSeverity,
bool isEnabledByDefault,
LocalizableString description = null,
string helpLinkUri = null,
LocalizableString? description = null,
string? helpLinkUri = null,
params string[] customTags)
: this(id, title, messageFormat, category, defaultSeverity, isEnabledByDefault, description, helpLinkUri, customTags.AsImmutableOrEmpty())
{
......@@ -132,8 +134,8 @@ public sealed class DiagnosticDescriptor : IEquatable<DiagnosticDescriptor>
string category,
DiagnosticSeverity defaultSeverity,
bool isEnabledByDefault,
LocalizableString description,
string helpLinkUri,
LocalizableString? description,
string? helpLinkUri,
ImmutableArray<string> customTags)
{
if (string.IsNullOrWhiteSpace(id))
......@@ -167,7 +169,7 @@ public sealed class DiagnosticDescriptor : IEquatable<DiagnosticDescriptor>
this.CustomTags = customTags;
}
public bool Equals(DiagnosticDescriptor other)
public bool Equals(DiagnosticDescriptor? other)
{
return
other != null &&
......@@ -181,7 +183,7 @@ public bool Equals(DiagnosticDescriptor other)
this.Title.Equals(other.Title);
}
public override bool Equals(object obj)
public override bool Equals(object? obj)
{
return Equals(obj as DiagnosticDescriptor);
}
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
#nullable enable
using System;
using System.Globalization;
using Microsoft.CodeAnalysis.Text;
......@@ -18,7 +20,7 @@ public class DiagnosticFormatter
/// <param name="diagnostic">The diagnostic.</param>
/// <param name="formatter">The formatter; or null to use the default formatter.</param>
/// <returns>The formatted message.</returns>
public virtual string Format(Diagnostic diagnostic, IFormatProvider formatter = null)
public virtual string Format(Diagnostic diagnostic, IFormatProvider? formatter = null)
{
if (diagnostic == null)
{
......@@ -39,7 +41,7 @@ public virtual string Format(Diagnostic diagnostic, IFormatProvider formatter =
goto default;
}
string path, basePath;
string? path, basePath;
if (mappedSpan.HasMappedPath)
{
path = mappedSpan.Path;
......@@ -64,13 +66,13 @@ public virtual string Format(Diagnostic diagnostic, IFormatProvider formatter =
}
}
internal virtual string FormatSourcePath(string path, string basePath, IFormatProvider formatter)
internal virtual string FormatSourcePath(string path, string? basePath, IFormatProvider? formatter)
{
// ignore base path
return path;
}
internal virtual string FormatSourceSpan(LinePositionSpan span, IFormatProvider formatter)
internal virtual string FormatSourceSpan(LinePositionSpan span, IFormatProvider? formatter)
{
return string.Format("({0},{1})", span.Start.Line + 1, span.Start.Character + 1);
}
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
#nullable enable
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
......@@ -26,7 +28,7 @@ internal class DiagnosticInfo : IFormattable, IObjectWritable
private readonly int _errorCode;
private readonly DiagnosticSeverity _defaultSeverity;
private readonly DiagnosticSeverity _effectiveSeverity;
private readonly object[] _arguments;
private readonly object[]? _arguments;
private static ImmutableDictionary<int, DiagnosticDescriptor> s_errorCodeToDescriptorMap = ImmutableDictionary<int, DiagnosticDescriptor>.Empty;
......@@ -96,7 +98,7 @@ internal static void AssertMessageSerializable(object[] args)
{
foreach (var arg in args)
{
Debug.Assert(arg != null);
RoslynDebug.Assert(arg != null);
if (arg is IFormattable)
{
......@@ -158,7 +160,7 @@ protected virtual void WriteTo(ObjectWriter writer)
if (count > 0)
{
foreach (var arg in _arguments)
foreach (var arg in _arguments!)
{
writer.WriteString(arg.ToString());
}
......@@ -320,7 +322,7 @@ public string MessageIdentifier
/// <summary>
/// Get the text of the message in the given language.
/// </summary>
public virtual string GetMessage(IFormatProvider formatProvider = null)
public virtual string GetMessage(IFormatProvider? formatProvider = null)
{
// Get the message and fill in arguments.
string message = _messageProvider.LoadMessage(_errorCode, formatProvider as CultureInfo);
......@@ -337,9 +339,10 @@ public virtual string GetMessage(IFormatProvider formatProvider = null)
return String.Format(formatProvider, message, GetArgumentsToUse(formatProvider));
}
protected object[] GetArgumentsToUse(IFormatProvider formatProvider)
protected object[] GetArgumentsToUse(IFormatProvider? formatProvider)
{
object[] argumentsToUse = null;
RoslynDebug.Assert(_arguments is object);
object[]? argumentsToUse = null;
for (int i = 0; i < _arguments.Length; i++)
{
var embedded = _arguments[i] as DiagnosticInfo;
......@@ -361,20 +364,21 @@ protected object[] GetArgumentsToUse(IFormatProvider formatProvider)
return argumentsToUse ?? _arguments;
}
private object[] InitializeArgumentListIfNeeded(object[] argumentsToUse)
private object[] InitializeArgumentListIfNeeded(object[]? argumentsToUse)
{
if (argumentsToUse != null)
{
return argumentsToUse;
}
RoslynDebug.Assert(_arguments != null);
var newArguments = new object[_arguments.Length];
Array.Copy(_arguments, newArguments, newArguments.Length);
return newArguments;
}
internal object[] Arguments
internal object[]? Arguments
{
get { return _arguments; }
}
......@@ -385,17 +389,17 @@ internal CommonMessageProvider MessageProvider
}
// TODO (tomat): remove
public override string ToString()
public override string? ToString()
{
return ToString(null);
}
public string ToString(IFormatProvider formatProvider)
public string ToString(IFormatProvider? formatProvider)
{
return ((IFormattable)this).ToString(null, formatProvider);
}
string IFormattable.ToString(string format, IFormatProvider formatProvider)
string IFormattable.ToString(string format, IFormatProvider? formatProvider)
{
return String.Format(formatProvider, "{0}: {1}",
_messageProvider.GetMessagePrefix(this.MessageIdentifier, this.Severity, this.IsWarningAsError, formatProvider as CultureInfo),
......@@ -416,15 +420,15 @@ public sealed override int GetHashCode()
return hashCode;
}
public sealed override bool Equals(object obj)
public sealed override bool Equals(object? obj)
{
DiagnosticInfo other = obj as DiagnosticInfo;
DiagnosticInfo? other = obj as DiagnosticInfo;
bool result = false;
if (other != null &&
other._errorCode == _errorCode &&
this.GetType() == obj.GetType())
other.GetType() == this.GetType())
{
if (_arguments == null && other._arguments == null)
{
......@@ -447,7 +451,7 @@ public sealed override bool Equals(object obj)
return result;
}
private string GetDebuggerDisplay()
private string? GetDebuggerDisplay()
{
// There aren't message resources for our internal error codes, so make
// sure we don't call ToString for those.
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
#nullable enable
namespace Microsoft.CodeAnalysis
{
/// <summary>
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
#nullable enable
using System;
using System.Collections.Generic;
using System.Diagnostics;
......@@ -20,8 +22,8 @@ internal class DiagnosticWithInfo : Diagnostic
internal DiagnosticWithInfo(DiagnosticInfo info, Location location, bool isSuppressed = false)
{
Debug.Assert(info != null);
Debug.Assert(location != null);
RoslynDebug.Assert(info != null);
RoslynDebug.Assert(location != null);
_info = info;
_location = location;
_isSuppressed = isSuppressed;
......@@ -95,12 +97,12 @@ public sealed override int WarningLevel
get { return this.Info.WarningLevel; }
}
public override string GetMessage(IFormatProvider formatProvider = null)
public override string GetMessage(IFormatProvider? formatProvider = null)
{
return this.Info.GetMessage(formatProvider);
}
internal override IReadOnlyList<object> Arguments
internal override IReadOnlyList<object>? Arguments
{
get { return this.Info.Arguments; }
}
......@@ -139,12 +141,12 @@ public override int GetHashCode()
return Hash.Combine(this.Location.GetHashCode(), this.Info.GetHashCode());
}
public override bool Equals(object obj)
public override bool Equals(object? obj)
{
return Equals(obj as Diagnostic);
}
public override bool Equals(Diagnostic obj)
public override bool Equals(Diagnostic? obj)
{
if (this == obj)
{
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
#nullable enable
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
......@@ -30,9 +32,9 @@ internal sealed class SimpleDiagnostic : Diagnostic
DiagnosticSeverity severity,
int warningLevel,
Location location,
IEnumerable<Location> additionalLocations,
object[] messageArgs,
ImmutableDictionary<string, string> properties,
IEnumerable<Location>? additionalLocations,
object[]? messageArgs,
ImmutableDictionary<string, string>? properties,
bool isSuppressed)
{
if ((warningLevel == 0 && severity != DiagnosticSeverity.Error) ||
......@@ -56,9 +58,9 @@ internal sealed class SimpleDiagnostic : Diagnostic
DiagnosticSeverity severity,
int warningLevel,
Location location,
IEnumerable<Location> additionalLocations,
object[] messageArgs,
ImmutableDictionary<string, string> properties,
IEnumerable<Location>? additionalLocations,
object[]? messageArgs,
ImmutableDictionary<string, string>? properties,
bool isSuppressed = false)
{
return new SimpleDiagnostic(descriptor, severity, warningLevel, location, additionalLocations, messageArgs, properties, isSuppressed);
......@@ -67,8 +69,8 @@ internal sealed class SimpleDiagnostic : Diagnostic
internal static SimpleDiagnostic Create(string id, LocalizableString title, string category, LocalizableString message, LocalizableString description, string helpLink,
DiagnosticSeverity severity, DiagnosticSeverity defaultSeverity,
bool isEnabledByDefault, int warningLevel, Location location,
IEnumerable<Location> additionalLocations, IEnumerable<string> customTags,
ImmutableDictionary<string, string> properties, bool isSuppressed = false)
IEnumerable<Location>? additionalLocations, IEnumerable<string>? customTags,
ImmutableDictionary<string, string>? properties, bool isSuppressed = false)
{
var descriptor = new DiagnosticDescriptor(id, title, message,
category, defaultSeverity, isEnabledByDefault, description, helpLink, customTags.ToImmutableArrayOrEmpty());
......@@ -85,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)
{
......@@ -140,7 +142,7 @@ public override IReadOnlyList<Location> AdditionalLocations
get { return _properties; }
}
public override bool Equals(Diagnostic obj)
public override bool Equals(Diagnostic? obj)
{
var other = obj as SimpleDiagnostic;
if (other == null)
......@@ -176,7 +178,7 @@ public override int GetHashCode()
internal override Diagnostic WithLocation(Location location)
{
if (location == null)
if (location is null)
{
throw new ArgumentNullException(nameof(location));
}
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
#nullable enable
using System;
using Microsoft.CodeAnalysis.Text;
using Roslyn.Utilities;
......@@ -46,12 +48,12 @@ public override LocationKind Kind
}
}
public override bool Equals(object obj)
public override bool Equals(object? obj)
{
return this.Equals(obj as ExternalFileLocation);
}
public bool Equals(ExternalFileLocation obj)
public bool Equals(ExternalFileLocation? obj)
{
if (ReferenceEquals(obj, this))
{
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
#nullable enable
using System;
using Microsoft.CodeAnalysis.Text;
using Roslyn.Utilities;
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
#nullable enable
using System;
namespace Microsoft.CodeAnalysis
......@@ -15,14 +17,14 @@ private sealed class FixedLocalizableString : LocalizableString
private readonly string _fixedString;
public static FixedLocalizableString Create(string fixedResource)
public static FixedLocalizableString Create(string? fixedResource)
{
if (string.IsNullOrEmpty(fixedResource))
{
return s_empty;
}
return new FixedLocalizableString(fixedResource);
return new FixedLocalizableString(fixedResource!);
}
private FixedLocalizableString(string fixedResource)
......@@ -30,12 +32,12 @@ private FixedLocalizableString(string fixedResource)
_fixedString = fixedResource;
}
protected override string GetText(IFormatProvider formatProvider)
protected override string GetText(IFormatProvider? formatProvider)
{
return _fixedString;
}
protected override bool AreEqual(object other)
protected override bool AreEqual(object? other)
{
var fixedStr = other as FixedLocalizableString;
return fixedStr != null && string.Equals(_fixedString, fixedStr._fixedString);
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
#nullable enable
using System;
using System.Globalization;
using System.Linq;
......@@ -107,7 +109,7 @@ void IObjectWritable.WriteTo(ObjectWriter writer)
}
}
protected override string GetText(IFormatProvider formatProvider)
protected override string? GetText(IFormatProvider? formatProvider)
{
var culture = formatProvider as CultureInfo ?? CultureInfo.CurrentUICulture;
var resourceString = _resourceManager.GetString(_nameOfLocalizableResource, culture);
......@@ -116,7 +118,7 @@ protected override string GetText(IFormatProvider formatProvider)
string.Empty;
}
protected override bool AreEqual(object other)
protected override bool AreEqual(object? other)
{
var otherResourceString = other as LocalizableResourceString;
return otherResourceString != null &&
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
#nullable enable
using System;
namespace Microsoft.CodeAnalysis
......@@ -14,12 +16,12 @@ public abstract partial class LocalizableString : IFormattable, IEquatable<Local
/// Fired when an exception is raised by any of the public methods of <see cref="LocalizableString"/>.
/// If the exception handler itself throws an exception, that exception is ignored.
/// </summary>
public event EventHandler<Exception> OnException;
public event EventHandler<Exception>? OnException;
/// <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
{
......@@ -32,22 +34,22 @@ public string ToString(IFormatProvider formatProvider)
}
}
public static explicit operator string(LocalizableString localizableResource)
public static explicit operator string?(LocalizableString localizableResource)
{
return localizableResource.ToString(null);
}
public static implicit operator LocalizableString(string fixedResource)
public static implicit operator LocalizableString(string? fixedResource)
{
return FixedLocalizableString.Create(fixedResource);
}
public sealed override string ToString()
public sealed override string? ToString()
{
return ToString(null);
}
string IFormattable.ToString(string ignored, IFormatProvider formatProvider)
string? IFormattable.ToString(string? ignored, IFormatProvider? formatProvider)
{
return ToString(formatProvider);
}
......@@ -65,7 +67,7 @@ public sealed override int GetHashCode()
}
}
public sealed override bool Equals(object other)
public sealed override bool Equals(object? other)
{
try
{
......@@ -78,9 +80,9 @@ public sealed override bool Equals(object other)
}
}
public bool Equals(LocalizableString other)
public bool Equals(LocalizableString? other)
{
return Equals((object)other);
return Equals((object?)other);
}
/// <summary>
......@@ -88,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
......@@ -102,7 +104,7 @@ public bool Equals(LocalizableString other)
/// if this method throws an exception.
/// </summary>
/// <returns></returns>
protected abstract bool AreEqual(object other);
protected abstract bool AreEqual(object? other);
private void RaiseOnException(Exception ex)
{
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
#nullable enable
using System;
using System.Diagnostics;
using Microsoft.CodeAnalysis.Symbols;
......@@ -35,7 +37,7 @@ internal Location()
/// <summary>
/// The syntax tree this location is located in or <c>null</c> if not in a syntax tree.
/// </summary>
public virtual SyntaxTree SourceTree { get { return null; } }
public virtual SyntaxTree? SourceTree { get { return null; } }
/// <summary>
/// Returns the metadata module the location is associated with or <c>null</c> if the module is not available.
......@@ -44,9 +46,9 @@ internal Location()
/// Might return null even if <see cref="IsInMetadata"/> returns true. The module symbol might not be available anymore,
/// for example, if the location is serialized and deserialized.
/// </remarks>
public IModuleSymbol MetadataModule { get { return (IModuleSymbol)MetadataModuleInternal?.GetISymbol(); } }
public IModuleSymbol? MetadataModule { get { return (IModuleSymbol?)MetadataModuleInternal?.GetISymbol(); } }
internal virtual IModuleSymbolInternal MetadataModuleInternal { get { return null; } }
internal virtual IModuleSymbolInternal? MetadataModuleInternal { get { return null; } }
/// <summary>
/// The location within the syntax tree that this location is associated with.
......@@ -85,7 +87,7 @@ public virtual FileLinePositionSpan GetMappedLineSpan()
}
// Derived classes should provide value equality semantics.
public abstract override bool Equals(object obj);
public abstract override bool Equals(object? obj);
public abstract override int GetHashCode();
public override string ToString()
......@@ -115,7 +117,7 @@ public override string ToString()
return result;
}
public static bool operator ==(Location left, Location right)
public static bool operator ==(Location? left, Location? right)
{
if (object.ReferenceEquals(left, null))
{
......@@ -125,7 +127,7 @@ public override string ToString()
return left.Equals(right);
}
public static bool operator !=(Location left, Location right)
public static bool operator !=(Location? left, Location? right)
{
return !(left == right);
}
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
#nullable enable
using Microsoft.CodeAnalysis.Text;
namespace Microsoft.CodeAnalysis
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
#nullable enable
using System;
using System.Diagnostics;
using Microsoft.CodeAnalysis.Symbols;
using Roslyn.Utilities;
namespace Microsoft.CodeAnalysis
{
......@@ -15,7 +18,7 @@ internal sealed class MetadataLocation : Location, IEquatable<MetadataLocation>
internal MetadataLocation(IModuleSymbolInternal module)
{
Debug.Assert(module != null);
RoslynDebug.Assert(module != null);
_module = module;
}
......@@ -34,14 +37,14 @@ public override int GetHashCode()
return _module.GetHashCode();
}
public override bool Equals(object obj)
public override bool Equals(object? obj)
{
return Equals(obj as MetadataLocation);
}
public bool Equals(MetadataLocation other)
public bool Equals(MetadataLocation? other)
{
return other != null && other._module == _module;
return other is object && other._module == _module;
}
}
}
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
#nullable enable
namespace Microsoft.CodeAnalysis
{
/// <summary>
......@@ -19,7 +21,7 @@ public override LocationKind Kind
get { return LocationKind.None; }
}
public override bool Equals(object obj)
public override bool Equals(object? obj)
{
return (object)this == obj;
}
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
#nullable enable
using System;
using System.Collections.Immutable;
......@@ -17,7 +19,7 @@ internal ProgrammaticSuppressionInfo(ImmutableHashSet<(string Id, LocalizableStr
Suppressions = suppressions;
}
public bool Equals(ProgrammaticSuppressionInfo other)
public bool Equals(ProgrammaticSuppressionInfo? other)
{
if (ReferenceEquals(this, other))
{
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
#nullable enable
namespace Microsoft.CodeAnalysis
{
/// <summary>
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
#nullable enable
using System;
using System.Diagnostics;
using Microsoft.CodeAnalysis.Text;
......@@ -101,7 +103,7 @@ public override FileLinePositionSpan GetMappedLineSpan()
return _syntaxTree.GetMappedLineSpan(_span);
}
public bool Equals(SourceLocation other)
public bool Equals(SourceLocation? other)
{
if (ReferenceEquals(this, other))
{
......@@ -111,7 +113,7 @@ public bool Equals(SourceLocation other)
return other != null && other._syntaxTree == _syntaxTree && other._span == _span;
}
public override bool Equals(object obj)
public override bool Equals(object? obj)
{
return this.Equals(obj as SourceLocation);
}
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
#nullable enable
using System;
using Microsoft.CodeAnalysis.Diagnostics;
using Roslyn.Utilities;
......@@ -68,7 +70,7 @@ public sealed class SuppressionDescriptor : IEquatable<SuppressionDescriptor>
this.Justification = justification ?? throw new ArgumentNullException(nameof(justification));
}
public bool Equals(SuppressionDescriptor other)
public bool Equals(SuppressionDescriptor? other)
{
if (ReferenceEquals(this, other))
{
......@@ -82,7 +84,7 @@ public bool Equals(SuppressionDescriptor other)
this.Justification.Equals(other.Justification);
}
public override bool Equals(object obj)
public override bool Equals(object? obj)
{
return Equals(obj as SuppressionDescriptor);
}
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
#nullable enable
namespace Microsoft.CodeAnalysis.Diagnostics
{
/// <summary>
......@@ -16,9 +18,9 @@ public sealed class SuppressionInfo
/// If the diagnostic was suppressed by an attribute, then returns that attribute.
/// Otherwise, returns null.
/// </summary>
public AttributeData Attribute { get; }
public AttributeData? Attribute { get; }
internal SuppressionInfo(string id, AttributeData attribute)
internal SuppressionInfo(string id, AttributeData? attribute)
{
Id = id;
Attribute = attribute;
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
#nullable enable
using Microsoft.CodeAnalysis.Diagnostics;
namespace Microsoft.CodeAnalysis
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
#nullable enable
using Microsoft.CodeAnalysis.Text;
using System;
using System.Xml.Linq;
......@@ -56,7 +58,7 @@ public override FileLinePositionSpan GetLineSpan()
return _positionSpan;
}
public bool Equals(XmlLocation other)
public bool Equals(XmlLocation? other)
{
if (ReferenceEquals(this, other))
{
......@@ -66,7 +68,7 @@ public bool Equals(XmlLocation other)
return other != null && other._positionSpan.Equals(_positionSpan);
}
public override bool Equals(object obj)
public override bool Equals(object? obj)
{
return this.Equals(obj as XmlLocation);
}
......
......@@ -523,6 +523,7 @@ async Task VerifyDiagnosticLocationAsync(string id, Location location)
break;
case LocationKind.SourceFile:
{
RoslynDebug.Assert(location.SourceTree != null);
if (project.GetDocument(location.SourceTree) == null)
{
// Disallow diagnostics with source locations outside this project.
......
......@@ -326,7 +326,7 @@ private bool IsCandidateForFullSolutionAnalysis(DiagnosticAnalyzer analyzer, Pro
// For most of analyzers, the number of diagnostic descriptors is small, so this should be cheap.
var descriptors = AnalyzerService.GetDiagnosticDescriptors(analyzer);
return descriptors.Any(d => d.GetEffectiveSeverity(project.CompilationOptions) != ReportDiagnostic.Hidden);
return descriptors.Any(d => d.GetEffectiveSeverity(project.CompilationOptions!) != ReportDiagnostic.Hidden);
}
private void RaiseProjectDiagnosticsIfNeeded(
......
......@@ -559,7 +559,7 @@ protected virtual string GetSuspensionPointDisplayName(SyntaxNode node, EditKind
if (firstDeclaratingErrorOpt != null)
{
var location = firstDeclaratingErrorOpt.Location;
DocumentAnalysisResults.Log.Write("Declaration errors, first: {0}", location.IsInSource ? location.SourceTree.FilePath : location.MetadataModule.Name);
DocumentAnalysisResults.Log.Write("Declaration errors, first: {0}", location.IsInSource ? location.SourceTree!.FilePath : location.MetadataModule!.Name);
return DocumentAnalysisResults.Errors(newActiveStatements.AsImmutable(), ImmutableArray<RudeEditDiagnostic>.Empty, hasSemanticErrors: true);
}
......
......@@ -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:
......
......@@ -23,8 +23,8 @@ internal sealed class DiagnosticData : IEquatable<DiagnosticData>
{
public readonly string Id;
public readonly string Category;
public readonly string Message;
public readonly string ENUMessageForBingSearch;
public readonly string? Message;
public readonly string? ENUMessageForBingSearch;
public readonly DiagnosticSeverity Severity;
public readonly DiagnosticSeverity DefaultSeverity;
......@@ -56,8 +56,8 @@ internal sealed class DiagnosticData : IEquatable<DiagnosticData>
public DiagnosticData(
string id,
string category,
string message,
string enuMessageForBingSearch,
string? message,
string? enuMessageForBingSearch,
DiagnosticSeverity severity,
DiagnosticSeverity defaultSeverity,
bool isEnabledByDefault,
......@@ -384,7 +384,7 @@ public static bool TryCreate(DiagnosticDescriptor descriptor, string[] messageAr
{
// Get the effective severity of the diagnostic from the compilation options.
// PERF: We do not check if the diagnostic was suppressed by a source suppression, as this requires us to force complete the assembly attributes, which is very expensive.
var reportDiagnostic = descriptor.GetEffectiveSeverity(project.CompilationOptions);
var reportDiagnostic = descriptor.GetEffectiveSeverity(project.CompilationOptions!);
if (reportDiagnostic == ReportDiagnostic.Suppress)
{
// Rule is disabled by compilation options.
......
......@@ -24,14 +24,14 @@ internal static partial class Extensions
{
public static readonly CultureInfo USCultureInfo = new CultureInfo("en-US");
public static string GetBingHelpMessage(this Diagnostic diagnostic, OptionSet options)
public static string? GetBingHelpMessage(this Diagnostic diagnostic, OptionSet options)
{
// We use the ENU version of the message for bing search.
return options.GetOption(InternalDiagnosticsOptions.PutCustomTypeInBingSearch) ?
diagnostic.GetMessage(USCultureInfo) : diagnostic.Descriptor.GetBingHelpMessage();
}
public static string GetBingHelpMessage(this DiagnosticDescriptor descriptor)
public static string? GetBingHelpMessage(this DiagnosticDescriptor descriptor)
{
// We use the ENU version of the message for bing search.
return descriptor.MessageFormat.ToString(USCultureInfo);
......
......@@ -9,16 +9,16 @@ namespace Microsoft.CodeAnalysis.Shared.Extensions
internal static class LocationExtensions
{
public static SyntaxToken FindToken(this Location location, CancellationToken cancellationToken)
=> location.SourceTree.GetRoot(cancellationToken).FindToken(location.SourceSpan.Start);
=> location.SourceTree!.GetRoot(cancellationToken).FindToken(location.SourceSpan.Start);
public static SyntaxNode FindNode(this Location location, CancellationToken cancellationToken)
=> location.SourceTree.GetRoot(cancellationToken).FindNode(location.SourceSpan);
=> location.SourceTree!.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.SourceTree!.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.SourceTree!.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.
先完成此消息的编辑!
想要评论请 注册