Skip to content

Commit 4688c80

Browse files
grleachmanretailcoder
authored andcommitted
#1225 fix the IExtractMethod for InSelection (#1567)
* Wrap CodeModule. Add RD Interface * Run AutoFormatter over file * fix xml comments * Add a method for ParseString for a module. * Heavy refactoring of ExtractMethodRefactoring #1225. Provisionally remove GUI interaction as it's not required. Add stubs for tests. * Marker for needing to validate the MEthodName and increment. * #1225 : Add checking for Multiple NewMethod signatures. Start work on ExtractMethodSelectionValidation, aka CanExecute * prep for next stage of ExtractMethodRefactor * Validate selection is within a single method * Validate selection procEndLine only needs ParserRuleContext to validate * #1225 : Removed Obsolete Call on method siganture * #1225 modify tests for new spec on Method Call. change from underscore nomenclature * #1225 prep for local variable only used within selection * completed logic for ExtractMethodModel ByVal, ByRef, MoveIn * Adjust the method for determining byval, byref and movein * Extract methods and pull together with surrounding code. * Break down the Extraction and Testing a little deeper * Working through requirements now. Specifications almost complete. UI interfacing needs refactoring. Some nasty bits here and there * Why was that left out ??. commit interface for ExtractMethodRule! * End of my exploration into ExtractMethodRefactoring. Maybe I'll come back to this. * Final refactorings, now only need to apply the blackbox testing * final implementation of this version. Haven't implemented line lable moves * #1225 added check for moving an internally declared dim. Now need to resolve if that dim is used externally * add NCrunch to git ignore * fix breaking code * fix breaking code. Again * Remove new tests, that don't have working code yet.
1 parent 1143a56 commit 4688c80

File tree

2 files changed

+5
-96
lines changed

2 files changed

+5
-96
lines changed

RetailCoder.VBE/Refactorings/ExtractMethod/IExtractMethodRule.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,11 @@ public class ExtractMethodRuleInSelection : IExtractMethodRule
5353
{
5454
public void setValidFlag(ref byte flags, IdentifierReference reference, Selection selection)
5555
{
56-
if (selection.StartLine <= reference.Selection.StartLine &&
57-
reference.Selection.StartLine <= selection.EndLine &&
58-
(reference.Declaration == null) ? false : reference.Declaration.Selection.StartLine != reference.Selection.StartLine)
59-
flags = (byte)(flags | 8);
56+
57+
if (selection.StartLine <= reference.Selection.StartLine &&
58+
reference.Selection.StartLine <= selection.EndLine &&
59+
((reference.Declaration == null) ? false : reference.Declaration.Selection.StartLine != reference.Selection.StartLine))
60+
flags = (byte)(flags | ((byte)ExtractMethodRuleFlags.InSelection));
6061
}
6162
}
6263

RubberduckTests/Refactoring/ExtractMethod/ExtractMethodModelTests.cs

Lines changed: 0 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -53,98 +53,6 @@ public void shouldNotSetFlag()
5353
}
5454

5555
}
56-
[TestClass]
57-
public class WhenSetValidFlagIsCalledWhenTheReferenceIsInSelection : ExtractMethodRuleInSelectionTests
58-
{
59-
#region inputCode
60-
string inputCode = @"
61-
Option explicit
62-
Public Sub CodeWithDeclaration()
63-
Dim x as long
64-
Dim z as long
65-
66-
x = 1 + 2
67-
DebugPrint x
68-
Dim y as long
69-
y = x + 1
70-
x = 2
71-
DebugPrint y
72-
73-
z = x
74-
DebugPrint z
75-
76-
End Sub
77-
Public Sub DebugPrint(byval g as long)
78-
End Sub
79-
80-
81-
";
82-
#endregion
83-
[TestClass]
84-
public class AndReferenceIsNotADeclaration : WhenSetValidFlagIsCalledWhenTheReferenceIsInSelection
85-
{
86-
[TestMethod]
87-
[TestCategory("ExtractMethodRuleTests")]
88-
public void shouldSetFlagInSelection()
89-
{
90-
QualifiedModuleName qualifiedModuleName;
91-
RubberduckParserState state;
92-
MockParser.ParseString(inputCode, out qualifiedModuleName, out state);
93-
94-
var declarations = state.AllDeclarations;
95-
var selection = new Selection(8, 4, 13, 14);
96-
var referenceSelection = new Selection(10, 1, 10, 1);
97-
98-
QualifiedSelection? qualifiedSelection = new QualifiedSelection(qualifiedModuleName, selection);
99-
var codeModule = new Mock<ICodeModuleWrapper>();
100-
101-
byte flag = new byte();
102-
103-
104-
IdentifierReference reference = declarations.SelectMany(d => d.References, (d, r) => new { refernce = r, declarationStartLine = d.Selection.StartLine })
105-
.Where(anon => anon.declarationStartLine != anon.refernce.Selection.StartLine)
106-
.Select(anon => anon.refernce).First();
107-
108-
var SUT = new ExtractMethodRuleInSelection();
109-
SUT.setValidFlag(ref flag, reference, selection);
110-
111-
Assert.AreEqual((byte)ExtractMethodRuleFlags.InSelection, flag);
112-
}
113-
}
114-
115-
[TestClass]
116-
public class AndReferenceIsADeclaration : WhenSetValidFlagIsCalledWhenTheReferenceIsInSelection
117-
{
118-
[TestMethod]
119-
[TestCategory("ExtractMethodRuleTests")]
120-
public void shouldNotSetFlagInSelection()
121-
{
122-
QualifiedModuleName qualifiedModuleName;
123-
RubberduckParserState state;
124-
MockParser.ParseString(inputCode, out qualifiedModuleName, out state);
125-
126-
var declarations = state.AllDeclarations;
127-
var selection = new Selection(8, 4, 13, 14);
128-
var referenceSelection = new Selection(9, 1, 9, 1);
129-
130-
QualifiedSelection? qualifiedSelection = new QualifiedSelection(qualifiedModuleName, selection);
131-
var codeModule = new Mock<ICodeModuleWrapper>();
132-
133-
byte flag = new byte();
134-
135-
IdentifierReference reference = declarations.SelectMany(d => d.References, (d, r) => new { refernce = r, declarationStartLine = d.Selection.StartLine })
136-
.Where(anon => anon.declarationStartLine != anon.refernce.Selection.StartLine)
137-
.Select(anon => anon.refernce).First();
138-
139-
var SUT = new ExtractMethodRuleInSelection();
140-
SUT.setValidFlag(ref flag, reference, selection);
141-
142-
Assert.AreEqual((byte)ExtractMethodRuleFlags.InSelection, flag);
143-
144-
}
145-
}
146-
147-
}
14856

14957
}
15058

0 commit comments

Comments
 (0)