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 void ExtractMethod_PrivateFunction()
        {
            const string inputCode = @"
Private Sub Foo()
    Dim x As Integer
    x = 1 + 2
End Sub";

            const string expectedCode = @"
Private Sub Foo()
    x = Bar()
End Sub

Private Function Bar() As Integer
    Dim x As Integer
    x = 1 + 2
    Bar = x
End Function

";

            var codePaneFactory = new CodePaneWrapperFactory();

            var         builder = new MockVbeBuilder();
            VBComponent component;
            var         vbe    = builder.BuildFromSingleStandardModule(inputCode, out component);
            var         module = component.CodeModule;

            var mockHost = new Mock <IHostApplication>();

            mockHost.SetupAllProperties();
            var editor = new ActiveCodePaneEditor(module.VBE, codePaneFactory);
            var parser = MockParser.Create(vbe.Object, new RubberduckParserState());

            parser.Parse();
            if (parser.State.Status == ParserState.Error)
            {
                Assert.Inconclusive("Parser Error");
            }

            var qualifiedSelection = new QualifiedSelection(new QualifiedModuleName(module.Parent), new Selection(4, 1, 4, 20));
            var model = new ExtractMethodModel(editor, parser.State.AllDeclarations, qualifiedSelection);

            model.Method.Accessibility = Accessibility.Private;
            model.Method.MethodName    = "Bar";
            model.Method.ReturnValue   = new ExtractedParameter("Integer", ExtractedParameter.PassedBy.ByVal, "x");
            model.Method.Parameters    = new List <ExtractedParameter>();

            var factory = SetupFactory(model);

            //act
            var refactoring = new ExtractMethodRefactoring(factory.Object, editor);

            refactoring.Refactor(qualifiedSelection);

            //assert
            Assert.AreEqual(expectedCode, module.Lines());
        }
Exemplo n.º 3
0
        public App(VBE vbe, AddIn addIn)
        {
            _vbe   = vbe;
            _addIn = addIn;

            _parserErrorsPresenter          = new ParserErrorsPresenter(vbe, addIn);
            _configService.SettingsChanged += _configService_SettingsChanged;

            _editor = new ActiveCodePaneEditor(vbe);

            LoadConfig();

            CleanUp();

            Setup();
        }