-
Notifications
You must be signed in to change notification settings - Fork 296
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' of https://github.com/comintern/Rubberduck.git
- Loading branch information
Showing
142 changed files
with
3,228 additions
and
9,604 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using Rubberduck.Inspections.Abstract; | ||
using Rubberduck.Inspections.Resources; | ||
using Rubberduck.Inspections.Results; | ||
using Rubberduck.Parsing; | ||
using Rubberduck.Parsing.Grammar; | ||
using Rubberduck.Parsing.VBA; | ||
|
||
namespace Rubberduck.Inspections | ||
{ | ||
public sealed class OptionBaseZeroInspection : InspectionBase, IParseTreeInspection<VBAParser.OptionBaseStmtContext> | ||
{ | ||
private IEnumerable<QualifiedContext> _parseTreeResults; | ||
|
||
public OptionBaseZeroInspection(RubberduckParserState state) | ||
: base(state, CodeInspectionSeverity.Hint) | ||
{ | ||
} | ||
|
||
public override string Meta { get { return InspectionsUI.OptionBaseZeroInspectionMeta; } } | ||
public override string Description { get { return InspectionsUI.OptionBaseZeroInspectionName; } } | ||
public override CodeInspectionType InspectionType { get { return CodeInspectionType.MaintainabilityAndReadabilityIssues; } } | ||
|
||
public IEnumerable<QualifiedContext<VBAParser.OptionBaseStmtContext>> ParseTreeResults { get { return _parseTreeResults.OfType<QualifiedContext<VBAParser.OptionBaseStmtContext>>(); } } | ||
public void SetResults(IEnumerable<QualifiedContext> results) { _parseTreeResults = results; } | ||
|
||
public override IEnumerable<InspectionResultBase> GetInspectionResults() | ||
{ | ||
if (ParseTreeResults == null) | ||
{ | ||
return new InspectionResultBase[] { }; | ||
} | ||
|
||
return ParseTreeResults.Where(context => !IsIgnoringInspectionResultFor(context.ModuleName.Component, context.Context.Start.Line)) | ||
.Select(context => new OptionBaseZeroInspectionResult(this, new QualifiedContext<VBAParser.OptionBaseStmtContext>(context.ModuleName, context.Context))); | ||
} | ||
|
||
public class OptionBaseStatementListener : VBAParserBaseListener | ||
{ | ||
private readonly IList<VBAParser.OptionBaseStmtContext> _contexts = new List<VBAParser.OptionBaseStmtContext>(); | ||
public IEnumerable<VBAParser.OptionBaseStmtContext> Contexts { get { return _contexts; } } | ||
|
||
public override void ExitOptionBaseStmt(VBAParser.OptionBaseStmtContext context) | ||
{ | ||
if (context.numberLiteral()?.INTEGERLITERAL().Symbol.Text == "0") | ||
{ | ||
_contexts.Add(context); | ||
} | ||
} | ||
} | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
RetailCoder.VBE/Inspections/QuickFixes/RemoveOptionBaseStatementQuickFix.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,35 @@ | ||
using Antlr4.Runtime; | ||
using Rubberduck.Inspections.Abstract; | ||
using Rubberduck.Inspections.Resources; | ||
using Rubberduck.VBEditor; | ||
using System; | ||
using System.Linq; | ||
|
||
namespace Rubberduck.Inspections.QuickFixes | ||
{ | ||
internal class RemoveOptionBaseStatementQuickFix : QuickFixBase | ||
{ | ||
public RemoveOptionBaseStatementQuickFix(ParserRuleContext context, QualifiedSelection selection) | ||
: base(context, selection, InspectionsUI.RemoveOptionBaseStatementQuickFix) | ||
{ | ||
} | ||
|
||
public override void Fix() | ||
{ | ||
var module = Selection.QualifiedName.Component.CodeModule; | ||
var lines = module.GetLines(Selection.Selection).Split(new[] { Environment.NewLine }, StringSplitOptions.None); | ||
|
||
var newContent = Selection.Selection.LineCount != 1 | ||
? lines[0].Remove(Selection.Selection.StartColumn - 1) | ||
: lines[0].Remove(Selection.Selection.StartColumn - 1, Selection.Selection.EndColumn - Selection.Selection.StartColumn); | ||
|
||
if (Selection.Selection.LineCount != 1) | ||
{ | ||
newContent += lines.Last().Remove(0, Selection.Selection.EndColumn - 1); | ||
} | ||
|
||
module.DeleteLines(Selection.Selection); | ||
module.InsertLines(Selection.Selection.StartLine, newContent); | ||
} | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
RetailCoder.VBE/Inspections/Resources/InspectionsUI.Designer.cs
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
36 changes: 36 additions & 0 deletions
36
RetailCoder.VBE/Inspections/Results/OptionBaseZeroInspectionResult.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,36 @@ | ||
using System.Collections.Generic; | ||
using Rubberduck.Common; | ||
using Rubberduck.Inspections.Abstract; | ||
using Rubberduck.Inspections.Resources; | ||
using Rubberduck.Parsing; | ||
using Rubberduck.Parsing.Grammar; | ||
using Rubberduck.Inspections.QuickFixes; | ||
|
||
namespace Rubberduck.Inspections.Results | ||
{ | ||
public class OptionBaseZeroInspectionResult : InspectionResultBase | ||
{ | ||
private IEnumerable<QuickFixBase> _quickFixes; | ||
|
||
public OptionBaseZeroInspectionResult(IInspection inspection, QualifiedContext<VBAParser.OptionBaseStmtContext> qualifiedContext) | ||
: base(inspection, qualifiedContext.ModuleName, qualifiedContext.Context) | ||
{ } | ||
|
||
public override IEnumerable<QuickFixBase> QuickFixes | ||
{ | ||
get | ||
{ | ||
return _quickFixes ?? (_quickFixes = new QuickFixBase[] | ||
{ | ||
new RemoveOptionBaseStatementQuickFix(Context, QualifiedSelection), | ||
new IgnoreOnceQuickFix(Context, QualifiedSelection, Inspection.AnnotationName) | ||
}); | ||
} | ||
} | ||
|
||
public override string Description | ||
{ | ||
get { return string.Format(InspectionsUI.OptionBaseZeroInspectionResultFormat.Captialize(), QualifiedName.ComponentName); } | ||
} | ||
} | ||
} |
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.