-
Notifications
You must be signed in to change notification settings - Fork 295
/
ObsoleteWhileWendStatementInspection.cs
77 lines (69 loc) · 2.56 KB
/
ObsoleteWhileWendStatementInspection.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
using Rubberduck.Inspections.Abstract;
using System.Collections.Generic;
using System.Linq;
using Antlr4.Runtime;
using Rubberduck.Inspections.Inspections.Extensions;
using Rubberduck.Inspections.Results;
using Rubberduck.Parsing;
using Rubberduck.Parsing.Grammar;
using Rubberduck.Parsing.Inspections.Abstract;
using Rubberduck.Parsing.VBA;
using Rubberduck.Resources.Inspections;
using Rubberduck.VBEditor;
namespace Rubberduck.CodeAnalysis.Inspections.Concrete
{
/// <summary>
/// Flags 'While...Wend' loops as obsolete.
/// </summary>
/// <why>
/// 'While...Wend' loops were made obsolete when 'Do While...Loop' statements were introduced.
/// 'While...Wend' loops cannot be exited early without a GoTo jump; 'Do...Loop' statements can be conditionally exited with 'Exit Do'.
/// </why>
/// <example hasresult="true">
/// <![CDATA[
/// Public Sub DoSomething()
/// While True
/// ' ...
/// Wend
/// End Sub
/// ]]>
/// </example>
/// <example hasresult="false">
/// <![CDATA[
/// Public Sub DoSomething()
/// Do While True
/// ' ...
/// Loop
/// End Sub
/// ]]>
/// </example>
public sealed class ObsoleteWhileWendStatementInspection : ParseTreeInspectionBase
{
public ObsoleteWhileWendStatementInspection(RubberduckParserState state)
: base(state)
{
Listener = new ObsoleteWhileWendStatementListener();
}
public override IInspectionListener Listener { get; }
protected override IEnumerable<IInspectionResult> DoGetInspectionResults()
{
return Listener.Contexts
.Select(context => new QualifiedContextInspectionResult(this, InspectionResults.ObsoleteWhileWendStatementInspection, context));
}
public class ObsoleteWhileWendStatementListener : VBAParserBaseListener, IInspectionListener
{
private readonly List<QualifiedContext<ParserRuleContext>> _contexts =
new List<QualifiedContext<ParserRuleContext>>();
public IReadOnlyList<QualifiedContext<ParserRuleContext>> Contexts => _contexts;
public QualifiedModuleName CurrentModuleName { get; set; }
public void ClearContexts()
{
_contexts.Clear();
}
public override void ExitWhileWendStmt(VBAParser.WhileWendStmtContext context)
{
_contexts.Add(new QualifiedContext<ParserRuleContext>(CurrentModuleName, context));
}
}
}
}