public void GivenPrivateSub_DefaultQuickFixRemovesParameter() { const string inputCode = @" Private Sub Foo(ByVal arg1 as Integer) End Sub"; const string expectedCode = @" Private Sub Foo() End Sub"; var vbe = MockVbeBuilder.BuildFromSingleStandardModule(inputCode, out var component); var(state, rewritingManager) = MockParser.CreateAndParseWithRewritingManager(vbe.Object); using (state) { var inspection = new ParameterNotUsedInspection(state); var inspectionResults = inspection.GetInspectionResults(CancellationToken.None); var rewriteSession = rewritingManager.CheckOutCodePaneSession(); var selectionService = MockedSelectionService(); var factory = new Mock <IRefactoringPresenterFactory>().Object; var selectedDeclarationProvider = new SelectedDeclarationProvider(selectionService, state); var uiDispatcherMock = new Mock <IUiDispatcher>(); uiDispatcherMock .Setup(m => m.Invoke(It.IsAny <Action>())) .Callback((Action action) => action.Invoke()); var refactoring = new RemoveParametersRefactoring(state, factory, rewritingManager, selectionService, selectedDeclarationProvider, uiDispatcherMock.Object); new RemoveUnusedParameterQuickFix(refactoring) .Fix(inspectionResults.First(), rewriteSession); Assert.AreEqual(expectedCode, component.CodeModule.Content()); } }
public override IEnumerable <InspectionResultBase> GetInspectionResults() { var declarations = UserDeclarations.ToList(); var interfaceMemberScopes = declarations.FindInterfaceMembers().Select(m => m.Scope).ToList(); var interfaceImplementationMemberScopes = declarations.FindInterfaceImplementationMembers().Select(m => m.Scope).ToList(); var builtInHandlers = State.AllDeclarations.FindBuiltInEventHandlers(); var parameters = declarations.Where(parameter => parameter.DeclarationType == DeclarationType.Parameter && parameter.ParentDeclaration.DeclarationType != DeclarationType.Event && parameter.ParentDeclaration.DeclarationType != DeclarationType.LibraryFunction && parameter.ParentDeclaration.DeclarationType != DeclarationType.LibraryProcedure); var unused = parameters.Where(parameter => !parameter.References.Any()).ToList(); var quickFixRefactoring = new RemoveParametersRefactoring(_vbe, new RemoveParametersPresenterFactory(_vbe, new RemoveParametersDialog(), State, _messageBox)); var issues = from issue in unused.Where(parameter => !IsInterfaceMemberParameter(parameter, interfaceMemberScopes) && !builtInHandlers.Contains(parameter.ParentDeclaration)) let isInterfaceImplementationMember = IsInterfaceMemberImplementationParameter(issue, interfaceImplementationMemberScopes) select new ParameterNotUsedInspectionResult(this, issue, ((dynamic)issue.Context).unrestrictedIdentifier(), issue.QualifiedName, isInterfaceImplementationMember, quickFixRefactoring, State); return(issues.ToList()); }
public void RemoveParamatersRefactoring_RemoveOnlyParam() { //Input const string inputCode = @"Private Sub Foo(ByVal arg1 As Integer) End Sub"; var selection = new Selection(1, 23, 1, 27); //startLine, startCol, endLine, endCol //Expectation const string expectedCode = @"Private Sub Foo() End Sub"; //Arrange SetupProject(inputCode); var parseResult = new RubberduckParser().Parse(_project.Object); var qualifiedSelection = GetQualifiedSelection(selection); //Specify Params to remove var model = new RemoveParametersModel(parseResult, qualifiedSelection); model.Parameters.ForEach(arg => arg.IsRemoved = true); //SetupFactory var factory = SetupFactory(model); //Act var refactoring = new RemoveParametersRefactoring(factory.Object); refactoring.Refactor(qualifiedSelection); //Assert Assert.AreEqual(expectedCode, _module.Object.Lines()); }
public void RemoveParamatersRefactoring_RemoveFirstParam() { //Input const string inputCode = @"Private Sub Foo(ByVal arg1 As Integer, ByVal arg2 As String) End Sub"; var selection = new Selection(1, 23, 1, 27); //startLine, startCol, endLine, endCol //Expectation const string expectedCode = @"Private Sub Foo( ByVal arg2 As String) End Sub"; //note: The IDE strips out the extra whitespace //Arrange SetupProject(inputCode); var parseResult = new RubberduckParser().Parse(_project.Object); var qualifiedSelection = GetQualifiedSelection(selection); //Specify Param(s) to remove var model = new RemoveParametersModel(parseResult, qualifiedSelection); model.Parameters[0].IsRemoved = true; //SetupFactory var factory = SetupFactory(model); //Act var refactoring = new RemoveParametersRefactoring(factory.Object); refactoring.Refactor(qualifiedSelection); //Assert Assert.AreEqual(expectedCode, _module.Object.Lines()); }
public override IEnumerable <InspectionResultBase> GetInspectionResults() { var declarations = UserDeclarations.ToList(); var interfaceMemberScopes = declarations.FindInterfaceMembers().Select(m => m.Scope).ToList(); var interfaceImplementationMemberScopes = declarations.FindInterfaceImplementationMembers().Select(m => m.Scope).ToList(); var builtInHandlers = declarations.FindBuiltInEventHandlers(); var parameters = declarations.Where(parameter => parameter.DeclarationType == DeclarationType.Parameter && !(parameter.Context.Parent.Parent is VBAParser.EventStmtContext) && !(parameter.Context.Parent.Parent is VBAParser.DeclareStmtContext)); var unused = parameters.Where(parameter => !parameter.References.Any()).ToList(); var editor = new ActiveCodePaneEditor(_vbe, _wrapperFactory); var quickFixRefactoring = new RemoveParametersRefactoring( new RemoveParametersPresenterFactory(editor, new RemoveParametersDialog(), State, _messageBox), editor); var issues = from issue in unused.Where(parameter => !IsInterfaceMemberParameter(parameter, interfaceMemberScopes) && !builtInHandlers.Contains(parameter.ParentDeclaration)) let isInterfaceImplementationMember = IsInterfaceMemberImplementationParameter(issue, interfaceImplementationMemberScopes) select new ParameterNotUsedInspectionResult(this, issue, ((dynamic)issue.Context).identifier(), issue.QualifiedName, isInterfaceImplementationMember, quickFixRefactoring, State); return(issues.ToList()); }
public RemoveUnusedParameterQuickFix(ParserRuleContext context, QualifiedSelection selection, RemoveParametersRefactoring quickFixRefactoring, RubberduckParserState parseResult) : base(context, selection, InspectionsUI.RemoveUnusedParameterQuickFix) { _quickFixRefactoring = quickFixRefactoring; _parseResult = parseResult; }
public ParameterNotUsedInspectionResult(string inspection, CodeInspectionSeverity type, ParserRuleContext context, QualifiedMemberName qualifiedName, bool isInterfaceImplementation, RemoveParametersRefactoring quickFixRefactoring, VBProjectParseResult parseResult) : base(inspection, type, qualifiedName.QualifiedModuleName, context) { _isInterfaceImplementation = isInterfaceImplementation; _quickFixRefactoring = quickFixRefactoring; _parseResult = parseResult; }
public override void Fix() { using (var dialog = new RemoveParametersDialog(new RemoveParametersViewModel(_state))) { var refactoring = new RemoveParametersRefactoring(_vbe, new RemoveParametersPresenterFactory(_vbe, dialog, _state, _messageBox)); refactoring.QuickFix(_state, Selection); } }
protected override void OnExecute(object parameter) { var selection = Vbe.GetActiveSelection(); using (var view = new RemoveParametersDialog(new RemoveParametersViewModel(_state))) { var factory = new RemoveParametersPresenterFactory(Vbe, view, _state, _msgbox); var refactoring = new RemoveParametersRefactoring(Vbe, factory, _rewritingManager); refactoring.Refactor(selection.Value); } }
public ParameterNotUsedInspectionResult(IInspection inspection, Declaration target, ParserRuleContext context, QualifiedMemberName qualifiedName, bool isInterfaceImplementation, RemoveParametersRefactoring refactoring, RubberduckParserState parseResult) : base(inspection, qualifiedName.QualifiedModuleName, context, target) { _quickFixes = isInterfaceImplementation ? new CodeInspectionQuickFix[] {} : new CodeInspectionQuickFix[] { new RemoveUnusedParameterQuickFix(Context, QualifiedSelection, refactoring, parseResult), new IgnoreOnceQuickFix(Context, QualifiedSelection, Inspection.AnnotationName), }; }
private void RemoveParameter(QualifiedSelection selection) { var progress = new ParsingProgressPresenter(); var result = progress.Parse(_parser, IDE.ActiveVBProject); using (var view = new RemoveParametersDialog()) { var factory = new RemoveParametersPresenterFactory(_editor, view, result); var refactoring = new RemoveParametersRefactoring(factory); refactoring.Refactor(selection); } }
//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 dialog = new RemoveParametersDialog(new RemoveParametersViewModel(_state))) { var refactoring = new RemoveParametersRefactoring( _vbe, new RemoveParametersPresenterFactory(_vbe, dialog, _state, _messageBox), _rewritingManager); refactoring.QuickFix(_state, result.QualifiedSelection); } }
public RefactorRemoveParametersCommand( RemoveParametersRefactoring refactoring, RemoveParameterFailedNotifier removeParameterFailedNotifier, RubberduckParserState state, ISelectionProvider selectionProvider, ISelectedDeclarationProvider selectedDeclarationProvider) : base(refactoring, removeParameterFailedNotifier, selectionProvider, state) { _state = state; _selectedDeclarationProvider = selectedDeclarationProvider; AddToCanExecuteEvaluation(SpecializedEvaluateCanExecute); }
protected override void OnExecute(object parameter) { var activeSelection = SelectionService.ActiveSelection(); if (!activeSelection.HasValue) { return; } var refactoring = new RemoveParametersRefactoring(_state, _factory, RewritingManager, SelectionService); refactoring.Refactor(activeSelection.Value); }
protected override CommandBase TestCommand(IVBE vbe, RubberduckParserState state, IRewritingManager rewritingManager, ISelectionService selectionService) { var msgBox = new Mock <IMessageBox>().Object; var factory = new Mock <IRefactoringPresenterFactory>().Object; var selectedDeclarationProvider = new SelectedDeclarationProvider(selectionService, state); var uiDispatcherMock = new Mock <IUiDispatcher>(); uiDispatcherMock .Setup(m => m.Invoke(It.IsAny <Action>())) .Callback((Action action) => action.Invoke()); var refactoring = new RemoveParametersRefactoring(state, factory, rewritingManager, selectionService, selectedDeclarationProvider, uiDispatcherMock.Object); var notifier = new RemoveParameterFailedNotifier(msgBox); return(new RefactorRemoveParametersCommand(refactoring, notifier, state, selectionService, selectedDeclarationProvider)); }
protected override void ExecuteImpl(object parameter) { if (Vbe.ActiveCodePane == null) { return; } var selection = Vbe.ActiveCodePane.GetQualifiedSelection(); using (var view = new RemoveParametersDialog()) { var factory = new RemoveParametersPresenterFactory(Vbe, view, _state, new MessageBox()); var refactoring = new RemoveParametersRefactoring(Vbe, factory); refactoring.Refactor(selection.Value); } }
public override void Execute(object parameter) { if (Vbe.ActiveCodePane == null) { return; } var selection = Vbe.ActiveCodePane.GetSelection(); using (var view = new RemoveParametersDialog()) { var factory = new RemoveParametersPresenterFactory(Editor, view, _state, new MessageBox()); var refactoring = new RemoveParametersRefactoring(factory, Editor); refactoring.Refactor(selection); } }
protected override void ExecuteImpl(object parameter) { var pane = Vbe.ActiveCodePane; if (pane.IsWrappingNullReference) { return; } var selection = pane.GetQualifiedSelection(); using (var view = new RemoveParametersDialog(new RemoveParametersViewModel(_state))) { var factory = new RemoveParametersPresenterFactory(Vbe, view, _state, _msgbox); var refactoring = new RemoveParametersRefactoring(Vbe, factory); refactoring.Refactor(selection.Value); } }
public IEnumerable <CodeInspectionResultBase> GetInspectionResults(VBProjectParseResult parseResult) { var interfaceMemberScopes = parseResult.Declarations.FindInterfaceMembers().Select(m => m.Scope).ToList(); var interfaceImplementationMemberScopes = parseResult.Declarations.FindInterfaceImplementationMembers().Select(m => m.Scope).ToList(); var parameters = parseResult.Declarations.Items.Where(parameter => !parameter.IsBuiltIn && parameter.DeclarationType == DeclarationType.Parameter && !(parameter.Context.Parent.Parent is VBAParser.EventStmtContext) && !(parameter.Context.Parent.Parent is VBAParser.DeclareStmtContext)); var unused = parameters.Where(parameter => !parameter.References.Any()).ToList(); var quickFixRefactoring = new RemoveParametersRefactoring( new RemoveParametersPresenterFactory(new ActiveCodePaneEditor(parseResult.Project.VBE), new RemoveParametersDialog(), parseResult)); var issues = from issue in unused.Where(parameter => !IsInterfaceMemberParameter(parameter, interfaceMemberScopes)) let isInterfaceImplementationMember = IsInterfaceMemberImplementationParameter(issue, interfaceImplementationMemberScopes) select new ParameterNotUsedInspectionResult(string.Format(Description, issue.IdentifierName), Severity, ((dynamic)issue.Context).ambiguousIdentifier(), issue.QualifiedName, isInterfaceImplementationMember, quickFixRefactoring, parseResult); return(issues.ToList()); }
public RemoveUnusedParameterQuickFix(RemoveParametersRefactoring refactoring) : base(refactoring, typeof(ParameterNotUsedInspection)) { }
//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 RemoveParametersRefactoring(_declarationFinderProvider, _factory, _rewritingManager, _selectionService); refactoring.QuickFix(result.QualifiedSelection); }