1313
1414namespace Rubberduck . Inspections . Concrete
1515{
16+ [ Flags ]
17+ public enum ConditionBlockToInspect
18+ {
19+ NA = 0x0 ,
20+ If = 0x1 ,
21+ ElseIf = 0x2 ,
22+ Else = 0x4 ,
23+ All = If | ElseIf | Else
24+ }
25+
1626 internal class EmptyConditionBlockInspection : ParseTreeInspectionBase
1727 {
18- public EmptyConditionBlockInspection ( RubberduckParserState state )
19- : base ( state , CodeInspectionSeverity . Suggestion ) { }
28+ public EmptyConditionBlockInspection ( RubberduckParserState state ,
29+ ConditionBlockToInspect BlockToInspect ) //= ConditionBlockToInspect.EmptyIf
30+ : base ( state , CodeInspectionSeverity . Suggestion )
31+ {
32+ _blockToInspect = BlockToInspect ;
33+ Listener = new EmptyConditionBlockListener ( BlockToInspect ) ; // ¿better way to set this up?
34+ }
35+
36+ public static ConditionBlockToInspect _blockToInspect { get ; private set ; }
2037
2138 public override Type Type => typeof ( EmptyConditionBlockInspection ) ;
2239
@@ -29,33 +46,49 @@ public override IEnumerable<IInspectionResult> GetInspectionResults()
2946 result ) ) ;
3047 }
3148
32- public override IInspectionListener Listener { get ; } =
33- new EmptyConditionBlockListener ( ) ;
49+ public override IInspectionListener Listener { get ; } = new EmptyConditionBlockListener ( _blockToInspect ) ;
3450
3551 public class EmptyConditionBlockListener : EmptyBlockInspectionListenerBase
3652 {
53+ ConditionBlockToInspect _blockToInspect ;
54+
55+ public EmptyConditionBlockListener ( ConditionBlockToInspect blockToInspect )
56+ {
57+ _blockToInspect = blockToInspect ;
58+ }
59+
3760 public override void EnterIfStmt ( [ NotNull ] VBAParser . IfStmtContext context )
3861 {
39- InspectBlockForExecutableStatements ( context . block ( ) , context ) ;
62+ if ( ( _blockToInspect & ConditionBlockToInspect . If ) == ConditionBlockToInspect . If )
63+ {
64+ InspectBlockForExecutableStatements ( context . block ( ) , context ) ;
65+ }
4066 }
4167
4268 public override void EnterElseIfBlock ( [ NotNull ] VBAParser . ElseIfBlockContext context )
4369 {
44- InspectBlockForExecutableStatements ( context . block ( ) , context ) ;
70+ if ( ( _blockToInspect & ConditionBlockToInspect . ElseIf ) == ConditionBlockToInspect . ElseIf )
71+ {
72+ InspectBlockForExecutableStatements ( context . block ( ) , context ) ;
73+ }
4574 }
4675
4776 public override void EnterSingleLineIfStmt ( [ NotNull ] VBAParser . SingleLineIfStmtContext context )
4877 {
49- if ( context . ifWithEmptyThen ( ) != null )
78+ if ( context . ifWithEmptyThen ( ) != null
79+ & ( ( _blockToInspect & ConditionBlockToInspect . If ) == ConditionBlockToInspect . If ) )
5080 {
5181 AddResult ( new QualifiedContext < ParserRuleContext > ( CurrentModuleName , context . ifWithEmptyThen ( ) ) ) ;
5282 }
5383 }
5484
5585 public override void EnterElseBlock ( [ NotNull ] VBAParser . ElseBlockContext context )
5686 {
57- InspectBlockForExecutableStatements ( context . block ( ) , context ) ;
87+ if ( ( _blockToInspect & ConditionBlockToInspect . Else ) == ConditionBlockToInspect . Else )
88+ {
89+ InspectBlockForExecutableStatements ( context . block ( ) , context ) ;
90+ }
5891 }
5992 }
6093 }
61- }
94+ }
0 commit comments