Skip to content

Commit 2c81efc

Browse files
committed
Merge pull request #888 from Hosch250/ExtractMethod
Check declaration scope as well as reference scope, and validate method name better
2 parents 1b00de3 + 08bc86e commit 2c81efc

File tree

5 files changed

+105
-62
lines changed

5 files changed

+105
-62
lines changed

RetailCoder.VBE/Refactorings/ExtractMethod/ExtractMethodModel.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,15 @@ public ExtractMethodModel(IActiveCodePaneEditor editor, IEnumerable<Declaration>
3333
.ToList();
3434

3535
var usedInSelection = new HashSet<Declaration>(inScopeDeclarations.Where(item =>
36+
selection.Selection.Contains(item.Selection) &&
3637
item.References.Any(reference => inSelection.Contains(reference))));
3738

3839
var usedBeforeSelection = new HashSet<Declaration>(inScopeDeclarations.Where(item =>
40+
item.Selection.StartLine < selection.Selection.StartLine ||
3941
item.References.Any(reference => reference.Selection.StartLine < selection.Selection.StartLine)));
4042

4143
var usedAfterSelection = new HashSet<Declaration>(inScopeDeclarations.Where(item =>
44+
item.Selection.StartLine > selection.Selection.StartLine ||
4245
item.References.Any(reference => reference.Selection.StartLine > selection.Selection.EndLine)));
4346

4447
// identifiers used inside selection and before selection (or if it's a parameter) are candidates for parameters:

RetailCoder.VBE/Refactorings/ExtractMethod/ExtractMethodPresenter.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ public ExtractMethodModel Show()
3636

3737
private void PrepareView()
3838
{
39+
_view.OldMethodName = _model.SourceMember.IdentifierName;
3940
_view.MethodName = _model.SourceMember.IdentifierName + "_1";
4041
_view.Inputs = _model.Inputs;
4142
_view.Outputs = _model.Outputs;

RetailCoder.VBE/Refactorings/ExtractMethod/IExtractMethodDialog.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ public interface IExtractMethodDialog : IDialogView
1515
string Preview { get; set; }
1616

1717
string MethodName { get; set; }
18+
string OldMethodName { get; set; }
1819
Accessibility Accessibility { get; set; }
1920
bool SetReturnValue { get; set; }
2021
ExtractedParameter ReturnValue { get; set; }

RetailCoder.VBE/UI/Refactorings/ExtractMethodDialog.Designer.cs

Lines changed: 60 additions & 43 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)