/
EmptyWhileWendBlockInspection.cs
61 lines (57 loc) · 2.07 KB
/
EmptyWhileWendBlockInspection.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
51
52
53
54
55
56
57
58
59
60
61
using Antlr4.Runtime.Misc;
using Rubberduck.CodeAnalysis.Inspections.Abstract;
using Rubberduck.Parsing;
using Rubberduck.Parsing.Grammar;
using Rubberduck.Parsing.VBA;
using Rubberduck.Resources.Inspections;
namespace Rubberduck.CodeAnalysis.Inspections.Concrete
{
/// <summary>
/// Identifies empty 'While...Wend' blocks that can be safely removed.
/// </summary>
/// <why>
/// Dead code should be removed. A loop without a body is usually redundant.
/// </why>
/// <example hasResult="true">
/// <module name="MyModule" type="Standard Module">
/// <![CDATA[
/// Public Sub DoSomething(ByVal foo As Long)
/// While foo < 100
/// 'no executable statements... would be an infinite loop if entered
/// Wend
/// End Sub
/// ]]>
/// </module>
/// </example>
/// <example hasResult="false">
/// <module name="MyModule" type="Standard Module">
/// <![CDATA[
/// Public Sub DoSomething(ByVal foo As Long)
/// While foo < 100
/// foo = foo + 1
/// Wend
/// End Sub
/// ]]>
/// </module>
/// </example>
internal sealed class EmptyWhileWendBlockInspection : EmptyBlockInspectionBase<VBAParser.WhileWendStmtContext>
{
public EmptyWhileWendBlockInspection(IDeclarationFinderProvider declarationFinderProvider)
: base(declarationFinderProvider)
{
ContextListener = new EmptyWhileWendBlockListener();
}
protected override IInspectionListener<VBAParser.WhileWendStmtContext> ContextListener { get; }
protected override string ResultDescription(QualifiedContext<VBAParser.WhileWendStmtContext> context)
{
return InspectionResults.EmptyWhileWendBlockInspection;
}
private class EmptyWhileWendBlockListener : EmptyBlockInspectionListenerBase
{
public override void EnterWhileWendStmt([NotNull] VBAParser.WhileWendStmtContext context)
{
InspectBlockForExecutableStatements(context.block(), context);
}
}
}
}