Skip to content

Commit d635094

Browse files
authored
Merge pull request #2341 from retailcoder/next
some test fixes - 14 tests are still failing
2 parents 6db9512 + f41fc4f commit d635094

File tree

49 files changed

+241
-224
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+241
-224
lines changed

RetailCoder.VBE/Inspections/DeclareAsExplicitVariantQuickFix.cs

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using System.Linq;
22
using Antlr4.Runtime;
3-
using Antlr4.Runtime.Tree;
43
using Rubberduck.Parsing;
54
using Rubberduck.Parsing.Grammar;
65
using Rubberduck.VBEditor;
@@ -17,32 +16,37 @@ public DeclareAsExplicitVariantQuickFix(ParserRuleContext context, QualifiedSele
1716
public override void Fix()
1817
{
1918
var module = Selection.QualifiedName.Component.CodeModule;
20-
{
21-
string originalInstruction;
19+
var contextLines = module.GetLines(Context.GetSelection());
20+
var originalIndent = contextLines.Substring(0, contextLines.TakeWhile(c => c == ' ').Count());
2221

23-
// DeclareExplicitVariant() overloads return empty string if context is null
24-
Selection selection;
25-
var fix = DeclareExplicitVariant(Context as VBAParser.VariableSubStmtContext, out originalInstruction, out selection);
22+
string originalInstruction;
2623

27-
if (string.IsNullOrEmpty(originalInstruction))
28-
{
29-
fix = DeclareExplicitVariant(Context as VBAParser.ConstSubStmtContext, out originalInstruction, out selection);
30-
}
24+
// DeclareExplicitVariant() overloads return empty string if context is null
25+
Selection selection;
26+
var fix = DeclareExplicitVariant(Context as VBAParser.VariableSubStmtContext, out originalInstruction, out selection);
27+
if (!string.IsNullOrEmpty(fix))
28+
{
29+
// maintain original indentation for a variable declaration
30+
fix = originalIndent + fix;
31+
}
3132

32-
if (string.IsNullOrEmpty(originalInstruction))
33-
{
34-
fix = DeclareExplicitVariant(Context as VBAParser.ArgContext, out originalInstruction, out selection);
35-
}
33+
if (string.IsNullOrEmpty(originalInstruction))
34+
{
35+
fix = DeclareExplicitVariant(Context as VBAParser.ConstSubStmtContext, out originalInstruction, out selection);
36+
}
3637

37-
if (string.IsNullOrEmpty(originalInstruction))
38-
{
39-
return;
40-
}
38+
if (string.IsNullOrEmpty(originalInstruction))
39+
{
40+
fix = DeclareExplicitVariant(Context as VBAParser.ArgContext, out originalInstruction, out selection);
41+
}
4142

42-
43-
module.DeleteLines(selection.StartLine, selection.LineCount);
44-
module.InsertLines(selection.StartLine, fix);
43+
if (string.IsNullOrEmpty(originalInstruction))
44+
{
45+
return;
4546
}
47+
48+
module.DeleteLines(selection.StartLine, selection.LineCount);
49+
module.InsertLines(selection.StartLine, fix);
4650
}
4751

4852
private string DeclareExplicitVariant(VBAParser.ArgContext context, out string instruction, out Selection selection)
@@ -71,7 +75,7 @@ private string DeclareExplicitVariant(VBAParser.ArgContext context, out string i
7175
{
7276
if (part is VBAParser.UnrestrictedIdentifierContext)
7377
{
74-
fix += part.GetText() + ' ' + Tokens.As + ' ' + Tokens.Variant + ' ';
78+
fix += part.GetText() + ' ' + Tokens.As + ' ' + Tokens.Variant;
7579
}
7680
else
7781
{
@@ -108,7 +112,7 @@ private string DeclareExplicitVariant(VBAParser.VariableSubStmtContext context,
108112
selection = parent.GetSelection();
109113

110114
var variable = context.GetText();
111-
var replacement = context.identifier().GetText() + ' ' + Tokens.As + ' ' + Tokens.Variant + ' ';
115+
var replacement = context.identifier().GetText() + ' ' + Tokens.As + ' ' + Tokens.Variant;
112116

113117
var result = instruction.Replace(variable, replacement);
114118
return result;

RetailCoder.VBE/Navigation/RegexSearchReplace/RegexSearchReplace.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ private IEnumerable<RegexSearchResult> GetResultsFromModule(ICodeModule module,
9696

9797
private void SetSelection(RegexSearchResult item)
9898
{
99-
item.Module.CodePane.SetSelection(item.Selection);
99+
item.Module.CodePane.Selection = item.Selection;
100100
}
101101

102102
private List<RegexSearchResult> SearchSelection(string searchPattern)
@@ -105,7 +105,7 @@ private List<RegexSearchResult> SearchSelection(string searchPattern)
105105
var module = pane.CodeModule;
106106
{
107107
var results = GetResultsFromModule(module, searchPattern);
108-
return results.Where(r => pane.GetSelection().Contains(r.Selection)).ToList();
108+
return results.Where(r => pane.Selection.Contains(r.Selection)).ToList();
109109
}
110110
}
111111

@@ -127,7 +127,7 @@ private List<RegexSearchResult> SearchCurrentBlock(string searchPattern)
127127
{
128128
var results = GetResultsFromModule(module, searchPattern);
129129

130-
var qualifiedSelection = new QualifiedSelection(new QualifiedModuleName(module.Parent), pane.GetSelection());
130+
var qualifiedSelection = new QualifiedSelection(new QualifiedModuleName(module.Parent), pane.Selection);
131131
dynamic block = state.AllDeclarations.FindTarget(qualifiedSelection, declarationTypes).Context.Parent;
132132
var selection = new Selection(block.Start.Line, block.Start.Column, block.Stop.Line, block.Stop.Column);
133133
return results.Where(r => selection.Contains(r.Selection)).ToList();

RetailCoder.VBE/Refactorings/EncapsulateField/EncapsulateFieldPresenterFactory.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,13 @@ public EncapsulateFieldPresenterFactory(IVBE vbe, RubberduckParserState state, I
1818

1919
public EncapsulateFieldPresenter Create()
2020
{
21-
var selection = _vbe.ActiveCodePane.GetQualifiedSelection();
21+
var pane = _vbe.ActiveCodePane;
22+
if (pane == null || pane.IsWrappingNullReference)
23+
{
24+
return null;
25+
}
26+
27+
var selection = pane.GetQualifiedSelection();
2228
if (!selection.HasValue)
2329
{
2430
return null;

RetailCoder.VBE/Refactorings/EncapsulateField/EncapsulateFieldRefactoring.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public void Refactor()
4747
var module = oldSelection.Value.QualifiedName.Component.CodeModule;
4848
var pane = module.CodePane;
4949
{
50-
pane.SetSelection(oldSelection.Value.Selection);
50+
pane.Selection = oldSelection.Value.Selection;
5151
}
5252
}
5353

@@ -58,7 +58,7 @@ public void Refactor(QualifiedSelection target)
5858
{
5959
var pane = _vbe.ActiveCodePane;
6060
{
61-
pane.SetSelection(target.Selection);
61+
pane.Selection = target.Selection;
6262
}
6363
Refactor();
6464
}
@@ -67,7 +67,7 @@ public void Refactor(Declaration target)
6767
{
6868
var pane = _vbe.ActiveCodePane;
6969
{
70-
pane.SetSelection(target.QualifiedSelection.Selection);
70+
pane.Selection = target.QualifiedSelection.Selection;
7171
}
7272
Refactor();
7373
}
@@ -112,7 +112,7 @@ private void SetFieldToPrivate(ICodeModule module)
112112
module.InsertLines(module.CountOfDeclarationLines + 1, newField);
113113
var pane = module.CodePane;
114114
{
115-
pane.SetSelection(_model.TargetDeclaration.QualifiedSelection.Selection);
115+
pane.Selection = _model.TargetDeclaration.QualifiedSelection.Selection;
116116
}
117117

118118
for (var index = 1; index <= module.CountOfDeclarationLines; index++)

RetailCoder.VBE/Refactorings/ExtractInterface/ExtractInterfacePresenterFactory.cs

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,22 +20,25 @@ public ExtractInterfacePresenterFactory(IVBE vbe, RubberduckParserState state, I
2020
public ExtractInterfacePresenter Create()
2121
{
2222
var pane = _vbe.ActiveCodePane;
23+
if (pane == null || pane.IsWrappingNullReference)
2324
{
24-
var selection = pane.GetQualifiedSelection();
25-
if (selection == null)
26-
{
27-
return null;
28-
}
29-
30-
var model = new ExtractInterfaceModel(_state, selection.Value);
31-
if (!model.Members.Any())
32-
{
33-
// don't show the UI if there's no member to extract
34-
return null;
35-
}
25+
return null;
26+
}
27+
var selection = pane.GetQualifiedSelection();
28+
if (selection == null)
29+
{
30+
return null;
31+
}
3632

37-
return new ExtractInterfacePresenter(_view, model);
33+
var model = new ExtractInterfaceModel(_state, selection.Value);
34+
if (!model.Members.Any())
35+
{
36+
// don't show the UI if there's no member to extract
37+
return null;
3838
}
39+
40+
return new ExtractInterfacePresenter(_view, model);
41+
3942
}
4043
}
4144
}

RetailCoder.VBE/Refactorings/ExtractInterface/ExtractInterfaceRefactoring.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ public void Refactor()
4343
return;
4444
}
4545

46-
QualifiedSelection? oldSelection = null;
4746
var pane = _vbe.ActiveCodePane;
4847
{
48+
QualifiedSelection? oldSelection;
4949
if (!pane.IsWrappingNullReference)
5050
{
5151
var module = pane.CodeModule;
@@ -62,7 +62,7 @@ public void Refactor()
6262

6363
if (oldSelection.HasValue)
6464
{
65-
pane.SetSelection(oldSelection.Value.Selection);
65+
pane.Selection = oldSelection.Value.Selection;
6666
}
6767
}
6868

@@ -77,7 +77,7 @@ public void Refactor(QualifiedSelection target)
7777
{
7878
return;
7979
}
80-
pane.SetSelection(target.Selection);
80+
pane.Selection = target.Selection;
8181
}
8282
Refactor();
8383
}
@@ -90,7 +90,7 @@ public void Refactor(Declaration target)
9090
{
9191
return;
9292
}
93-
pane.SetSelection(target.QualifiedSelection.Selection);
93+
pane.Selection = target.QualifiedSelection.Selection;
9494
}
9595
Refactor();
9696
}
@@ -129,7 +129,7 @@ private void _state_StateChanged(object sender, EventArgs e)
129129
var qualifiedSelection = new QualifiedSelection(_model.TargetDeclaration.QualifiedSelection.QualifiedName, new Selection(_insertionLine, 1, _insertionLine, 1));
130130
var pane = _vbe.ActiveCodePane;
131131
{
132-
pane.SetSelection(qualifiedSelection.Selection);
132+
pane.Selection = qualifiedSelection.Selection;
133133
}
134134

135135
var implementInterfaceRefactoring = new ImplementInterfaceRefactoring(_vbe, _state, _messageBox);

RetailCoder.VBE/Refactorings/ExtractMethod/ExtractMethodRefactoring.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public void Refactor(QualifiedSelection target)
7272
{
7373
var pane = _codeModule.CodePane;
7474
{
75-
pane.SetSelection(target.Selection);
75+
pane.Selection = target.Selection;
7676
Refactor();
7777
}
7878
}

RetailCoder.VBE/Refactorings/ImplementInterface/ImplementInterfaceRefactoring.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public void Refactor(QualifiedSelection selection)
7979
var module = oldSelection.Value.QualifiedName.Component.CodeModule;
8080
var pane = module.CodePane;
8181
{
82-
pane.SetSelection(oldSelection.Value.Selection);
82+
pane.Selection = oldSelection.Value.Selection;
8383
}
8484
}
8585

RetailCoder.VBE/Refactorings/IntroduceField/IntroduceFieldRefactoring.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ private void PromoteVariable(Declaration target)
9393
var module = oldSelection.Value.QualifiedName.Component.CodeModule;
9494
var pane = module.CodePane;
9595
{
96-
pane.SetSelection(oldSelection.Value.Selection);
96+
pane.Selection = oldSelection.Value.Selection;
9797
}
9898
}
9999

RetailCoder.VBE/Refactorings/IntroduceParameter/IntroduceParameterRefactoring.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ private void PromoteVariable(Declaration target)
111111

112112
if (oldSelection.HasValue)
113113
{
114-
pane.SetSelection(oldSelection.Value.Selection);
114+
pane.Selection = oldSelection.Value.Selection;
115115
}
116116

117117
_state.OnParseRequested(this);

0 commit comments

Comments
 (0)