Skip to content

Commit 51e8f88

Browse files
committed
Change APIs to use Type instead of IInspection
1 parent efc2b99 commit 51e8f88

File tree

90 files changed

+584
-555
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

90 files changed

+584
-555
lines changed

Rubberduck.Inspections/Abstract/QuickFixBase.cs

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,36 @@
66

77
namespace Rubberduck.Inspections.Abstract
88
{
9-
public class QuickFixBase
9+
public abstract class QuickFixBase : IQuickFix
1010
{
11-
private HashSet<Type> _supportedInspections = new HashSet<Type>();
11+
private HashSet<Type> _supportedInspections;
1212
public IReadOnlyCollection<Type> SupportedInspections => _supportedInspections.ToList();
1313

14-
public void RemoveInspections(params IInspection[] inspections)
14+
protected QuickFixBase(params Type[] inspections)
1515
{
16-
_supportedInspections = _supportedInspections.Except(inspections.Select(s => s.Type)).ToHashSet();
16+
RegisterInspections(inspections);
1717
}
1818

19-
public void RegisterInspections(params IInspection[] inspections)
19+
public void RegisterInspections(params Type[] inspections)
2020
{
21-
_supportedInspections = inspections.Where(w => w != null).Select(s => s.Type).ToHashSet();
21+
if (!inspections.All(s => s.GetInterfaces().Any(a => a == typeof(IInspection))))
22+
{
23+
throw new ArgumentException($"Parameters must implement {nameof(IInspection)}", nameof(inspections));
24+
}
25+
26+
_supportedInspections = inspections.ToHashSet();
27+
}
28+
29+
public void RemoveInspections(params Type[] inspections)
30+
{
31+
_supportedInspections = _supportedInspections.Except(inspections).ToHashSet();
2232
}
33+
34+
public abstract void Fix(IInspectionResult result);
35+
public abstract string Description(IInspectionResult result);
36+
37+
public abstract bool CanFixInProcedure { get; }
38+
public abstract bool CanFixInModule { get; }
39+
public abstract bool CanFixInProject { get; }
2340
}
2441
}

Rubberduck.Inspections/InspectionLocator.cs

Lines changed: 0 additions & 21 deletions
This file was deleted.

Rubberduck.Inspections/QuickFixes/AddIdentifierToWhiteListQuickFix.cs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,17 @@
88

99
namespace Rubberduck.Inspections.QuickFixes
1010
{
11-
public sealed class AddIdentifierToWhiteListQuickFix : QuickFixBase, IQuickFix
11+
public sealed class AddIdentifierToWhiteListQuickFix : QuickFixBase
1212
{
1313
private readonly IPersistanceService<CodeInspectionSettings> _settings;
1414

15-
public AddIdentifierToWhiteListQuickFix(IPersistanceService<CodeInspectionSettings> settings, InspectionLocator inspectionLocator)
15+
public AddIdentifierToWhiteListQuickFix(IPersistanceService<CodeInspectionSettings> settings)
16+
: base(typeof(HungarianNotationInspection), typeof(UseMeaningfulNameInspection))
1617
{
1718
_settings = settings;
18-
RegisterInspections(inspectionLocator.GetInspection<HungarianNotationInspection>(),
19-
inspectionLocator.GetInspection<UseMeaningfulNameInspection>());
2019
}
2120

22-
public void Fix(IInspectionResult result)
21+
public override void Fix(IInspectionResult result)
2322
{
2423
var inspectionSettings = _settings.Load(new CodeInspectionSettings()) ?? new CodeInspectionSettings();
2524
var whitelist = inspectionSettings.WhitelistedIdentifiers;
@@ -28,13 +27,13 @@ public void Fix(IInspectionResult result)
2827
_settings.Save(inspectionSettings);
2928
}
3029

31-
public string Description(IInspectionResult result)
30+
public override string Description(IInspectionResult result)
3231
{
3332
return InspectionsUI.WhiteListIdentifierQuickFix;
3433
}
3534

36-
public bool CanFixInProcedure { get; } = false;
37-
public bool CanFixInModule { get; } = false;
38-
public bool CanFixInProject { get; } = false;
35+
public override bool CanFixInProcedure { get; } = false;
36+
public override bool CanFixInModule { get; } = false;
37+
public override bool CanFixInProject { get; } = false;
3938
}
4039
}

Rubberduck.Inspections/QuickFixes/ApplicationWorksheetFunctionQuickFix.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,29 +6,29 @@
66

77
namespace Rubberduck.Inspections.QuickFixes
88
{
9-
public sealed class ApplicationWorksheetFunctionQuickFix : QuickFixBase, IQuickFix
9+
public sealed class ApplicationWorksheetFunctionQuickFix : QuickFixBase
1010
{
1111
private readonly RubberduckParserState _state;
1212

13-
public ApplicationWorksheetFunctionQuickFix(RubberduckParserState state, InspectionLocator inspectionLocator)
13+
public ApplicationWorksheetFunctionQuickFix(RubberduckParserState state)
14+
: base(typeof(ApplicationWorksheetFunctionInspection))
1415
{
1516
_state = state;
16-
RegisterInspections(inspectionLocator.GetInspection<ApplicationWorksheetFunctionInspection>());
1717
}
1818

19-
public void Fix(IInspectionResult result)
19+
public override void Fix(IInspectionResult result)
2020
{
2121
var rewriter = _state.GetRewriter(result.QualifiedSelection.QualifiedName);
2222
rewriter.InsertBefore(result.Context.Start.TokenIndex, "WorksheetFunction.");
2323
}
2424

25-
public string Description(IInspectionResult result)
25+
public override string Description(IInspectionResult result)
2626
{
2727
return InspectionsUI.ApplicationWorksheetFunctionQuickFix;
2828
}
2929

30-
public bool CanFixInProcedure { get; } = true;
31-
public bool CanFixInModule { get; } = true;
32-
public bool CanFixInProject { get; } = true;
30+
public override bool CanFixInProcedure { get; } = true;
31+
public override bool CanFixInModule { get; } = true;
32+
public override bool CanFixInProject { get; } = true;
3333
}
3434
}

Rubberduck.Inspections/QuickFixes/AssignedByValParameterMakeLocalCopyQuickFix.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,19 @@
1616

1717
namespace Rubberduck.Inspections.QuickFixes
1818
{
19-
public sealed class AssignedByValParameterMakeLocalCopyQuickFix : QuickFixBase, IQuickFix
19+
public sealed class AssignedByValParameterMakeLocalCopyQuickFix : QuickFixBase
2020
{
2121
private readonly IAssignedByValParameterQuickFixDialogFactory _dialogFactory;
2222
private readonly RubberduckParserState _parserState;
2323

24-
public AssignedByValParameterMakeLocalCopyQuickFix(RubberduckParserState state, InspectionLocator inspectionLocator, IAssignedByValParameterQuickFixDialogFactory dialogFactory)
24+
public AssignedByValParameterMakeLocalCopyQuickFix(RubberduckParserState state, IAssignedByValParameterQuickFixDialogFactory dialogFactory)
25+
: base(typeof(AssignedByValParameterInspection))
2526
{
2627
_dialogFactory = dialogFactory;
2728
_parserState = state;
28-
RegisterInspections(inspectionLocator.GetInspection<AssignedByValParameterInspection>());
2929
}
3030

31-
public void Fix(IInspectionResult result)
31+
public override void Fix(IInspectionResult result)
3232
{
3333
var forbiddenNames = _parserState.DeclarationFinder.GetDeclarationsWithIdentifiersToAvoid(result.Target).Select(n => n.IdentifierName);
3434

@@ -43,14 +43,14 @@ public void Fix(IInspectionResult result)
4343
InsertLocalVariableDeclarationAndAssignment(rewriter, result.Target, localIdentifier);
4444
}
4545

46-
public string Description(IInspectionResult result)
46+
public override string Description(IInspectionResult result)
4747
{
4848
return InspectionsUI.AssignedByValParameterMakeLocalCopyQuickFix;
4949
}
5050

51-
public bool CanFixInProcedure { get; } = false;
52-
public bool CanFixInModule { get; } = false;
53-
public bool CanFixInProject { get; } = false;
51+
public override bool CanFixInProcedure { get; } = false;
52+
public override bool CanFixInModule { get; } = false;
53+
public override bool CanFixInProject { get; } = false;
5454

5555
private string PromptForLocalVariableName(Declaration target, List<string> forbiddenNames)
5656
{

Rubberduck.Inspections/QuickFixes/ChangeDimToPrivateQuickFix.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,31 +7,31 @@
77

88
namespace Rubberduck.Inspections.QuickFixes
99
{
10-
public sealed class ChangeDimToPrivateQuickFix : QuickFixBase, IQuickFix
10+
public sealed class ChangeDimToPrivateQuickFix : QuickFixBase
1111
{
1212
private readonly RubberduckParserState _state;
1313

14-
public ChangeDimToPrivateQuickFix(RubberduckParserState state, InspectionLocator inspectionLocator)
14+
public ChangeDimToPrivateQuickFix(RubberduckParserState state)
15+
: base(typeof(ModuleScopeDimKeywordInspection))
1516
{
1617
_state = state;
17-
RegisterInspections(inspectionLocator.GetInspection<ModuleScopeDimKeywordInspection>());
1818
}
1919

20-
public void Fix(IInspectionResult result)
20+
public override void Fix(IInspectionResult result)
2121
{
2222
var rewriter = _state.GetRewriter(result.QualifiedSelection.QualifiedName);
2323

2424
var context = (VBAParser.VariableStmtContext)result.Context.Parent.Parent;
2525
rewriter.Replace(context.DIM(), Tokens.Private);
2626
}
2727

28-
public string Description(IInspectionResult result)
28+
public override string Description(IInspectionResult result)
2929
{
3030
return InspectionsUI.ChangeDimToPrivateQuickFix;
3131
}
3232

33-
public bool CanFixInProcedure { get; } = false;
34-
public bool CanFixInModule { get; } = true;
35-
public bool CanFixInProject { get; } = true;
33+
public override bool CanFixInProcedure { get; } = false;
34+
public override bool CanFixInModule { get; } = true;
35+
public override bool CanFixInProject { get; } = true;
3636
}
3737
}

Rubberduck.Inspections/QuickFixes/ChangeIntegerToLongQuickFix.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,17 @@
1313

1414
namespace Rubberduck.Inspections.QuickFixes
1515
{
16-
public class ChangeIntegerToLongQuickFix : QuickFixBase, IQuickFix
16+
public class ChangeIntegerToLongQuickFix : QuickFixBase
1717
{
1818
private readonly RubberduckParserState _state;
1919

20-
public ChangeIntegerToLongQuickFix(RubberduckParserState state, InspectionLocator inspectionLocator)
20+
public ChangeIntegerToLongQuickFix(RubberduckParserState state)
21+
: base(typeof(IntegerDataTypeInspection))
2122
{
2223
_state = state;
23-
RegisterInspections(inspectionLocator.GetInspection<IntegerDataTypeInspection>());
2424
}
2525

26-
public void Fix(IInspectionResult result)
26+
public override void Fix(IInspectionResult result)
2727
{
2828
var rewriter = _state.GetRewriter(result.Target);
2929

@@ -181,14 +181,14 @@ public void Fix(IInspectionResult result)
181181
}
182182
}
183183

184-
public string Description(IInspectionResult result)
184+
public override string Description(IInspectionResult result)
185185
{
186186
return InspectionsUI.IntegerDataTypeQuickFix;
187187
}
188188

189-
public bool CanFixInProcedure => true;
190-
public bool CanFixInModule => true;
191-
public bool CanFixInProject => true;
189+
public override bool CanFixInProcedure => true;
190+
public override bool CanFixInModule => true;
191+
public override bool CanFixInProject => true;
192192

193193
private static int GetParameterIndex(VBAParser.ArgContext context)
194194
{

Rubberduck.Inspections/QuickFixes/ChangeProcedureToFunctionQuickFix.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,17 @@
1010

1111
namespace Rubberduck.Inspections.QuickFixes
1212
{
13-
public sealed class ChangeProcedureToFunctionQuickFix : QuickFixBase, IQuickFix
13+
public sealed class ChangeProcedureToFunctionQuickFix : QuickFixBase
1414
{
1515
private readonly RubberduckParserState _state;
1616

17-
public ChangeProcedureToFunctionQuickFix(RubberduckParserState state, InspectionLocator inspectionLocator)
17+
public ChangeProcedureToFunctionQuickFix(RubberduckParserState state)
18+
: base(typeof(ProcedureCanBeWrittenAsFunctionInspection))
1819
{
1920
_state = state;
20-
RegisterInspections(inspectionLocator.GetInspection<ProcedureCanBeWrittenAsFunctionInspection>());
2121
}
2222

23-
public void Fix(IInspectionResult result)
23+
public override void Fix(IInspectionResult result)
2424
{
2525
var parameterizedDeclaration = (IParameterizedDeclaration) result.Target;
2626
var arg = parameterizedDeclaration.Parameters.Cast<ParameterDeclaration>().First(p => p.IsByRef || p.IsImplicitByRef);
@@ -33,7 +33,7 @@ public void Fix(IInspectionResult result)
3333
}
3434
}
3535

36-
public string Description(IInspectionResult result)
36+
public override string Description(IInspectionResult result)
3737
{
3838
return InspectionsUI.ProcedureShouldBeFunctionInspectionQuickFix;
3939
}
@@ -77,8 +77,8 @@ private void UpdateCall(IdentifierReference reference, int argIndex)
7777
rewriter.InsertAfter(argListContext.Stop.TokenIndex, ")");
7878
}
7979

80-
public bool CanFixInProcedure => false;
81-
public bool CanFixInModule => false;
82-
public bool CanFixInProject => false;
80+
public override bool CanFixInProcedure => false;
81+
public override bool CanFixInModule => false;
82+
public override bool CanFixInProject => false;
8383
}
8484
}

Rubberduck.Inspections/QuickFixes/ConvertToProcedureQuickFix.cs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,17 @@
1111

1212
namespace Rubberduck.Inspections.QuickFixes
1313
{
14-
public sealed class ConvertToProcedureQuickFix : QuickFixBase, IQuickFix
14+
public sealed class ConvertToProcedureQuickFix : QuickFixBase
1515
{
1616
private readonly RubberduckParserState _state;
1717

18-
public ConvertToProcedureQuickFix(RubberduckParserState state, InspectionLocator inspectionLocator)
18+
public ConvertToProcedureQuickFix(RubberduckParserState state)
19+
: base(typeof(NonReturningFunctionInspection), typeof(FunctionReturnValueNotUsedInspection))
1920
{
2021
_state = state;
21-
RegisterInspections(inspectionLocator.GetInspection<NonReturningFunctionInspection>(),
22-
inspectionLocator.GetInspection<FunctionReturnValueNotUsedInspection>());
2322
}
2423

25-
public void Fix(IInspectionResult result)
24+
public override void Fix(IInspectionResult result)
2625
{
2726
switch (result.Context)
2827
{
@@ -85,14 +84,14 @@ private void ConvertPropertyGet(IInspectionResult result, VBAParser.PropertyGetS
8584
}
8685
}
8786

88-
public string Description(IInspectionResult result)
87+
public override string Description(IInspectionResult result)
8988
{
9089
return InspectionsUI.ConvertFunctionToProcedureQuickFix;
9190
}
9291

93-
public bool CanFixInProcedure => false;
94-
public bool CanFixInModule => true;
95-
public bool CanFixInProject => false;
92+
public override bool CanFixInProcedure => false;
93+
public override bool CanFixInModule => true;
94+
public override bool CanFixInProject => false;
9695

9796
private IEnumerable<ParserRuleContext> GetReturnStatements(Declaration declaration)
9897
{

Rubberduck.Inspections/QuickFixes/DeclareAsExplicitVariantQuickFix.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,17 @@
88

99
namespace Rubberduck.Inspections.QuickFixes
1010
{
11-
public sealed class DeclareAsExplicitVariantQuickFix : QuickFixBase, IQuickFix
11+
public sealed class DeclareAsExplicitVariantQuickFix : QuickFixBase
1212
{
1313
private readonly RubberduckParserState _state;
1414

15-
public DeclareAsExplicitVariantQuickFix(RubberduckParserState state, InspectionLocator inspectionLocator)
15+
public DeclareAsExplicitVariantQuickFix(RubberduckParserState state)
16+
: base(typeof(VariableTypeNotDeclaredInspection))
1617
{
1718
_state = state;
18-
RegisterInspections(inspectionLocator.GetInspection<VariableTypeNotDeclaredInspection>());
1919
}
2020

21-
public void Fix(IInspectionResult result)
21+
public override void Fix(IInspectionResult result)
2222
{
2323
var rewriter = _state.GetRewriter(result.Target);
2424

@@ -29,13 +29,13 @@ result.Context is VBAParser.VariableSubStmtContext || result.Context is VBAParse
2929
rewriter.InsertAfter(identifierNode.Stop.TokenIndex, " As Variant");
3030
}
3131

32-
public string Description(IInspectionResult result)
32+
public override string Description(IInspectionResult result)
3333
{
3434
return InspectionsUI.DeclareAsExplicitVariantQuickFix;
3535
}
3636

37-
public bool CanFixInProcedure => true;
38-
public bool CanFixInModule => true;
39-
public bool CanFixInProject => true;
37+
public override bool CanFixInProcedure => true;
38+
public override bool CanFixInModule => true;
39+
public override bool CanFixInProject => true;
4040
}
4141
}

0 commit comments

Comments
 (0)