-
Notifications
You must be signed in to change notification settings - Fork 4k
/
AnalyzerImageReference.cs
93 lines (80 loc) · 2.47 KB
/
AnalyzerImageReference.cs
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
89
90
91
92
93
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using System.Collections.Immutable;
using System.Diagnostics;
using System.Linq;
using System.Text;
namespace Microsoft.CodeAnalysis.Diagnostics
{
/// <summary>
/// Represents an in-memory analyzer reference image.
/// </summary>
[DebuggerDisplay("{GetDebuggerDisplay(), nq}")]
public sealed class AnalyzerImageReference : AnalyzerReference
{
private readonly ImmutableArray<DiagnosticAnalyzer> _analyzers;
private readonly string? _fullPath;
private readonly string? _display;
private readonly string _id;
public AnalyzerImageReference(ImmutableArray<DiagnosticAnalyzer> analyzers, string? fullPath = null, string? display = null)
{
if (analyzers.Any(a => a == null))
{
throw new ArgumentException("Cannot have null-valued analyzer", nameof(analyzers));
}
_analyzers = analyzers;
_fullPath = fullPath;
_display = display;
_id = Guid.NewGuid().ToString();
}
public override ImmutableArray<DiagnosticAnalyzer> GetAnalyzersForAllLanguages()
{
return _analyzers;
}
public override ImmutableArray<DiagnosticAnalyzer> GetAnalyzers(string language)
{
return _analyzers;
}
public override string? FullPath
{
get
{
return _fullPath;
}
}
public override string Display
{
get
{
return _display ?? _fullPath ?? CodeAnalysisResources.InMemoryAssembly;
}
}
public override object Id
{
get
{
return _id;
}
}
private string GetDebuggerDisplay()
{
var sb = new StringBuilder();
sb.Append("Assembly");
if (_fullPath != null)
{
sb.Append(" Path='");
sb.Append(_fullPath);
sb.Append("'");
}
if (_display != null)
{
sb.Append(" Display='");
sb.Append(_display);
sb.Append("'");
}
return sb.ToString();
}
}
}