Skip to content

Commit b814cee

Browse files
committed
On local error inspection
1 parent b99aa13 commit b814cee

File tree

13 files changed

+207
-3
lines changed

13 files changed

+207
-3
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
using System.Collections.Generic;
2+
using System.Linq;
3+
using Antlr4.Runtime;
4+
using Rubberduck.Inspections.Abstract;
5+
using Rubberduck.Inspections.Results;
6+
using Rubberduck.Parsing;
7+
using Rubberduck.Parsing.Grammar;
8+
using Rubberduck.Parsing.Inspections.Abstract;
9+
using Rubberduck.Resources.Inspections;
10+
using Rubberduck.Parsing.VBA;
11+
using Rubberduck.VBEditor;
12+
using Antlr4.Runtime.Misc;
13+
14+
namespace Rubberduck.Inspections.Concrete
15+
{
16+
public sealed class OnLocalErrorInspection : ParseTreeInspectionBase
17+
{
18+
public OnLocalErrorInspection(RubberduckParserState state)
19+
: base(state) { }
20+
21+
public override IInspectionListener Listener { get; } =
22+
new OnLocalErrorListener();
23+
24+
protected override IEnumerable<IInspectionResult> DoGetInspectionResults()
25+
{
26+
return Listener.Contexts
27+
.Where(result => !IsIgnoringInspectionResultFor(result.ModuleName, result.Context.Start.Line))
28+
.Select(result => new QualifiedContextInspectionResult(this,
29+
InspectionResults.OnLocalErrorInspection,
30+
result));
31+
}
32+
33+
public class OnLocalErrorListener : VBAParserBaseListener, IInspectionListener
34+
{
35+
private readonly List<QualifiedContext<ParserRuleContext>> _contexts = new List<QualifiedContext<ParserRuleContext>>();
36+
public IReadOnlyList<QualifiedContext<ParserRuleContext>> Contexts => _contexts;
37+
38+
public QualifiedModuleName CurrentModuleName { get; set; }
39+
40+
public void ClearContexts()
41+
{
42+
_contexts.Clear();
43+
}
44+
45+
public override void ExitOnErrorStmt([NotNull] VBAParser.OnErrorStmtContext context)
46+
{
47+
if (context.ON_LOCAL_ERROR() != null)
48+
{
49+
_contexts.Add(new QualifiedContext<ParserRuleContext>(CurrentModuleName, context));
50+
}
51+
}
52+
}
53+
}
54+
}

Rubberduck.CodeAnalysis/Rubberduck.CodeAnalysis.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@
8181
<Compile Include="Inspections\Concrete\EmptyForEachBlockInspection.cs" />
8282
<Compile Include="Inspections\Concrete\EmptyForLoopBlockInspection.cs" />
8383
<Compile Include="Inspections\Concrete\BooleanAssignedInIfElseInspection.cs" />
84+
<Compile Include="Inspections\Concrete\OnLocalErrorInspection.cs" />
8485
<Compile Include="Inspections\Concrete\ModuleWithoutFolderInspection.cs" />
8586
<Compile Include="Inspections\Concrete\EmptyWhileWendBlockInspection.cs" />
8687
<Compile Include="Inspections\Concrete\ObsoleteCallingConventionInspection.cs" />

Rubberduck.Core/Properties/Settings.Designer.cs

Lines changed: 4 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Rubberduck.Core/Properties/Settings.settings

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,7 @@
280280
&lt;CodeInspection Name="ObsoleteCallingConventionInspection" Severity="Warning" InspectionType="CodeQualityIssues" /&gt;
281281
&lt;CodeInspection Name="DuplicatedAnnotationInspection" Severity="Error" InspectionType="RubberduckOpportunities" /&gt;
282282
&lt;CodeInspection Name="ModuleWithoutFolderInspection" Severity="Suggestion" InspectionType="RubberduckOpportunities" /&gt;
283+
&lt;CodeInspection Name="OnLocalErrorInspection" Severity="Suggestion" InspectionType="RubberduckOpportunities" /&gt;
283284
&lt;/CodeInspections&gt;
284285
&lt;WhitelistedIdentifiers /&gt;
285286
&lt;RunInspectionsOnSuccessfulParse&gt;true&lt;/RunInspectionsOnSuccessfulParse&gt;

Rubberduck.Core/app.config

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,8 @@
404404
InspectionType="RubberduckOpportunities" />
405405
<CodeInspection Name="ModuleWithoutFolderInspection" Severity="Suggestion"
406406
InspectionType="RubberduckOpportunities" />
407+
<CodeInspection Name="OnLocalErrorInspection" Severity="Suggestion"
408+
InspectionType="RubberduckOpportunities" />
407409
</CodeInspections>
408410
<WhitelistedIdentifiers />
409411
<RunInspectionsOnSuccessfulParse>true</RunInspectionsOnSuccessfulParse>

Rubberduck.Resources/Inspections/InspectionInfo.Designer.cs

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Rubberduck.Resources/Inspections/InspectionInfo.resx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,4 +337,7 @@ If the parameter can be null, ignore this inspection result; passing a null valu
337337
<data name="ModuleWithoutFolderInspection" xml:space="preserve">
338338
<value>Modules without the '@Folder' annotation cannot receive custom groupings in the Code Explorer. </value>
339339
</data>
340+
<data name="OnLocalErrorInspection" xml:space="preserve">
341+
<value>On Local Error exists only for compatibility with previous versions of Visual Basic, and all Errors are treated as Local regardless of the Error statement. Use of this keyword inaccurately gives the impression that there is a distinction between types of error handling when there is not.</value>
342+
</data>
340343
</root>

Rubberduck.Resources/Inspections/InspectionNames.Designer.cs

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Rubberduck.Resources/Inspections/InspectionNames.resx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,4 +336,7 @@
336336
<data name="ModuleWithoutFolderInspection" xml:space="preserve">
337337
<value>Module without '@Folder' annotation</value>
338338
</data>
339+
<data name="OnLocalErrorInspection" xml:space="preserve">
340+
<value>On Local Error statement</value>
341+
</data>
339342
</root>

Rubberduck.Resources/Inspections/InspectionResults.Designer.cs

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)