Skip to content
Permalink
Browse files

Stop renaming references to Me

Class module references to Me should not be renamed to not break the
code.
Fixes #2710
  • Loading branch information...
Vogel612 committed Nov 25, 2017
1 parent 2c7c83e commit 002efc86985ee643d0f436ae3d577aa6e36c9292
@@ -476,7 +476,9 @@ private void RenameStandardElements(Declaration target, string newName)

private void RenameReferences(Declaration target, string newName)
{
var modules = target.References.GroupBy(r => r.QualifiedModuleName);
var modules = target.References
.Where(reference => reference.Context.GetText() != "Me")
.GroupBy(r => r.QualifiedModuleName);
foreach (var grouping in modules)
{
_modulesToRewrite.Add(grouping.Key);
@@ -1962,6 +1962,48 @@ public void RenameRefactoring_RenameViewModel_IsValidName_ChangeCasingNotValid()
Assert.IsFalse(renameViewModel.IsValidName);
}


[TestMethod]
[TestCategory("Refactorings")]
[TestCategory("Rename")]
public void RenameRefactoring_RenameClassModule_DoesNotChangeMeReferences()
{
const string newName = "RenamedClassModule";

//Input
const string inputCode =
@"Property Get Self() As IClassModule
Set Self = Me
End Property";

var selection = new Selection(3, 27, 3, 27);

IVBComponent component;
var vbe = MockVbeBuilder.BuildFromSingleModule(inputCode, "ClassModule1", ComponentType.ClassModule, out component, selection);
using (var state = MockParser.CreateAndParse(vbe.Object))
{

var qualifiedSelection = new QualifiedSelection(new QualifiedModuleName(component), selection);

var msgbox = new Mock<IMessageBox>();
msgbox.Setup(m => m.Show(It.IsAny<string>(), It.IsAny<string>(), MessageBoxButtons.YesNo, It.IsAny<MessageBoxIcon>()))
.Returns(DialogResult.Yes);

var vbeWrapper = vbe.Object;
var model = new RenameModel(vbeWrapper, state, qualifiedSelection) { NewName = newName };
model.Target = model.Declarations.FirstOrDefault(i => i.DeclarationType == DeclarationType.ClassModule && i.IdentifierName == "ClassModule1");

//SetupFactory
var factory = SetupFactory(model);

var refactoring = new RenameRefactoring(vbeWrapper, factory.Object, msgbox.Object, state);
refactoring.Refactor(model.Target);

Assert.AreSame(newName, component.CodeModule.Name);
Assert.AreEqual(inputCode, component.CodeModule.GetLines(0, component.CodeModule.CountOfLines));
}

}
#endregion

#region Test Execution

0 comments on commit 002efc8

Please sign in to comment.
You can’t perform that action at this time.