-
Notifications
You must be signed in to change notification settings - Fork 316
Consolidate Empty(If|Else)Block into EmptyConditionBlock #3376
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
def4242
c3d1958
5098d54
575a7ff
493e4de
d206fb5
d6b69c4
046d24b
ca83371
52b05ad
862017b
af52720
b44850b
6ab6e93
8e44c2f
c0dbaa4
2772478
753eaed
d743c6f
f572634
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,94 @@ | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Linq; | ||
| using Rubberduck.Inspections.Abstract; | ||
| using Rubberduck.Parsing.Inspections.Abstract; | ||
| using Rubberduck.Parsing.Inspections.Resources; | ||
| using Antlr4.Runtime; | ||
| using Antlr4.Runtime.Misc; | ||
| using Rubberduck.Parsing.Grammar; | ||
| using Rubberduck.Parsing; | ||
| using Rubberduck.Parsing.VBA; | ||
| using Rubberduck.Inspections.Results; | ||
|
|
||
| namespace Rubberduck.Inspections.Concrete | ||
| { | ||
| [Flags] | ||
| public enum ConditionBlockToInspect | ||
| { | ||
| NA = 0x0, | ||
| If = 0x1, | ||
| ElseIf = 0x2, | ||
| Else = 0x4, | ||
| All = If | ElseIf | Else | ||
| } | ||
|
|
||
| internal class EmptyConditionBlockInspection : ParseTreeInspectionBase | ||
| { | ||
| public EmptyConditionBlockInspection(RubberduckParserState state, | ||
| ConditionBlockToInspect BlockToInspect) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ninject has no idea how to create the inspection instance, |
||
| : base(state, CodeInspectionSeverity.Suggestion) | ||
| { | ||
| _blockToInspect = BlockToInspect; | ||
| _listener = new EmptyConditionBlockListener(BlockToInspect); | ||
| } | ||
|
|
||
| public static ConditionBlockToInspect _blockToInspect { get; private set; } | ||
|
|
||
| public override Type Type => typeof(EmptyConditionBlockInspection); | ||
|
|
||
| public override IEnumerable<IInspectionResult> GetInspectionResults() | ||
| { | ||
| return Listener.Contexts | ||
| .Where(result => !IsIgnoringInspectionResultFor(result.ModuleName, result.Context.Start.Line)) | ||
| .Select(result => new QualifiedContextInspectionResult(this, | ||
| InspectionsUI.EmptyConditionBlockInspectionsResultFormat, | ||
| result)); | ||
| } | ||
|
|
||
| private IInspectionListener _listener; | ||
| public override IInspectionListener Listener { get { return _listener; } } | ||
|
|
||
| public class EmptyConditionBlockListener : EmptyBlockInspectionListenerBase | ||
| { | ||
| ConditionBlockToInspect _blockToInspect; | ||
|
|
||
| public EmptyConditionBlockListener(ConditionBlockToInspect blockToInspect) | ||
| { | ||
| _blockToInspect = blockToInspect; | ||
| } | ||
|
|
||
| public override void EnterIfStmt([NotNull] VBAParser.IfStmtContext context) | ||
| { | ||
| if (_blockToInspect.HasFlag(ConditionBlockToInspect.If)) | ||
| { | ||
| InspectBlockForExecutableStatements(context.block(), context); | ||
| } | ||
| } | ||
|
|
||
| public override void EnterElseIfBlock([NotNull] VBAParser.ElseIfBlockContext context) | ||
| { | ||
| if (_blockToInspect.HasFlag(ConditionBlockToInspect.ElseIf)) | ||
| { | ||
| InspectBlockForExecutableStatements(context.block(), context); | ||
| } | ||
| } | ||
|
|
||
| public override void EnterSingleLineIfStmt([NotNull] VBAParser.SingleLineIfStmtContext context) | ||
| { | ||
| if (context.ifWithEmptyThen() != null & _blockToInspect.HasFlag(ConditionBlockToInspect.If)) | ||
| { | ||
| AddResult(new QualifiedContext<ParserRuleContext>(CurrentModuleName, context.ifWithEmptyThen())); | ||
| } | ||
| } | ||
|
|
||
| public override void EnterElseBlock([NotNull] VBAParser.ElseBlockContext context) | ||
| { | ||
| if (_blockToInspect.HasFlag(ConditionBlockToInspect.Else)) | ||
| { | ||
| InspectBlockForExecutableStatements(context.block(), context); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
This file was deleted.
This file was deleted.
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be
ConditionBlockTypeToInspect. The current name suggests an actual code block.