Skip to content

Commit c1f4435

Browse files
committed
Stop renaming default member accesses
They do not show the identifier. So, there is nothing to change.
1 parent 7f04a16 commit c1f4435

File tree

2 files changed

+80
-1
lines changed

2 files changed

+80
-1
lines changed

Rubberduck.Refactorings/Rename/RenameRefactoring.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,8 @@ private void RenameReferences(Declaration target, string newName, IRewriteSessio
466466
var modules = target.References
467467
.Where(reference =>
468468
reference.Context.GetText() != "Me"
469-
&& !reference.IsArrayAccess)
469+
&& !reference.IsArrayAccess
470+
&& !reference.IsDefaultMemberAccess)
470471
.GroupBy(r => r.QualifiedModuleName);
471472

472473
foreach (var grouping in modules)

RubberduckTests/Refactoring/Rename/RenameTests.cs

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -683,6 +683,84 @@ End Sub"
683683
PerformExpectedVersusActualRenameTests(tdo, inputOutput);
684684
}
685685

686+
[Test]
687+
[Category("Refactorings")]
688+
[Category("Rename")]
689+
public void RenameRefactoring_RenameFunction_DoesNotChangeIndexedDefaultMemberCalls()
690+
{
691+
var tdo = new RenameTestsDataObject(selectedIdentifier: "Foo", newName: "Goo");
692+
var defaultMemberInputOutput = new RenameTestModuleDefinition("ClassFoo")
693+
{
694+
Input =
695+
@"Public Function Fo|o(arg As String) As Boolean
696+
Attribute Foo.VB_UserMemId = 0
697+
Foo = True
698+
End Function",
699+
//TODO: Make it possible that the attribute survives this appropriately adjusted.
700+
//The VBE will remove the now invalid attribute, which does not happen in tests.
701+
Expected =
702+
@"Public Function Goo(arg As String) As Boolean
703+
Attribute Foo.VB_UserMemId = 0
704+
Goo = True
705+
End Function"
706+
};
707+
var callingModuleInputOutput = new RenameTestModuleDefinition("TestModule", ComponentType.StandardModule)
708+
{
709+
Input =
710+
@"Private Function Baz(arg As String) As Boolean
711+
Dim bar As ClassFoo
712+
Set bar = New ClassFoo
713+
Baz = bar(arg)
714+
End Function",
715+
Expected =
716+
@"Private Function Baz(arg As String) As Boolean
717+
Dim bar As ClassFoo
718+
Set bar = New ClassFoo
719+
Baz = bar(arg)
720+
End Function"
721+
};
722+
PerformExpectedVersusActualRenameTests(tdo, defaultMemberInputOutput, callingModuleInputOutput);
723+
}
724+
725+
[Test]
726+
[Category("Refactorings")]
727+
[Category("Rename")]
728+
public void RenameRefactoring_RenameFunction_DoesNotChangeNonIndexedDefaultMemberCalls()
729+
{
730+
var tdo = new RenameTestsDataObject(selectedIdentifier: "Foo", newName: "Goo");
731+
var defaultMemberInputOutput = new RenameTestModuleDefinition("ClassFoo")
732+
{
733+
Input =
734+
@"Public Function Fo|o() As Boolean
735+
Attribute Foo.VB_UserMemId = 0
736+
Foo = True
737+
End Function",
738+
//TODO: Make it possible that the attribute survives this appropriately adjusted.
739+
//The VBE will remove the now invalid attribute, which does not happen in tests.
740+
Expected =
741+
@"Public Function Goo() As Boolean
742+
Attribute Foo.VB_UserMemId = 0
743+
Goo = True
744+
End Function"
745+
};
746+
var callingModuleInputOutput = new RenameTestModuleDefinition("TestModule", ComponentType.StandardModule)
747+
{
748+
Input =
749+
@"Private Function Baz(arg As String) As Boolean
750+
Dim bar As ClassFoo
751+
Set bar = New ClassFoo
752+
Baz = bar
753+
End Function",
754+
Expected =
755+
@"Private Function Baz(arg As String) As Boolean
756+
Dim bar As ClassFoo
757+
Set bar = New ClassFoo
758+
Baz = bar
759+
End Function"
760+
};
761+
PerformExpectedVersusActualRenameTests(tdo, defaultMemberInputOutput, callingModuleInputOutput);
762+
}
763+
686764
[Test]
687765
[Category("Refactorings")]
688766
[Category("Rename")]

0 commit comments

Comments
 (0)