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).ambiguousIdentifier(), 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 void RemoveParamatersRefactoring_RemoveBothParams()
        {
            //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( )
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 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 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), 
     };
 }
        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);
            }
        }
        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 void RemoveParamatersRefactoring_ClientReferencesAreUpdated()
        {
            //Input
            const string inputCode =
@"Private Sub Foo(ByVal arg1 As Integer, ByVal arg2 As String)
End Sub

Private Sub Bar()
    Foo 10, ""Hello""
End Sub
";
            var selection = new Selection(1, 23, 1, 27); //startLine, startCol, endLine, endCol

            //Expectation
            const string expectedCode =
@"Private Sub Foo(ByVal arg1 As Integer )
End Sub

Private Sub Bar()
 Foo 10 
End Sub
"; //note: The IDE strips out the extra whitespace, you can't see it but there's a space after "Foo 10 "

            //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[1].IsRemoved = true;

            //SetupFactory
            var factory = SetupFactory(model);

            //Act
            var refactoring = new RemoveParametersRefactoring(factory.Object);
            refactoring.Refactor(qualifiedSelection);

            //Assert
            Assert.AreEqual(expectedCode, _module.Object.Lines());
        }
Exemplo n.º 9
0
        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);
            }
        }