Пример #1
0
        protected override void OnExecute(object parameter)
        {
            var factory     = new RenamePresenterFactory(_vbe, _view, _state);
            var refactoring = new RenameRefactoring(_vbe, factory, _msgBox, _state);

            refactoring.Refactor(((ICodeExplorerDeclarationViewModel)parameter).Declaration);
        }
        protected override void OnExecute(object parameter)
        {
            Declaration target;

            using (var activePane = Vbe.ActiveCodePane)
            {
                if (activePane == null || activePane.IsWrappingNullReference)
                {
                    return;
                }

                if (parameter != null)
                {
                    target = parameter as Declaration;
                }
                else
                {
                    target = _state.FindSelectedDeclaration(activePane);
                }
            }

            if (target == null || !target.IsUserDefined)
            {
                return;
            }

            using (var view = new RenameDialog(new RenameViewModel(_state)))
            {
                var factory     = new RenamePresenterFactory(Vbe, view, _state);
                var refactoring = new RenameRefactoring(Vbe, factory, _messageBox, _state, _state.ProjectsProvider, _rewritingManager);

                refactoring.Refactor(target);
            }
        }
Пример #3
0
        private void Rename()
        {
            var progress = new ParsingProgressPresenter();
            var result   = progress.Parse(_parser, _vbe.ActiveVBProject);

            var designer = (dynamic)_vbe.SelectedVBComponent.Designer;

            foreach (var control in designer.Controls)
            {
                if (!control.InSelection)
                {
                    continue;
                }

                var controlToRename =
                    result.Declarations.Items
                    .FirstOrDefault(item => item.IdentifierName == control.Name &&
                                    item.ComponentName == _vbe.SelectedVBComponent.Name &&
                                    _vbe.ActiveVBProject.Equals(item.Project));

                using (var view = new RenameDialog())
                {
                    var factory     = new RenamePresenterFactory(_vbe, view, result);
                    var refactoring = new RenameRefactoring(factory);
                    refactoring.Refactor(controlToRename);
                }
            }
        }
        protected override void ExecuteImpl(object parameter)
        {
            if (Vbe.ActiveCodePane == null)
            {
                return;
            }

            Declaration target;

            if (parameter != null)
            {
                target = parameter as Declaration;
            }
            else
            {
                target = _state.FindSelectedDeclaration(Vbe.ActiveCodePane);
            }

            if (target == null)
            {
                return;
            }

            using (var view = new RenameDialog())
            {
                var factory     = new RenamePresenterFactory(Vbe, view, _state, new MessageBox());
                var refactoring = new RenameRefactoring(Vbe, factory, new MessageBox(), _state);

                refactoring.Refactor(target);
            }
        }
Пример #5
0
        public void Rename_PresenterIsNull()
        {
            //Input
            const string inputCode =
                @"Private Sub Foo()
End Sub";

            IVBComponent component;
            var          vbe   = MockVbeBuilder.BuildFromSingleStandardModule(inputCode, out component);
            var          state = MockParser.CreateAndParse(vbe.Object);

            var codePaneMock = new Mock <ICodePane>();

            codePaneMock.Setup(c => c.CodeModule).Returns(component.CodeModule);
            codePaneMock.Setup(c => c.Selection);
            vbe.Setup(v => v.ActiveCodePane).Returns(codePaneMock.Object);

            var vbeWrapper = vbe.Object;
            var factory    = new RenamePresenterFactory(vbeWrapper, null, state, null);

            var refactoring = new RenameRefactoring(vbeWrapper, factory, null, state);

            refactoring.Refactor();

            Assert.AreEqual(inputCode, component.CodeModule.Content());
        }
Пример #6
0
        protected override void OnExecute(object parameter)
        {
            if (Vbe.ActiveCodePane == null)
            {
                return;
            }

            Declaration target;

            if (parameter != null)
            {
                target = parameter as Declaration;
            }
            else
            {
                target = _state.FindSelectedDeclaration(Vbe.ActiveCodePane);
            }

            if (target == null || !target.IsUserDefined)
            {
                return;
            }

            using (var view = new RenameDialog(new RenameViewModel(_state)))
            {
                var factory     = new RenamePresenterFactory(Vbe, view, _state);
                var refactoring = new RenameRefactoring(Vbe, factory, _messageBox, _state);

                refactoring.Refactor(target);
            }
        }
Пример #7
0
        public void RenameRefactoring_InterfaceRenamed_AcceptPrompt()
        {
            //Input
            const string inputCode1 =
                @"Implements IClass1

Private Sub IClass1_DoSomething(ByVal a As Integer, ByVal b As String)
End Sub";
            const string inputCode2 =
                @"Public Sub DoSomething(ByVal a As Integer, ByVal b As String)
End Sub";

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

            //Expectation
            const string expectedCode1 =
                @"Implements IClass1

Private Sub IClass1_DoNothing(ByVal a As Integer, ByVal b As String)
End Sub";
            const string expectedCode2 =
                @"Public Sub DoNothing(ByVal a As Integer, ByVal b As String)
End Sub";

            var builder = new MockVbeBuilder();
            var project = builder.ProjectBuilder("TestProject1", ProjectProtection.Unprotected)
                          .AddComponent("Class1", ComponentType.ClassModule, inputCode1)
                          .AddComponent("IClass1", ComponentType.ClassModule, inputCode2)
                          .Build();
            var vbe = builder.AddProject(project).Build();

            var state = MockParser.CreateAndParse(vbe.Object);

            var qualifiedSelection = new QualifiedSelection(new QualifiedModuleName(project.Object.VBComponents[0]), selection);

            var module1 = project.Object.VBComponents[0].CodeModule;
            var module2 = project.Object.VBComponents[1].CodeModule;

            var messageBox = new Mock <IMessageBox>();

            messageBox.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, messageBox.Object)
            {
                NewName = "DoNothing"
            };

            //SetupFactory
            var factory = SetupFactory(model);

            var refactoring = new RenameRefactoring(vbeWrapper, factory.Object, messageBox.Object, state);

            refactoring.Refactor(model.Selection);

            Assert.AreEqual(expectedCode1, module1.Content());
            Assert.AreEqual(expectedCode2, module2.Content());
        }
Пример #8
0
        public void RenameRefactoring_RenameLastPropertyParameter_UpdatesRelatedParametersWithSameName()
        {
            //Input
            const string inputCode =
                @"Property Get Foo(ByVal index As Integer) As Variant
End Property

Property Let Foo(ByVal index As Integer, ByVal value As Variant)
    Dim d As Variant
    d = value
End Property

Property Set Foo(ByVal index As Integer, ByVal fizz As Variant)
    Dim d As Variant
    d = fizz
End Property";
            var selection = new Selection(4, 50, 4, 50);

            //Expectation
            const string expectedCode =
                @"Property Get Foo(ByVal index As Integer) As Variant
End Property

Property Let Foo(ByVal index As Integer, ByVal renamed As Variant)
    Dim d As Variant
    d = renamed
End Property

Property Set Foo(ByVal index As Integer, ByVal fizz As Variant)
    Dim d As Variant
    d = fizz
End Property";

            IVBComponent component;
            var          vbe   = MockVbeBuilder.BuildFromSingleStandardModule(inputCode, out component, selection);
            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, msgbox.Object)
            {
                NewName = "renamed"
            };

            //SetupFactory
            var factory = SetupFactory(model);

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

            refactoring.Refactor(qualifiedSelection);

            Assert.AreEqual(expectedCode, component.CodeModule.Content());
        }
Пример #9
0
        public void RenameRefactoring_RenameEvent()
        {
            //Input
            const string inputCode1 =
                @"Public Event Foo(ByVal arg1 As Integer, ByVal arg2 As String)";
            const string inputCode2 =
                @"Private WithEvents abc As Class1

Private Sub abc_Foo(ByVal i As Integer, ByVal s As String)
End Sub";

            var selection = new Selection(1, 16, 1, 16);

            //Expectation
            const string expectedCode1 =
                @"Public Event Goo(ByVal arg1 As Integer, ByVal arg2 As String)";
            const string expectedCode2 =
                @"Private WithEvents abc As Class1

Private Sub abc_Goo(ByVal i As Integer, ByVal s As String)
End Sub";

            var builder = new MockVbeBuilder();
            var project = builder.ProjectBuilder("TestProject1", ProjectProtection.Unprotected)
                          .AddComponent("Class1", ComponentType.ClassModule, inputCode1)
                          .AddComponent("Class2", ComponentType.ClassModule, inputCode2)
                          .Build();
            var vbe = builder.AddProject(project).Build();

            var state = MockParser.CreateAndParse(vbe.Object);

            var qualifiedSelection = new QualifiedSelection(new QualifiedModuleName(project.Object.VBComponents[0]), selection);

            var module1 = project.Object.VBComponents[0].CodeModule;
            var module2 = project.Object.VBComponents[1].CodeModule;

            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, msgbox.Object)
            {
                NewName = "Goo"
            };

            //SetupFactory
            var factory = SetupFactory(model);

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

            refactoring.Refactor(qualifiedSelection);

            Assert.AreEqual(expectedCode1, module1.Content());
            Assert.AreEqual(expectedCode2, module2.Content());
        }
Пример #10
0
 //The rewriteSession is optional since it is not used in this particular quickfix because it is a refactoring quickfix.
 public override void Fix(IInspectionResult result, IRewriteSession rewriteSession = null)
 {
     using (var view = new RenameDialog(new RenameViewModel(_state)))
     {
         var factory     = new RenamePresenterFactory(_vbe, view, _state);
         var refactoring = new RenameRefactoring(_vbe, factory, _messageBox, _state, _state.ProjectsProvider, _rewritingManager);
         refactoring.Refactor(result.Target);
     }
 }
Пример #11
0
 public override void Fix(IInspectionResult result)
 {
     using (var view = new RenameDialog(new RenameViewModel(_state)))
     {
         var factory     = new RenamePresenterFactory(_vbe, view, _state);
         var refactoring = new RenameRefactoring(_vbe, factory, _messageBox, _state);
         refactoring.Refactor(result.Target);
     }
 }
        protected override void OnExecute(object parameter)
        {
            var refactoring = new RenameRefactoring(_factory, _msgBox, _state, _state.ProjectsProvider, RewritingManager, SelectionService);
            var target      = GetTarget();

            if (target != null)
            {
                refactoring.Refactor(target);
            }
        }
Пример #13
0
        private void RenameProject()
        {
            var vbe = QualifiedSelection.QualifiedName.Project.VBE;

            using (var view = new RenameDialog())
            {
                var factory     = new RenamePresenterFactory(vbe, view, _parseResult);
                var refactoring = new RenameRefactoring(factory);
                refactoring.Refactor(Target);
            }
        }
Пример #14
0
        public void RenameRefactoring_RenameFunction_UpdatesReferences()
        {
            //Input
            const string inputCode =
                @"Private Function Foo() As Boolean
    Foo = True
End Function

Private Sub Goo()
    Dim var1 As Boolean
    var1 = Foo()
End Sub
";
            var selection = new Selection(1, 21, 1, 21);

            //Expectation
            const string expectedCode =
                @"Private Function Hoo() As Boolean
    Hoo = True
End Function

Private Sub Goo()
    Dim var1 As Boolean
    var1 = Hoo()
End Sub
";

            IVBComponent component;
            var          vbe   = MockVbeBuilder.BuildFromSingleStandardModule(inputCode, out component, selection);
            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, msgbox.Object)
            {
                NewName = "Hoo"
            };

            //SetupFactory
            var factory = SetupFactory(model);

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

            refactoring.Refactor(qualifiedSelection);

            Assert.AreEqual(expectedCode, component.CodeModule.Content());
        }
Пример #15
0
        public void Rename(Declaration target)
        {
            var progress = new ParsingProgressPresenter();
            var result   = progress.Parse(_parser, IDE.ActiveVBProject);

            using (var view = new RenameDialog())
            {
                var factory     = new RenamePresenterFactory(IDE, view, result);
                var refactoring = new RenameRefactoring(factory);
                refactoring.Refactor(target);
            }
        }
        public override void Fix()
        {
            var vbe = _target.Project.VBE;

            using (var view = new RenameDialog(new RenameViewModel(_state)))
            {
                var factory     = new RenamePresenterFactory(vbe, view, _state, _messageBox);
                var refactoring = new RenameRefactoring(vbe, factory, _messageBox, _state);
                refactoring.Refactor(_target);
                IsCancelled = view.DialogResult == DialogResult.Cancel;
            }
        }
Пример #17
0
        public override void Fix()
        {
            var vbe = Selection.QualifiedName.Project.VBE;

            using (var view = new RenameDialog())
            {
                var factory     = new RenamePresenterFactory(vbe, view, _state, new MessageBox());
                var refactoring = new RenameRefactoring(vbe, factory, new MessageBox(), _state);
                refactoring.Refactor(_target);
                IsCancelled = view.DialogResult == DialogResult.Cancel;
            }
        }
Пример #18
0
        protected override void OnExecute(object parameter)
        {
            if (!EvaluateCanExecute(parameter) ||
                !(parameter is CodeExplorerItemViewModel node) ||
                node.Declaration == null)
            {
                return;
            }

            var refactoring = new RenameRefactoring(_factory, _msgBox, _state, _state.ProjectsProvider, _rewritingManager, _selectionService);

            refactoring.Refactor(node.Declaration);
        }
Пример #19
0
        protected override void OnExecute(object parameter)
        {
            using (var view = new RenameDialog(new RenameViewModel(_state)))
            {
                var factory     = new RenamePresenterFactory(Vbe, view, _state);
                var refactoring = new RenameRefactoring(Vbe, factory, _msgBox, _state, _state.ProjectsProvider, _rewritingManager);

                var target = GetTarget();

                if (target != null)
                {
                    refactoring.Refactor(target);
                }
            }
        }
Пример #20
0
        public override void Execute(object parameter)
        {
            using (var view = new RenameDialog())
            {
                var factory     = new RenamePresenterFactory(Vbe, view, _state, _msgBox);
                var refactoring = new RenameRefactoring(Vbe, factory, _msgBox, _state);

                var target = GetTarget();

                if (target != null)
                {
                    refactoring.Refactor(target);
                }
            }
        }
        public override void Execute(object parameter)
        {
            using (var view = new RenameDialog())
            {
                var factory     = new RenamePresenterFactory(Vbe, view, _state, new MessageBox(), _wrapperWrapperFactory);
                var refactoring = new RenameRefactoring(factory, Editor, new MessageBox(), _state);

                var target = GetTarget();

                if (target != null)
                {
                    refactoring.Refactor(target);
                }
            }
        }
        protected override void ExecuteImpl(object parameter)
        {
            using (var view = new RenameDialog(new RenameViewModel(_state)))
            {
                var factory     = new RenamePresenterFactory(Vbe, view, _state, _messageBox);
                var refactoring = new RenameRefactoring(Vbe, factory, _messageBox, _state);

                var target = GetTarget();

                if (target != null)
                {
                    refactoring.Refactor(target);
                }
            }
        }
        private void Rename_Click(CommandBarButton Ctrl, ref bool CancelDefault)
        {
            VBProjectParseResult results;
            var declaration = FindSelectedDeclaration(out results);

            if (declaration == null)
            {
                return;
            }

            using (var view = new RenameDialog())
            {
                var factory     = new RenamePresenterFactory(_vbe, view, results);
                var refactoring = new RenameRefactoring(factory);
                refactoring.Refactor(declaration);
            }
        }
Пример #24
0
        public void RenameRefactoring_RenameGetterAndLetter()
        {
            //Input
            const string inputCode =
                @"Private Property Get Foo() 
End Property

Private Property Let Foo(ByVal arg1 As String) 
End Property";
            var selection = new Selection(1, 25, 1, 25);

            //Expectation
            const string expectedCode =
                @"Private Property Get Goo() 
End Property

Private Property Let Goo(ByVal arg1 As String) 
End Property";

            IVBComponent component;
            var          vbe   = MockVbeBuilder.BuildFromSingleStandardModule(inputCode, out component, selection);
            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, msgbox.Object)
            {
                NewName = "Goo"
            };

            //SetupFactory
            var factory = SetupFactory(model);

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

            refactoring.Refactor(qualifiedSelection);

            Assert.AreEqual(expectedCode, component.CodeModule.Content());
        }
Пример #25
0
        public void RenameRefactoring_RenameSub_ConflictingNames_Accept()
        {
            //Input
            const string inputCode =
                @"Private Sub Foo()
    Dim Goo As Integer
End Sub";
            var selection = new Selection(1, 14, 1, 14);

            //Expectation
            const string expectedCode =
                @"Private Sub Goo()
    Dim Goo As Integer
End Sub";

            IVBComponent component;
            var          vbe   = MockVbeBuilder.BuildFromSingleStandardModule(inputCode, out component, selection);
            var          state = MockParser.CreateAndParse(vbe.Object);

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

            var vbeWrapper = vbe.Object;
            var model      = new RenameModel(vbeWrapper, state, qualifiedSelection, null)
            {
                NewName = "Goo"
            };

            //SetupFactory
            var factory = SetupFactory(model);

            var messageBox = new Mock <IMessageBox>();

            messageBox.Setup(
                m =>
                m.Show(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <MessageBoxButtons>(),
                       It.IsAny <MessageBoxIcon>())).Returns(DialogResult.Yes);

            var refactoring = new RenameRefactoring(vbeWrapper, factory.Object, messageBox.Object, state);

            refactoring.Refactor(qualifiedSelection);

            Assert.AreEqual(expectedCode, component.CodeModule.Content());
        }
Пример #26
0
        protected override void OnExecute(object parameter)
        {
            var activeSelection = SelectionService.ActiveSelection();

            if (!activeSelection.HasValue)
            {
                return;
            }

            var target = _state.DeclarationFinder.FindSelectedDeclaration(activeSelection.Value);

            if (target == null || !target.IsUserDefined)
            {
                return;
            }

            var refactoring = new RenameRefactoring(_factory, _messageBox, _state, _state.ProjectsProvider, RewritingManager, SelectionService);

            refactoring.Refactor(target);
        }
Пример #27
0
        public void RenameRefactoring_RenameCodeModule()
        {
            const string newName = "RenameModule";

            //Input
            const string inputCode =
                @"Private Sub Foo(ByVal a As Integer, ByVal b As String)
End Sub";

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

            IVBComponent component;
            var          vbe   = MockVbeBuilder.BuildFromSingleModule(inputCode, "Class1", ComponentType.ClassModule, out component, selection);
            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, msgbox.Object)
            {
                NewName = newName
            };

            model.Target = model.Declarations.FirstOrDefault(i => i.DeclarationType == DeclarationType.ClassModule && i.IdentifierName == "Class1");

            //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);
        }
Пример #28
0
        public void RenameRefactoring_RenameProject()
        {
            const string oldName = "TestProject1";
            const string newName = "Renamed";

            var builder = new MockVbeBuilder();
            var vbe     = builder.ProjectBuilder(oldName, ProjectProtection.Unprotected)
                          .AddComponent("Module1", ComponentType.StandardModule, string.Empty)
                          .MockVbeBuilder()
                          .Build();


            var state = MockParser.CreateAndParse(vbe.Object);

            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, default(QualifiedSelection), msgbox.Object)
            {
                NewName = newName
            };

            model.Target = model.Declarations.First(i => i.DeclarationType == DeclarationType.Project && !i.IsBuiltIn);

            //SetupFactory
            var factory = SetupFactory(model);

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

            refactoring.Refactor(model.Target);

            Assert.AreEqual(newName, vbe.Object.VBProjects[0].Name);
        }
        //The rewriteSession is optional since it is not used in this particular quickfix because it is a refactoring quickfix.
        public override void Fix(IInspectionResult result, IRewriteSession rewriteSession = null)
        {
            var refactoring = new RenameRefactoring(_factory, _messageBox, _state, _state.ProjectsProvider, _rewritingManager, _selectionService);

            refactoring.Refactor(result.Target);
        }