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