-
Notifications
You must be signed in to change notification settings - Fork 86
/
Skimmer.cs
80 lines (58 loc) · 3 KB
/
Skimmer.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
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System;
using System.Collections.Generic;
using System.Resources;
namespace Microsoft.CodeAnalysis.Sarif.Driver
{
public abstract class Skimmer<TContext> : ReportingDescriptor
{
public Skimmer()
{
this.Options = new Dictionary<string, string>();
this.DefaultConfiguration = new ReportingConfiguration
{
Level = FailureLevel.Warning,
Enabled = this.EnabledByDefault
};
}
private IDictionary<string, MultiformatMessageString> multiformatMessageStrings;
protected virtual ResourceManager ResourceManager => null;
protected virtual ICollection<string> MessageResourceNames => throw new NotImplementedException();
public virtual bool EnabledByDefault => true;
public virtual ReportingDescriptorReference ReportingDescriptorReference { get; set; }
public virtual ISet<string> IncompatibleRuleIds { get; internal set; }
public override IDictionary<string, MultiformatMessageString> MessageStrings
{
get
{
if (this.multiformatMessageStrings == null)
{
this.multiformatMessageStrings = InitializeMultiformatMessageStrings();
}
return this.multiformatMessageStrings;
}
}
private Dictionary<string, MultiformatMessageString> InitializeMultiformatMessageStrings()
{
return (ResourceManager == null) ? null
: RuleUtilities.BuildDictionary(ResourceManager, MessageResourceNames, ruleId: Id);
}
public int ExtensionIndex { get; set; }
public override string Id => throw new InvalidOperationException($"The {nameof(Id)} property must be overridden in the SkimmerBase-derived class.");
public override MultiformatMessageString FullDescription => throw new InvalidOperationException($"The {nameof(FullDescription)} property must be overridden in the SkimmerBase-derived class.");
public override MultiformatMessageString ShortDescription => null;
public override string Name => this.GetType().Name;
public IDictionary<string, string> Options { get; }
public virtual HashSet<RuleKind> RuleKinds => new HashSet<RuleKind>(new[] { RuleKind.Sarif });
public virtual void Initialize(TContext context) { }
public virtual SupportedPlatform SupportedPlatforms => SupportedPlatform.All;
public virtual AnalysisApplicability CanAnalyze(TContext context, out string reasonIfNotApplicable)
{
reasonIfNotApplicable = null;
return AnalysisApplicability.ApplicableToSpecifiedTarget;
}
public abstract void Analyze(TContext context);
protected static string MakeAnalyzerMoniker(string id, string name) => $"{id}.{name}";
}
}