public static Diagnostic Create( string id, string category, LocalizableString message, DiagnosticSeverity severity, DiagnosticSeverity defaultSeverity, 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) { if (id == null) { throw new ArgumentNullException(nameof(id)); } if (category == null) { throw new ArgumentNullException(nameof(category)); } if (message == null) { throw new ArgumentNullException(nameof(message)); } return(SimpleDiagnostic.Create(id, title ?? string.Empty, category, message, description ?? string.Empty, helpLink ?? string.Empty, severity, defaultSeverity, isEnabledByDefault, warningLevel, location ?? Location.None, additionalLocations, customTags, properties, isSuppressed)); }
/// <summary> /// Creates a <see cref="Diagnostic"/> instance which is localizable. /// </summary> /// <param name="id">An identifier for the diagnostic. For diagnostics generated by the compiler, this will be a numeric code with a prefix such as "CS1001".</param> /// <param name="category">The category of the diagnostic. For diagnostics generated by the compiler, the category will be "Compiler".</param> /// <param name="message">The diagnostic message text.</param> /// <param name="severity">The diagnostic's effective severity.</param> /// <param name="defaultSeverity">The diagnostic's default severity.</param> /// <param name="isEnabledByDefault">True if the diagnostic is enabled by default</param> /// <param name="warningLevel">The warning level, between 1 and 4 if severity is <see cref="DiagnosticSeverity.Warning"/>; otherwise 0.</param> /// <param name="title">An optional short localizable title describing the diagnostic.</param> /// <param name="description">An optional longer localizable description for the diagnostic.</param> /// <param name="helpLink">An optional hyperlink that provides more detailed information regarding the diagnostic.</param> /// <param name="location">An optional primary location of the diagnostic. If null, <see cref="Location"/> will return <see cref="Location.None"/>.</param> /// <param name="additionalLocations"> /// An optional set of additional locations related to the diagnostic. /// Typically, these are locations of other items referenced in the message. /// If null, <see cref="AdditionalLocations"/> will return an empty list. /// </param> /// <param name="customTags"> /// An optional set of custom tags for the diagnostic. See <see cref="WellKnownDiagnosticTags"/> for some well known tags. /// If null, <see cref="CustomTags"/> will return an empty list. /// </param> /// <returns>The <see cref="Diagnostic"/> instance.</returns> public static Diagnostic Create( string id, string category, LocalizableString message, DiagnosticSeverity severity, 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) { if (id == null) { throw new ArgumentNullException("id"); } if (category == null) { throw new ArgumentNullException("category"); } if (message == null) { throw new ArgumentNullException("message"); } return(SimpleDiagnostic.Create(id, title ?? string.Empty, category, message, description ?? string.Empty, helpLink ?? string.Empty, severity, defaultSeverity, isEnabledByDefault, warningLevel, location ?? Location.None, additionalLocations, customTags)); }
/// <summary> /// Creates a <see cref="Diagnostic"/> instance. /// </summary> /// <param name="descriptor">A <see cref="DiagnosticDescriptor"/> describing the diagnostic.</param> /// <param name="location">An optional primary location of the diagnostic. If null, <see cref="Location"/> will return <see cref="Location.None"/>.</param> /// <param name="effectiveSeverity">Effective severity of the diagnostic.</param> /// <param name="additionalLocations"> /// An optional set of additional locations related to the diagnostic. /// Typically, these are locations of other items referenced in the message. /// If null, <see cref="AdditionalLocations"/> will return an empty list. /// </param> /// <param name="properties"> /// An optional set of name-value pairs by means of which the analyzer that creates the diagnostic /// can convey more detailed information to the fixer. If null, <see cref="Properties"/> will return /// <see cref="ImmutableDictionary{TKey, TValue}.Empty"/>. /// </param> /// <param name="messageArgs">Arguments to the message of the diagnostic.</param> /// <returns>The <see cref="Diagnostic"/> instance.</returns> public static Diagnostic Create( DiagnosticDescriptor descriptor, Location?location, DiagnosticSeverity effectiveSeverity, IEnumerable <Location>?additionalLocations, ImmutableDictionary <string, string?>?properties, params object?[]?messageArgs ) { if (descriptor == null) { throw new ArgumentNullException(nameof(descriptor)); } var warningLevel = GetDefaultWarningLevel(effectiveSeverity); return(SimpleDiagnostic.Create( descriptor, severity: effectiveSeverity, warningLevel: warningLevel, location: location ?? Location.None, additionalLocations: additionalLocations, messageArgs: messageArgs, properties: properties )); }
public void GetEffectiveDiagnostics() { var c = CSharpCompilation.Create("c", options: new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary). WithSpecificDiagnosticOptions( new[] { KeyValuePairUtil.Create($"CS{(int)ErrorCode.WRN_AlwaysNull:D4}", ReportDiagnostic.Suppress) })); var d1 = SimpleDiagnostic.Create(MessageProvider.Instance, (int)ErrorCode.WRN_AlignmentMagnitude); var d2 = SimpleDiagnostic.Create(MessageProvider.Instance, (int)ErrorCode.WRN_AlwaysNull); var ds = new[] { null, d1, d2 }; var filtered = CompilationWithAnalyzers.GetEffectiveDiagnostics(ds, c); // overwrite the original value to test eagerness: ds[1] = null; AssertEx.Equal(new[] { d1 }, filtered); }
public override bool Equals(Diagnostic obj) { SimpleDiagnostic other = obj as SimpleDiagnostic; if (other == null) { return(false); } if (AnalyzerExecutor.IsAnalyzerExceptionDiagnostic(this)) { // We have custom Equals logic for diagnostics generated for analyzer exceptions. return(AnalyzerExecutor.AreEquivalentAnalyzerExceptionDiagnostics(this, other)); } return(_descriptor.Equals(other._descriptor) && _messageArgs.SequenceEqual(other._messageArgs, (a, b) => a == b) && _location == other._location && _severity == other._severity && _warningLevel == other._warningLevel); }
/// <summary> /// Creates a <see cref="Diagnostic"/> instance. /// </summary> /// <param name="descriptor">A <see cref="DiagnosticDescriptor"/> describing the diagnostic.</param> /// <param name="location">An optional primary location of the diagnostic. If null, <see cref="Location"/> will return <see cref="Location.None"/>.</param> /// <param name="additionalLocations"> /// An optional set of additional locations related to the diagnostic. /// Typically, these are locations of other items referenced in the message. /// If null, <see cref="AdditionalLocations"/> will return an empty list. /// </param> /// <param name="messageArgs">Arguments to the message of the diagnostic.</param> /// <returns>The <see cref="Diagnostic"/> instance.</returns> public static Diagnostic Create( DiagnosticDescriptor descriptor, Location location, IEnumerable <Location> additionalLocations, params object[] messageArgs) { if (descriptor == null) { throw new ArgumentNullException("descriptor"); } var warningLevel = GetDefaultWarningLevel(descriptor.DefaultSeverity); return(SimpleDiagnostic.Create( descriptor, severity: descriptor.DefaultSeverity, warningLevel: warningLevel, location: location ?? Location.None, additionalLocations: additionalLocations, messageArgs: messageArgs)); }