Skip to content

Commit 48b02db

Browse files
authored
Merge pull request #3350 from Hosch250/quickFixes
Inspection quickfixes are now being added dynamically.
2 parents c40927f + fed718c commit 48b02db

File tree

141 files changed

+1012
-1883
lines changed

Some content is hidden

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

141 files changed

+1012
-1883
lines changed

RetailCoder.VBE/Rubberduck.csproj

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
<NoWarn>1591</NoWarn>
3030
<PlatformTarget>AnyCPU</PlatformTarget>
3131
<UseVSHostingProcess>true</UseVSHostingProcess>
32+
<LangVersion>7.1</LangVersion>
3233
</PropertyGroup>
3334
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
3435
<DebugType>full</DebugType>
@@ -41,6 +42,7 @@
4142
<DocumentationFile>bin\Release\Rubberduck.XML</DocumentationFile>
4243
<DebugSymbols>true</DebugSymbols>
4344
<NoWarn>1591</NoWarn>
45+
<LangVersion>7.1</LangVersion>
4446
</PropertyGroup>
4547
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'DebugAccess|AnyCPU'">
4648
<DebugSymbols>true</DebugSymbols>
@@ -54,6 +56,7 @@
5456
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
5557
<WarningLevel>4</WarningLevel>
5658
<Optimize>false</Optimize>
59+
<LangVersion>7.1</LangVersion>
5760
</PropertyGroup>
5861
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
5962
<DebugSymbols>true</DebugSymbols>
@@ -151,6 +154,7 @@
151154
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
152155
<WarningLevel>4</WarningLevel>
153156
<Optimize>false</Optimize>
157+
<LangVersion>7.1</LangVersion>
154158
</PropertyGroup>
155159
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug64|x64'">
156160
<DebugSymbols>true</DebugSymbols>
@@ -191,6 +195,7 @@
191195
<ErrorReport>prompt</ErrorReport>
192196
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
193197
<WarningLevel>4</WarningLevel>
198+
<LangVersion>7.1</LangVersion>
194199
</PropertyGroup>
195200
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release64|x64'">
196201
<DebugSymbols>true</DebugSymbols>
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using NLog;
5+
using Rubberduck.Parsing.Inspections.Abstract;
6+
using Rubberduck.Parsing.VBA;
7+
8+
namespace Rubberduck.Inspections.Abstract
9+
{
10+
public abstract class QuickFixBase : IQuickFix
11+
{
12+
private readonly ILogger _logger = LogManager.GetCurrentClassLogger();
13+
private HashSet<Type> _supportedInspections;
14+
public IReadOnlyCollection<Type> SupportedInspections => _supportedInspections.ToList();
15+
16+
protected QuickFixBase(params Type[] inspections)
17+
{
18+
RegisterInspections(inspections);
19+
}
20+
21+
public void RegisterInspections(params Type[] inspections)
22+
{
23+
if (!inspections.All(s => s.GetInterfaces().Any(a => a == typeof(IInspection))))
24+
{
25+
#if DEBUG
26+
throw new ArgumentException($"Parameters must implement {nameof(IInspection)}", nameof(inspections));
27+
#else
28+
inspections.Where(s => s.GetInterfaces().All(i => i != typeof(IInspection))).ToList()
29+
.ForEach(i => _logger.Error($"Type {i.Name} does not implement {nameof(IInspection)}"));
30+
#endif
31+
}
32+
33+
_supportedInspections = inspections.ToHashSet();
34+
}
35+
36+
public void RemoveInspections(params Type[] inspections)
37+
{
38+
_supportedInspections = _supportedInspections.Except(inspections).ToHashSet();
39+
}
40+
41+
public abstract void Fix(IInspectionResult result);
42+
public abstract string Description(IInspectionResult result);
43+
44+
public abstract bool CanFixInProcedure { get; }
45+
public abstract bool CanFixInModule { get; }
46+
public abstract bool CanFixInProject { get; }
47+
}
48+
}

Rubberduck.Inspections/Concrete/EmptyCaseBlockInspection.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ namespace Rubberduck.Inspections.Concrete
1414
internal class EmptyCaseBlockInspection : ParseTreeInspectionBase
1515
{
1616
public EmptyCaseBlockInspection(RubberduckParserState state)
17-
: base(state, CodeInspectionSeverity.Suggestion) { }
17+
: base(state, CodeInspectionSeverity.DoNotShow) { }
1818

1919
public override IInspectionListener Listener { get; } =
2020
new EmptyCaseBlockListener();

Rubberduck.Inspections/Concrete/EmptyElseBlockInspection.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ namespace Rubberduck.Inspections.Concrete
1414
internal class EmptyElseBlockInspection : ParseTreeInspectionBase
1515
{
1616
public EmptyElseBlockInspection(RubberduckParserState state)
17-
: base(state, CodeInspectionSeverity.Suggestion) { }
17+
: base(state, CodeInspectionSeverity.DoNotShow) { }
1818

1919
public override Type Type => typeof(EmptyElseBlockInspection);
2020

Rubberduck.Inspections/Concrete/EmptyForEachBlockInspection.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ namespace Rubberduck.Inspections.Concrete
1414
internal class EmptyForEachBlockInspection : ParseTreeInspectionBase
1515
{
1616
public EmptyForEachBlockInspection(RubberduckParserState state)
17-
: base(state, CodeInspectionSeverity.Suggestion) { }
17+
: base(state, CodeInspectionSeverity.DoNotShow) { }
1818

1919
public override Type Type => typeof(EmptyForEachBlockInspection);
2020

Rubberduck.Inspections/Concrete/EmptyForLoopBlockInspection.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ namespace Rubberduck.Inspections.Concrete
1414
internal class EmptyForLoopBlockInspection : ParseTreeInspectionBase
1515
{
1616
public EmptyForLoopBlockInspection(RubberduckParserState state)
17-
: base(state, CodeInspectionSeverity.Suggestion) { }
17+
: base(state, CodeInspectionSeverity.DoNotShow) { }
1818

1919
public override Type Type => typeof(EmptyForLoopBlockInspection);
2020

Rubberduck.Inspections/Concrete/EmptyIfBlockInspection.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ namespace Rubberduck.Inspections.Concrete
1616
internal class EmptyIfBlockInspection : ParseTreeInspectionBase
1717
{
1818
public EmptyIfBlockInspection(RubberduckParserState state)
19-
: base(state, CodeInspectionSeverity.Suggestion) { }
19+
: base(state, CodeInspectionSeverity.DoNotShow) { }
2020

2121
public override Type Type => typeof(EmptyIfBlockInspection);
2222

Rubberduck.Inspections/Concrete/EmptyWhileWendBlockInspection.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ namespace Rubberduck.Inspections.Concrete
1414
internal class EmptyWhileWendBlockInspection : ParseTreeInspectionBase
1515
{
1616
public EmptyWhileWendBlockInspection(RubberduckParserState state)
17-
: base(state, CodeInspectionSeverity.Suggestion) { }
17+
: base(state, CodeInspectionSeverity.DoNotShow) { }
1818

1919
public override Type Type => typeof(EmptyWhileWendBlockInspection);
2020

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
using System;
2-
using System.Collections.Generic;
31
using System.Linq;
2+
using Rubberduck.Inspections.Abstract;
43
using Rubberduck.Inspections.Concrete;
54
using Rubberduck.Parsing.Inspections.Abstract;
65
using Rubberduck.Parsing.Inspections.Resources;
@@ -9,23 +8,17 @@
98

109
namespace Rubberduck.Inspections.QuickFixes
1110
{
12-
public sealed class AddIdentifierToWhiteListQuickFix : IQuickFix
11+
public sealed class AddIdentifierToWhiteListQuickFix : QuickFixBase
1312
{
1413
private readonly IPersistanceService<CodeInspectionSettings> _settings;
15-
private static readonly HashSet<Type> _supportedInspections = new HashSet<Type>
16-
{
17-
typeof(HungarianNotationInspection),
18-
typeof(UseMeaningfulNameInspection)
19-
};
2014

2115
public AddIdentifierToWhiteListQuickFix(IPersistanceService<CodeInspectionSettings> settings)
16+
: base(typeof(HungarianNotationInspection), typeof(UseMeaningfulNameInspection))
2217
{
2318
_settings = settings;
2419
}
2520

26-
public IReadOnlyCollection<Type> SupportedInspections => _supportedInspections.ToList();
27-
28-
public void Fix(IInspectionResult result)
21+
public override void Fix(IInspectionResult result)
2922
{
3023
var inspectionSettings = _settings.Load(new CodeInspectionSettings()) ?? new CodeInspectionSettings();
3124
var whitelist = inspectionSettings.WhitelistedIdentifiers;
@@ -34,13 +27,13 @@ public void Fix(IInspectionResult result)
3427
_settings.Save(inspectionSettings);
3528
}
3629

37-
public string Description(IInspectionResult result)
30+
public override string Description(IInspectionResult result)
3831
{
3932
return InspectionsUI.WhiteListIdentifierQuickFix;
4033
}
4134

42-
public bool CanFixInProcedure { get; } = false;
43-
public bool CanFixInModule { get; } = false;
44-
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;
4538
}
4639
}
Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,34 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
1+
using Rubberduck.Inspections.Abstract;
42
using Rubberduck.Inspections.Concrete;
53
using Rubberduck.Parsing.Inspections.Abstract;
64
using Rubberduck.Parsing.Inspections.Resources;
75
using Rubberduck.Parsing.VBA;
86

97
namespace Rubberduck.Inspections.QuickFixes
108
{
11-
public sealed class ApplicationWorksheetFunctionQuickFix : IQuickFix
9+
public sealed class ApplicationWorksheetFunctionQuickFix : QuickFixBase
1210
{
1311
private readonly RubberduckParserState _state;
14-
private static readonly HashSet<Type> _supportedInspections = new HashSet<Type> {typeof(ApplicationWorksheetFunctionInspection) };
1512

1613
public ApplicationWorksheetFunctionQuickFix(RubberduckParserState state)
14+
: base(typeof(ApplicationWorksheetFunctionInspection))
1715
{
1816
_state = state;
1917
}
20-
21-
public IReadOnlyCollection<Type> SupportedInspections => _supportedInspections.ToList();
2218

23-
public void Fix(IInspectionResult result)
19+
public override void Fix(IInspectionResult result)
2420
{
2521
var rewriter = _state.GetRewriter(result.QualifiedSelection.QualifiedName);
2622
rewriter.InsertBefore(result.Context.Start.TokenIndex, "WorksheetFunction.");
2723
}
2824

29-
public string Description(IInspectionResult result)
25+
public override string Description(IInspectionResult result)
3026
{
3127
return InspectionsUI.ApplicationWorksheetFunctionQuickFix;
3228
}
3329

34-
public bool CanFixInProcedure { get; } = true;
35-
public bool CanFixInModule { get; } = true;
36-
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;
3733
}
3834
}

0 commit comments

Comments
 (0)