forked from UbiquityDotNET/Ubiquity.NET.Utils
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSourceProductionContextExtensions.cs
More file actions
88 lines (82 loc) · 4.19 KB
/
Copy pathSourceProductionContextExtensions.cs
File metadata and controls
88 lines (82 loc) · 4.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
// Copyright (c) Ubiquity.NET Contributors. All rights reserved.
// Licensed under the Apache-2.0 WITH LLVM-exception license. See the LICENSE.md file in the project root for full license information.
namespace Ubiquity.NET.CodeAnalysis.Utils
{
/// <summary>Utility class to provide extensions for a <see cref="SourceProductionContext"/></summary>
public static class SourceProductionContextExtensions
{
/// <summary>Reports deferred diagnostics for a <see cref="Result{T}"/></summary>
/// <typeparam name="T">Type of the result values</typeparam>
/// <param name="self">The context to report any diagnostics to</param>
/// <param name="result">The result</param>
/// <remarks>
/// if <paramref name="result"/> has no diagnostics associated with it this is a NOP.
/// </remarks>
public static void ReportDiagnostic<T>(this SourceProductionContext self, Result<T> result)
where T : IEquatable<T>
{
if(result.HasDiagnostics)
{
for(int i = 0; i < result.Diagnostics.Length; ++i)
{
self.ReportDiagnostic(result.Diagnostics[i]);
}
}
}
/// <summary>Reports a diagnostic to <paramref name="self"/></summary>
/// <param name="self">The context to report the diagnostic to</param>
/// <param name="info">Cached info to report</param>
public static void ReportDiagnostic( this SourceProductionContext self, DiagnosticInfo info)
{
self.ReportDiagnostic(info.CreateDiagnostic());
}
/// <summary>Reports a diagnostic to <paramref name="self"/></summary>
/// <param name="self">The context to report the diagnostic to</param>
/// <param name="descriptor">Descriptor of the diagnostic</param>
/// <param name="messageArgs">Message arguments</param>
public static void ReportDiagnostic( this SourceProductionContext self, DiagnosticDescriptor descriptor, params object[] messageArgs)
{
self.ReportDiagnostic(Diagnostic.Create(descriptor, null, messageArgs));
}
/// <summary>Reports a diagnostic to <paramref name="self"/></summary>
/// <param name="self">The context to report the diagnostic to</param>
/// <param name="location">Location of the source of this diagnostic</param>
/// <param name="descriptor">Descriptor for the diagnostic</param>
/// <param name="messageArgs">Arguments, if any, for the diagnostic message</param>
public static void ReportDiagnostic(
this SourceProductionContext self,
Location location,
DiagnosticDescriptor descriptor,
params object[] messageArgs
)
{
self.ReportDiagnostic(Diagnostic.Create(descriptor, location, messageArgs));
}
/// <summary>Reports a diagnostic to <paramref name="self"/></summary>
/// <param name="self">The context to report the diagnostic to</param>
/// <param name="node">Node as the source of the diagnostic</param>
/// <param name="descriptor">Descriptor for the diagnostic</param>
/// <param name="messageArgs">Arguments, if any, for the diagnostic message</param>
public static void ReportDiagnostic(
this SourceProductionContext self,
CSharpSyntaxNode node,
DiagnosticDescriptor descriptor,
params object[] messageArgs
)
{
self.ReportDiagnostic(node.GetLocation(), descriptor, messageArgs);
}
/// <summary>Report diagnostics for results to <paramref name="self"/></summary>
/// <typeparam name="T">Type of the result</typeparam>
/// <param name="self">The context to report the diagnostic to</param>
/// <param name="results">Array of <see cref="Result{T}"/> for the results</param>
public static void ReportDiagnostics<T>( this SourceProductionContext self, ImmutableArray<Result<T>> results)
where T : IEquatable<T>
{
for(int i = 0; i < results.Length; ++i)
{
self.ReportDiagnostic(results[i]);
}
}
}
}