Skip to content

Commit 6ab6e93

Browse files
committed
Rough EmptyConditionBlockInspection flag to select which block to inspect
2 parents b44850b + 0dfdcb9 commit 6ab6e93

17 files changed

+5010
-100
lines changed

Rubberduck.Inspections/Concrete/EmptyConditionBlockInspection.cs

Lines changed: 42 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,27 @@
1313

1414
namespace 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+
}

Rubberduck.Inspections/Concrete/IntegerDataTypeInspection.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,7 @@ public override IEnumerable<IInspectionResult> GetInspectionResults()
4040
.Select(issue =>
4141
new DeclarationInspectionResult(this,
4242
string.Format(InspectionsUI.IntegerDataTypeInspectionResultFormat,
43-
RubberduckUI.ResourceManager.GetString("DeclarationType_" + issue.DeclarationType,
44-
CultureInfo.CurrentUICulture),
45-
issue.IdentifierName),
43+
RubberduckUI.ResourceManager.GetString("DeclarationType_" + issue.DeclarationType, CultureInfo.CurrentUICulture), issue.IdentifierName),
4644
issue));
4745

4846
return result;

0 commit comments

Comments
 (0)