-
Notifications
You must be signed in to change notification settings - Fork 294
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'next' into czech-transl
- Loading branch information
Showing
22 changed files
with
404 additions
and
263 deletions.
There are no files selected for viewing
53 changes: 53 additions & 0 deletions
53
Rubberduck.CodeAnalysis/Inspections/Concrete/ObsoleteWhileWendStatementInspection.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
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 | ||
{ | ||
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.Where(context => | ||
!context.IsIgnoringInspectionResultFor(State.DeclarationFinder, AnnotationName)) | ||
.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)); | ||
} | ||
} | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
Rubberduck.CodeAnalysis/QuickFixes/ReplaceWhileWendWithDoWhileLoopQuickFix.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
using Rubberduck.CodeAnalysis.Inspections.Concrete; | ||
using Rubberduck.Inspections.Abstract; | ||
using Rubberduck.Parsing.Grammar; | ||
using Rubberduck.Parsing.Inspections.Abstract; | ||
using Rubberduck.Parsing.Rewriter; | ||
|
||
namespace Rubberduck.CodeAnalysis.QuickFixes | ||
{ | ||
public sealed class ReplaceWhileWendWithDoWhileLoopQuickFix : QuickFixBase | ||
{ | ||
public ReplaceWhileWendWithDoWhileLoopQuickFix() | ||
: base(typeof(ObsoleteWhileWendStatementInspection)) | ||
{ } | ||
|
||
public override void Fix(IInspectionResult result, IRewriteSession rewriteSession) | ||
{ | ||
var rewriter = rewriteSession.CheckOutModuleRewriter(result.QualifiedSelection.QualifiedName); | ||
var context = (VBAParser.WhileWendStmtContext)result.Context; | ||
|
||
rewriter.Replace(context.WHILE(), "Do While"); | ||
rewriter.Replace(context.WEND(), "Loop"); | ||
} | ||
|
||
public override string Description(IInspectionResult result) => Resources.Inspections.QuickFixes.ReplaceWhileWendWithDoWhileLoopQuickFix; | ||
|
||
public override bool CanFixInProcedure => true; | ||
public override bool CanFixInModule => true; | ||
public override bool CanFixInProject => true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.