-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathMethodAnalyzer.cs
More file actions
73 lines (68 loc) · 2.52 KB
/
Copy pathMethodAnalyzer.cs
File metadata and controls
73 lines (68 loc) · 2.52 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
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.Methods
{
/// <summary>
/// The method analyzer.
/// </summary>
[DiagnosticAnalyzer(LanguageNames.CSharp)]
public class MethodAnalyzer : DiagnosticAnalyzer
{
private readonly MethodAnalyzerSettings _analyzerSettings;
public MethodAnalyzer()
{
_analyzerSettings = new MethodAnalyzerSettings();
}
/// <summary>
/// Gets the supported diagnostics.
/// </summary>
public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics
{
get
{
return ImmutableArray.Create(_analyzerSettings.GetSupportedDiagnosticRule());
}
}
/// <summary>
/// Initializes.
/// </summary>
/// <param name="context"> The context. </param>
public override void Initialize(AnalysisContext context)
{
context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.None);
context.EnableConcurrentExecution();
context.RegisterSyntaxNodeAction(AnalyzeNode, SyntaxKind.MethodDeclaration);
}
/// <summary>
/// Analyzes node.
/// </summary>
/// <param name="context"> The context. </param>
public void AnalyzeNode(SyntaxNodeAnalysisContext context)
{
if (!(context.Node is MethodDeclarationSyntax node))
{
return;
}
//NOTE: Since interfaces declarations do not have accessors, we allow documenting all the time.
var isPrivate = PrivateMemberVerifier.IsPrivateMember(node);
var isOwnedByInterface = node.IsOwnedByInterface();
if (isPrivate && !isOwnedByInterface)
{
return;
}
var excludeAnanlyzer = ServiceLocator.DocumentationHeaderHelper.HasAnalyzerExclusion(node);
if (excludeAnanlyzer)
{
return;
}
var settings = ServiceLocator.SettingService.BuildSettings(context);
context.BuildDiagnostic(node, node.Identifier, (alreadyHasComment) => _analyzerSettings.GetRule(alreadyHasComment, settings));
}
}
}