Skip to content

Commit 1b00de3

Browse files
committed
Merge pull request #887 from Hosch250/BugBlipper
Change signature for all methods that implement an interface after pr…
2 parents e34fe49 + 876af05 commit 1b00de3

File tree

3 files changed

+53
-4
lines changed

3 files changed

+53
-4
lines changed

RetailCoder.VBE/Refactorings/IntroduceParameter/IntroduceParameterRefactoring.cs

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Linq;
4+
using System.Windows.Forms;
45
using Antlr4.Runtime.Misc;
56
using Microsoft.Vbe.Interop;
67
using Rubberduck.Common;
@@ -69,10 +70,34 @@ public void Refactor(Declaration target)
6970

7071
private void PromoteVariable(Declaration target)
7172
{
73+
if (!PromptIfMethodImplementsInterface(target))
74+
{
75+
return;
76+
}
77+
7278
RemoveVariable(target);
7379
UpdateSignature(target);
7480
}
7581

82+
private bool PromptIfMethodImplementsInterface(Declaration targetVariable)
83+
{
84+
var functionDeclaration = _declarations.FindSelection(targetVariable.QualifiedSelection, ValidDeclarationTypes);
85+
var interfaceImplementation = GetInterfaceImplementation(functionDeclaration);
86+
87+
if (interfaceImplementation == null)
88+
{
89+
return true;
90+
}
91+
92+
var message = string.Format(RubberduckUI.IntroduceParameter_PromptIfTargetIsInterface,
93+
functionDeclaration.IdentifierName, interfaceImplementation.ComponentName,
94+
interfaceImplementation.IdentifierName);
95+
var introduceParamToInterface = _messageBox.Show(message, RubberduckUI.IntroduceParameter_Caption,
96+
MessageBoxButtons.YesNo, MessageBoxIcon.Question);
97+
98+
return introduceParamToInterface != DialogResult.No;
99+
}
100+
76101
private void UpdateSignature(Declaration targetVariable)
77102
{
78103
var functionDeclaration = _declarations.FindSelection(targetVariable.QualifiedSelection, ValidDeclarationTypes);
@@ -91,9 +116,20 @@ private void UpdateSignature(Declaration targetVariable)
91116
}
92117

93118
var interfaceImplementation = GetInterfaceImplementation(functionDeclaration);
94-
if (interfaceImplementation != null)
119+
if (interfaceImplementation == null)
120+
{
121+
return;
122+
}
123+
UpdateSignature(interfaceImplementation, targetVariable);
124+
125+
var interfaceImplementations = _declarations.FindInterfaceImplementationMembers()
126+
.Where(item => item.Project.Equals(interfaceImplementation.Project)
127+
&& item.IdentifierName == interfaceImplementation.ComponentName + "_" + interfaceImplementation.IdentifierName
128+
&& !item.Equals(functionDeclaration));
129+
130+
foreach (var implementation in interfaceImplementations)
95131
{
96-
UpdateSignature(interfaceImplementation, targetVariable);
132+
UpdateSignature(implementation, targetVariable);
97133
}
98134
}
99135

RetailCoder.VBE/UI/RubberduckUI.Designer.cs

Lines changed: 10 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

RetailCoder.VBE/UI/RubberduckUI.resx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@
262262
<value>Remove parameters</value>
263263
</data>
264264
<data name="Refactoring_TargetIsInterfaceMemberImplementation" xml:space="preserve">
265-
<value>Method '{0}' implements '{1}.{2}'. Change interface signature? (will propagate to all implementations)</value>
265+
<value>Method '{0}' implements '{1}.{2}'. Change interface signature? (Will propagate to all implementations.)</value>
266266
<comment>0: Selected target; 1: Interface name; 2: Interface member name</comment>
267267
</data>
268268
<data name="RemoveParamsDialog_RemoveIllegalSetterLetterParameter" xml:space="preserve">
@@ -1281,4 +1281,8 @@ Are you sure you want to proceed with this rename?</value>
12811281
<data name="IntroduceParameter_Caption" xml:space="preserve">
12821282
<value>Rubberduck - Introduce Parameter</value>
12831283
</data>
1284+
<data name="IntroduceParameter_PromptIfTargetIsInterface" xml:space="preserve">
1285+
<value>Method '{0}' implements '{1}.{2}'. Change interface signature? (Will propagate to all implementations.)</value>
1286+
<comment>0: Selected target; 1: Interface name; 2: Interface member name</comment>
1287+
</data>
12841288
</root>

0 commit comments

Comments
 (0)