Skip to content

Commit c40927f

Browse files
authored
Merge pull request #3404 from IvenBach/next
Consolidates "empty conditional block" inspections.
2 parents 8945bfc + 7b59242 commit c40927f

File tree

3 files changed

+2173
-0
lines changed

3 files changed

+2173
-0
lines changed
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using Rubberduck.Inspections.Abstract;
5+
using Rubberduck.Parsing.Inspections.Abstract;
6+
using Rubberduck.Parsing.Inspections.Resources;
7+
using Antlr4.Runtime;
8+
using Antlr4.Runtime.Misc;
9+
using Rubberduck.Parsing.Grammar;
10+
using Rubberduck.Parsing;
11+
using Rubberduck.Parsing.VBA;
12+
using Rubberduck.Inspections.Results;
13+
14+
namespace Rubberduck.Inspections.Concrete
15+
{
16+
17+
internal class EmptyConditionBlockInspection : ParseTreeInspectionBase
18+
{
19+
public EmptyConditionBlockInspection(RubberduckParserState state)
20+
: base(state, CodeInspectionSeverity.Suggestion) { }
21+
22+
public override Type Type => typeof(EmptyConditionBlockInspection);
23+
24+
public override IEnumerable<IInspectionResult> GetInspectionResults()
25+
{
26+
return Listener.Contexts
27+
.Where(result => !IsIgnoringInspectionResultFor(result.ModuleName, result.Context.Start.Line))
28+
.Select(result => new QualifiedContextInspectionResult(this,
29+
InspectionsUI.EmptyConditionBlockInspectionsResultFormat,
30+
result));
31+
}
32+
33+
public override IInspectionListener Listener { get; } =
34+
new EmptyConditionBlockListener();
35+
36+
public class EmptyConditionBlockListener : EmptyBlockInspectionListenerBase
37+
{
38+
public override void EnterIfStmt([NotNull] VBAParser.IfStmtContext context)
39+
{
40+
InspectBlockForExecutableStatements(context.block(), context);
41+
}
42+
43+
public override void EnterElseIfBlock([NotNull] VBAParser.ElseIfBlockContext context)
44+
{
45+
InspectBlockForExecutableStatements(context.block(), context);
46+
}
47+
48+
public override void EnterSingleLineIfStmt([NotNull] VBAParser.SingleLineIfStmtContext context)
49+
{
50+
AddResult(new QualifiedContext<ParserRuleContext>(CurrentModuleName, context.ifWithEmptyThen()));
51+
}
52+
53+
public override void EnterElseBlock([NotNull] VBAParser.ElseBlockContext context)
54+
{
55+
InspectBlockForExecutableStatements(context.block(), context);
56+
}
57+
}
58+
}
59+
}

0 commit comments

Comments
 (0)