/
DuplicatedAnnotationInspection.cs
65 lines (59 loc) · 2.02 KB
/
DuplicatedAnnotationInspection.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
using System.Collections.Generic;
using System.Linq;
using Rubberduck.Inspections.Abstract;
using Rubberduck.Inspections.Results;
using Rubberduck.Parsing.Inspections.Abstract;
using Rubberduck.Parsing.VBA;
using Rubberduck.Resources.Inspections;
namespace Rubberduck.Inspections.Concrete
{
/// <summary>
/// Warns about duplicated annotations.
/// </summary>
/// <why>
/// Rubberduck annotations should not be specified more than once for a given module, member, variable, or expression.
/// </why>
/// <example hasResults="true">
/// <![CDATA[
/// '@Folder("Bar")
/// '@Folder("Foo")
///
/// Public Sub DoSomething()
/// ' ...
/// End Sub
/// ]]>
/// </example>
/// <example hasResults="false">
/// <![CDATA[
/// '@Folder("Foo.Bar")
///
/// Public Sub DoSomething()
/// ' ...
/// End Sub
/// ]]>
/// </example>
public sealed class DuplicatedAnnotationInspection : InspectionBase
{
public DuplicatedAnnotationInspection(RubberduckParserState state) : base(state)
{
}
protected override IEnumerable<IInspectionResult> DoGetInspectionResults()
{
var issues = new List<DeclarationInspectionResult>();
foreach (var declaration in State.AllUserDeclarations)
{
var duplicateAnnotations = declaration.Annotations
.GroupBy(annotation => annotation.GetType())
.Where(group => !group.First().MetaInformation.AllowMultiple && group.Count() > 1);
issues.AddRange(duplicateAnnotations.Select(duplicate =>
{
var result = new DeclarationInspectionResult(
this, string.Format(InspectionResults.DuplicatedAnnotationInspection, duplicate.Key.ToString()), declaration);
result.Properties.AnnotationType = duplicate.Key;
return result;
}));
}
return issues;
}
}
}