-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathInterfaceAnalyzer.cs
More file actions
63 lines (59 loc) · 2.28 KB
/
Copy pathInterfaceAnalyzer.cs
File metadata and controls
63 lines (59 loc) · 2.28 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
using System.Collections.Immutable;
using CodeDocumentor.Analyzers.Builders;
using CodeDocumentor.Common.Helper;
using CodeDocumentor.Common.Locators;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.Diagnostics;
namespace CodeDocumentor.Analyzers.Analyzers.Interfaces
{
/// <summary>
/// The interface analyzer.
/// </summary>
[DiagnosticAnalyzer(LanguageNames.CSharp)]
public class InterfaceAnalyzer : DiagnosticAnalyzer
{
private readonly InterfaceAnalyzerSettings _analyzerSettings;
public InterfaceAnalyzer()
{
_analyzerSettings = new InterfaceAnalyzerSettings();
}
/// <summary>
/// Gets the supported diagnostics.
/// </summary>
public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics => ImmutableArray.Create(_analyzerSettings.GetSupportedDiagnosticRule());
/// <summary>
/// Initializes action.
/// </summary>
/// <param name="context"> The context. </param>
public override void Initialize(AnalysisContext context)
{
context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.None);
context.EnableConcurrentExecution();
context.RegisterSyntaxNodeAction(AnalyzeNode, SyntaxKind.InterfaceDeclaration);
}
/// <summary>
/// Analyzes node.
/// </summary>
/// <param name="context"> The context. </param>
public void AnalyzeNode(SyntaxNodeAnalysisContext context)
{
if (!(context.Node is InterfaceDeclarationSyntax node))
{
return;
}
var settings = ServiceLocator.SettingService.BuildSettings(context);
if (settings.IsEnabledForPublicMembersOnly && PrivateMemberVerifier.IsPrivateMember(node))
{
return;
}
var excludeAnanlyzer = ServiceLocator.DocumentationHeaderHelper.HasAnalyzerExclusion(node);
if (excludeAnanlyzer)
{
return;
}
context.BuildDiagnostic(node, node.Identifier, (alreadyHasComment) => _analyzerSettings.GetRule(alreadyHasComment, settings));
}
}
}