-
Notifications
You must be signed in to change notification settings - Fork 45
/
SampleQuickFix.cs
50 lines (40 loc) · 1.54 KB
/
SampleQuickFix.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
using System;
using System.Collections.Generic;
using JetBrains.Application.Progress;
using JetBrains.Diagnostics;
using JetBrains.ProjectModel;
using JetBrains.ReSharper.Feature.Services.QuickFixes;
using JetBrains.ReSharper.Psi.CSharp.Tree;
using JetBrains.ReSharper.Psi.Resolve;
using JetBrains.ReSharper.Psi.Search;
using JetBrains.TextControl;
using JetBrains.Util;
namespace ReSharperPlugin.CodeInspections;
public class SampleQuickFix : QuickFixBase
{
private readonly ICSharpDeclaration _declaration;
public SampleQuickFix(ICSharpDeclaration declaration)
{
_declaration = declaration;
}
public override string Text => Resources.SampleQuickFixText;
public override bool IsAvailable(IUserDataHolder cache)
{
return _declaration.IsValid();
}
protected override Action<ITextControl> ExecutePsiTransaction(ISolution solution, IProgressIndicator progress)
{
var declaredElement = _declaration.DeclaredElement.NotNull();
var psiServices = _declaration.GetPsiServices();
var references = new List<IReference>();
psiServices.Finder.FindReferences(
declaredElement,
domain: psiServices.SearchDomainFactory.CreateSearchDomain(_declaration),
consumer: references.ConsumeReferences(),
NullProgressIndicator.Create());
_declaration.SetName(_declaration.NameIdentifier.NotNull().Name.ToUpperInvariant());
foreach (var reference in references)
reference.BindTo(declaredElement);
return null;
}
}