/
RemoveDuplicatedAnnotationQuickFix.cs
38 lines (32 loc) · 1.4 KB
/
RemoveDuplicatedAnnotationQuickFix.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
using System.Linq;
using Rubberduck.Inspections.Abstract;
using Rubberduck.Inspections.Concrete;
using Rubberduck.Parsing.Inspections.Abstract;
using Rubberduck.Parsing.Rewriter;
using Rubberduck.Parsing.VBA;
namespace Rubberduck.Inspections.QuickFixes
{
public sealed class RemoveDuplicatedAnnotationQuickFix : QuickFixBase
{
private readonly IAnnotationUpdater _annotationUpdater;
public RemoveDuplicatedAnnotationQuickFix(IAnnotationUpdater annotationUpdater)
: base(typeof(DuplicatedAnnotationInspection))
{
_annotationUpdater = annotationUpdater;
}
public override void Fix(IInspectionResult result, IRewriteSession rewriteSession)
{
var duplicateAnnotations = result.Target.Annotations
.Where(annotation => annotation.GetType() == result.Properties.AnnotationType)
.OrderBy(annotation => annotation.Context.Start.StartIndex)
.Skip(1)
.ToList();
_annotationUpdater.RemoveAnnotations(rewriteSession, duplicateAnnotations);
}
public override string Description(IInspectionResult result) =>
Resources.Inspections.QuickFixes.RemoveDuplicatedAnnotationQuickFix;
public override bool CanFixInProcedure => true;
public override bool CanFixInModule => true;
public override bool CanFixInProject => true;
}
}