Skip to content

Commit eb14de8

Browse files
committed
Merge branch 'next' into ExtractComponentsFromQMNsSecondTry
# Conflicts: # RubberduckTests/RubberduckTests.csproj Take both!
2 parents 9446fbe + bfc6720 commit eb14de8

26 files changed

+4146
-3180
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ Branch | Description | Build Status |
3535

3636
Rubberduck is a COM add-in for the VBA IDE (VBE).
3737

38-
Copyright (C) 2014-2017 Mathieu Guindon & Christopher McClellan
38+
Copyright (C) 2014-2018 Mathieu Guindon & Christopher McClellan
3939

4040
This program is free software: you can redistribute it and/or modify
4141
it under the terms of the GNU General Public License as published by

RetailCoder.VBE/UI/Inspections/InspectionResultsControl.xaml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
66
xmlns:codeInspections="clr-namespace:Rubberduck.UI.Inspections"
77
xmlns:controls="clr-namespace:Rubberduck.UI.Controls"
8-
xmlns:themes="clr-namespace:Microsoft.Windows.Themes;assembly=PresentationFramework.Aero"
9-
xmlns:converters="clr-namespace:Rubberduck.UI.Converters"
108
xmlns:abstract1="clr-namespace:Rubberduck.Parsing.Inspections.Abstract;assembly=Rubberduck.Parsing"
119
ResxExtension.DefaultResxName="Rubberduck.UI.RubberduckUI"
1210
Language="{UICulture}"
@@ -19,8 +17,6 @@
1917
<ResourceDictionary Source="../Controls/ToolBar.xaml"/>
2018
</ResourceDictionary.MergedDictionaries>
2119

22-
<converters:InvertBoolValueConverter x:Key="InvertBoolValue" />
23-
2420
<BooleanToVisibilityConverter x:Key="BoolToVisibility"/>
2521

2622
<codeInspections:InspectionSeverityImageSourceConverter x:Key="SeverityIconConverter" />

RetailCoder.VBE/UI/RubberduckUI.de.resx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1011,7 +1011,7 @@ Wollen Sie trotzdem fortfahren?</value>
10111011
<value>Über Rubberduck</value>
10121012
</data>
10131013
<data name="AboutWindow_Copyright" xml:space="preserve">
1014-
<value>© Copyright 2014-2017 Mathieu Guindon &amp; Christopher McClellan</value>
1014+
<value>© Copyright 2014-2018 Mathieu Guindon &amp; Christopher McClellan</value>
10151015
</data>
10161016
<data name="AboutWindow_SpecialThanksLabel" xml:space="preserve">
10171017
<value>Spezieller Dank</value>
@@ -2085,4 +2085,4 @@ Möchten sie die Einstellungen in Rubberduck importieren?</value>
20852085
<data name="CodeMetrics_Nesting" xml:space="preserve">
20862086
<value>Maximale Einrückung</value>
20872087
</data>
2088-
</root>
2088+
</root>

RetailCoder.VBE/UI/RubberduckUI.fr.resx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1266,7 +1266,7 @@ Support localisation WPF par Grant Frisken</value>
12661266
<value>Clé invalide</value>
12671267
</data>
12681268
<data name="AboutWindow_Copyright" xml:space="preserve">
1269-
<value>© Copyright 2014-2017 Mathieu Guindon &amp; Christopher McClellan</value>
1269+
<value>© Copyright 2014-2018 Mathieu Guindon &amp; Christopher McClellan</value>
12701270
</data>
12711271
<data name="UnitTest_NewModule_RunOnce" xml:space="preserve">
12721272
<value>cette procédure s'exécute une seule fois par module</value>
@@ -2088,4 +2088,4 @@ les projets dans le VBE.</value>
20882088
<data name="CodeMetrics_Lines" xml:space="preserve">
20892089
<value>Lignes</value>
20902090
</data>
2091-
</root>
2091+
</root>

RetailCoder.VBE/UI/RubberduckUI.resx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -710,7 +710,7 @@ Are you sure you want to proceed with this rename?</value>
710710
<value>About Rubberduck</value>
711711
</data>
712712
<data name="AboutWindow_Copyright" xml:space="preserve">
713-
<value>© Copyright 2014-2017 Mathieu Guindon &amp; Christopher McClellan</value>
713+
<value>© Copyright 2014-2018 Mathieu Guindon &amp; Christopher McClellan</value>
714714
</data>
715715
<data name="AboutWindow_SpecialThanksLabel" xml:space="preserve">
716716
<value>Special Thanks</value>
@@ -2155,4 +2155,4 @@ Would you like to import them to Rubberduck?</value>
21552155
<data name="GeneralSettings_ModifierWarning" xml:space="preserve">
21562156
<value>Modifier Warning</value>
21572157
</data>
2158-
</root>
2158+
</root>
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
using System.Collections.Generic;
2+
using System.Linq;
3+
using Rubberduck.Inspections.Abstract;
4+
using Rubberduck.Parsing.VBA;
5+
using Rubberduck.Parsing.Inspections.Resources;
6+
using Rubberduck.Parsing.Inspections.Abstract;
7+
using Rubberduck.Parsing.Grammar;
8+
using Antlr4.Runtime;
9+
using Rubberduck.Parsing;
10+
using Rubberduck.VBEditor;
11+
using Antlr4.Runtime.Misc;
12+
using Rubberduck.Inspections.Results;
13+
14+
namespace Rubberduck.Inspections.Concrete
15+
{
16+
public sealed class DefTypeStatementInspection : ParseTreeInspectionBase
17+
{
18+
public DefTypeStatementInspection(RubberduckParserState state)
19+
: base(state, CodeInspectionSeverity.Suggestion)
20+
{
21+
Listener = new DefTypeStatementInspectionListener();
22+
}
23+
24+
public override CodeInspectionType InspectionType => CodeInspectionType.LanguageOpportunities;
25+
public override IInspectionListener Listener { get; }
26+
27+
protected override IEnumerable<IInspectionResult> DoGetInspectionResults()
28+
{
29+
var results = Listener.Contexts.Where(context => !IsIgnoringInspectionResultFor(context.ModuleName, context.Context.Start.Line))
30+
.Select(context => new QualifiedContextInspectionResult(this,
31+
string.Format(InspectionsUI.DefTypeStatementInspectionResultFormat,
32+
GetTypeOfDefType(context.Context.start.Text),
33+
context.Context.start.Text),
34+
context));
35+
return results;
36+
}
37+
38+
public class DefTypeStatementInspectionListener : VBAParserBaseListener, IInspectionListener
39+
{
40+
private readonly List<QualifiedContext<ParserRuleContext>> _contexts = new List<QualifiedContext<ParserRuleContext>>();
41+
public IReadOnlyList<QualifiedContext<ParserRuleContext>> Contexts => _contexts;
42+
43+
public QualifiedModuleName CurrentModuleName { get; set; }
44+
45+
public void ClearContexts()
46+
{
47+
_contexts.Clear();
48+
}
49+
50+
public override void ExitDefType([NotNull] VBAParser.DefTypeContext context)
51+
{
52+
_contexts.Add(new QualifiedContext<ParserRuleContext>(CurrentModuleName, context));
53+
}
54+
}
55+
56+
private string GetTypeOfDefType(string defType)
57+
{
58+
_defTypes.TryGetValue(defType, out var value);
59+
return value;
60+
}
61+
62+
private readonly Dictionary<string, string> _defTypes = new Dictionary<string, string>
63+
{
64+
{ "DefBool", "Boolean" },
65+
{ "DefByte", "Byte" },
66+
{ "DefInt", "Integer" },
67+
{ "DefLng", "Long" },
68+
{ "DefCur", "Currency" },
69+
{ "DefSng", "Single" },
70+
{ "DefDbl", "Double" },
71+
{ "DefDate", "Date" },
72+
{ "DefStr", "String" },
73+
{ "DefObj", "Object" },
74+
{ "DefVar", "Variant" }
75+
};
76+
}
77+
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
using Rubberduck.Inspections.Abstract;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
using Rubberduck.Parsing.Inspections.Abstract;
6+
using Rubberduck.Parsing.Inspections.Resources;
7+
using Rubberduck.Parsing.VBA;
8+
using Rubberduck.Parsing.Grammar;
9+
using Antlr4.Runtime.Misc;
10+
using Antlr4.Runtime;
11+
using Rubberduck.Parsing;
12+
using Rubberduck.VBEditor;
13+
using Rubberduck.Inspections.Results;
14+
using static Rubberduck.Parsing.Grammar.VBAParser;
15+
16+
namespace Rubberduck.Inspections.Concrete
17+
{
18+
public sealed class StepIsNotSpecifiedInspection : ParseTreeInspectionBase
19+
{
20+
public StepIsNotSpecifiedInspection(RubberduckParserState state) : base(state, CodeInspectionSeverity.DoNotShow) { }
21+
22+
public override CodeInspectionType InspectionType => CodeInspectionType.LanguageOpportunities;
23+
24+
protected override IEnumerable<IInspectionResult> DoGetInspectionResults()
25+
{
26+
return Listener.Contexts
27+
.Where(result => !IsIgnoringInspectionResultFor(result.ModuleName, result.Context.Start.Line))
28+
.Select(result => new QualifiedContextInspectionResult(this,
29+
InspectionsUI.StepIsNotSpecifiedInspectionResultFormat,
30+
result));
31+
}
32+
33+
public override IInspectionListener Listener { get; } =
34+
new StepIsNotSpecifiedListener();
35+
}
36+
37+
public class StepIsNotSpecifiedListener : VBAParserBaseListener, IInspectionListener
38+
{
39+
private readonly List<QualifiedContext<ParserRuleContext>> _contexts = new List<QualifiedContext<ParserRuleContext>>();
40+
public IReadOnlyList<QualifiedContext<ParserRuleContext>> Contexts => _contexts;
41+
42+
public QualifiedModuleName CurrentModuleName
43+
{
44+
get;
45+
set;
46+
}
47+
48+
public void ClearContexts()
49+
{
50+
_contexts.Clear();
51+
}
52+
53+
public override void EnterForNextStmt([NotNull] VBAParser.ForNextStmtContext context)
54+
{
55+
StepStmtContext stepStatement = context.stepStmt();
56+
57+
if (stepStatement == null)
58+
{
59+
_contexts.Add(new QualifiedContext<ParserRuleContext>(CurrentModuleName, context));
60+
}
61+
}
62+
}
63+
}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
using Rubberduck.Inspections.Abstract;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
using Rubberduck.Parsing.Inspections.Abstract;
6+
using Rubberduck.Parsing.Inspections.Resources;
7+
using Rubberduck.Parsing.VBA;
8+
using Rubberduck.Parsing.Grammar;
9+
using Antlr4.Runtime.Misc;
10+
using Antlr4.Runtime;
11+
using Rubberduck.Parsing;
12+
using Rubberduck.VBEditor;
13+
using Rubberduck.Inspections.Results;
14+
using static Rubberduck.Parsing.Grammar.VBAParser;
15+
16+
namespace Rubberduck.Inspections.Concrete
17+
{
18+
public sealed class StepOneIsRedundantInspection : ParseTreeInspectionBase
19+
{
20+
public StepOneIsRedundantInspection(RubberduckParserState state) : base(state, CodeInspectionSeverity.Hint) { }
21+
22+
public override CodeInspectionType InspectionType => CodeInspectionType.LanguageOpportunities;
23+
24+
protected override IEnumerable<IInspectionResult> DoGetInspectionResults()
25+
{
26+
return Listener.Contexts
27+
.Where(result => !IsIgnoringInspectionResultFor(result.ModuleName, result.Context.Start.Line))
28+
.Select(result => new QualifiedContextInspectionResult(this,
29+
InspectionsUI.StepOneIsRedundantInspectionResultFormat,
30+
result));
31+
}
32+
33+
public override IInspectionListener Listener { get; } =
34+
new StepOneIsRedundantListener();
35+
}
36+
37+
public class StepOneIsRedundantListener : VBAParserBaseListener, IInspectionListener
38+
{
39+
private readonly List<QualifiedContext<ParserRuleContext>> _contexts = new List<QualifiedContext<ParserRuleContext>>();
40+
public IReadOnlyList<QualifiedContext<ParserRuleContext>> Contexts => _contexts;
41+
42+
public QualifiedModuleName CurrentModuleName
43+
{
44+
get;
45+
set;
46+
}
47+
48+
public void ClearContexts()
49+
{
50+
_contexts.Clear();
51+
}
52+
53+
public override void EnterForNextStmt([NotNull] VBAParser.ForNextStmtContext context)
54+
{
55+
StepStmtContext stepStatement = context.stepStmt();
56+
57+
if (stepStatement == null)
58+
{
59+
return;
60+
}
61+
62+
string stepText = stepStatement.expression().GetText();
63+
64+
if(stepText == "1")
65+
{
66+
_contexts.Add(new QualifiedContext<ParserRuleContext>(CurrentModuleName, stepStatement));
67+
}
68+
}
69+
}
70+
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
using Antlr4.Runtime;
2+
using Antlr4.Runtime.Tree;
3+
using Rubberduck.Inspections.Abstract;
4+
using Rubberduck.Inspections.Concrete;
5+
using Rubberduck.Parsing.Inspections.Abstract;
6+
using Rubberduck.Parsing.Inspections.Resources;
7+
using Rubberduck.Parsing.Rewriter;
8+
using Rubberduck.Parsing.VBA;
9+
using System;
10+
using System.Collections.Generic;
11+
using System.Linq;
12+
using System.Text;
13+
using System.Threading.Tasks;
14+
using static Rubberduck.Parsing.Grammar.VBAParser;
15+
16+
namespace Rubberduck.Inspections.QuickFixes
17+
{
18+
public class AddStepOneQuickFix : QuickFixBase
19+
{
20+
private readonly RubberduckParserState _state;
21+
22+
public AddStepOneQuickFix(RubberduckParserState state)
23+
: base(typeof(StepIsNotSpecifiedInspection))
24+
{
25+
_state = state;
26+
}
27+
28+
public override bool CanFixInProcedure => false;
29+
30+
public override bool CanFixInModule => false;
31+
32+
public override bool CanFixInProject => false;
33+
34+
public override string Description(IInspectionResult result)
35+
{
36+
return InspectionsUI.AddStepOneQuickFix;
37+
}
38+
39+
public override void Fix(IInspectionResult result)
40+
{
41+
IModuleRewriter rewriter = _state.GetRewriter(result.QualifiedSelection.QualifiedName);
42+
ForNextStmtContext context = result.Context as ForNextStmtContext;
43+
44+
int toExpressionEnd = this.GetToExpressionEnd(context);
45+
rewriter.InsertAfter(toExpressionEnd, " Step 1");
46+
}
47+
48+
private int GetToExpressionEnd(ForNextStmtContext context)
49+
{
50+
int toNodeIndex = context.TO().Symbol.TokenIndex;
51+
52+
foreach(ExpressionContext expressionChild in context.expression())
53+
{
54+
if (expressionChild.Stop.TokenIndex > toNodeIndex)
55+
{
56+
return expressionChild.Stop.TokenIndex;
57+
}
58+
}
59+
60+
throw new InvalidOperationException();
61+
}
62+
}
63+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
using Rubberduck.Inspections.Abstract;
2+
using Rubberduck.Inspections.Concrete;
3+
using Rubberduck.Parsing.Inspections.Abstract;
4+
using Rubberduck.Parsing.Inspections.Resources;
5+
using Rubberduck.Parsing.Rewriter;
6+
using Rubberduck.Parsing.VBA;
7+
8+
namespace Rubberduck.Inspections.QuickFixes
9+
{
10+
public class RemoveStepOneQuickFix : QuickFixBase
11+
{
12+
private readonly RubberduckParserState _state;
13+
14+
public RemoveStepOneQuickFix(RubberduckParserState state)
15+
: base(typeof(StepOneIsRedundantInspection))
16+
{
17+
_state = state;
18+
}
19+
20+
public override bool CanFixInProcedure => false;
21+
22+
public override bool CanFixInModule => false;
23+
24+
public override bool CanFixInProject => false;
25+
26+
public override string Description(IInspectionResult result)
27+
{
28+
return InspectionsUI.RemoveStepOneQuickFix;
29+
}
30+
31+
public override void Fix(IInspectionResult result)
32+
{
33+
IModuleRewriter rewriter = _state.GetRewriter(result.QualifiedSelection.QualifiedName);
34+
var context = result.Context;
35+
rewriter.Remove(context);
36+
}
37+
}
38+
}

0 commit comments

Comments
 (0)