private Declaration FindSelectedDeclaration(out VBProjectParseResult results)
        {
            var project = _vbe.ActiveVBProject;

            if (project == null)
            {
                results = null;
                return(null);
            }

            var progress = new ParsingProgressPresenter();

            results = progress.Parse(_parser, _vbe.ActiveVBProject);

            var selection = _vbe.SelectedVBComponent;

            if (selection != null)
            {
                var componentName = selection.Name;
                var matches       = results.Declarations[componentName].ToList();
                if (matches.Count == 1)
                {
                    return(matches.Single());
                }

                var result = matches.SingleOrDefault(item =>
                                                     (item.DeclarationType == DeclarationType.Class || item.DeclarationType == DeclarationType.Module) &&
                                                     item.Project == project);

                return(result);
            }

            return(results.Declarations[project.Name].SingleOrDefault(item =>
                                                                      item.DeclarationType == DeclarationType.Project && item.Project == project));
        }
        private Declaration FindSelectedDeclaration(out VBProjectParseResult results)
        {
            var project = _vbe.ActiveVBProject;
            if (project == null)
            {
                results = null;
                return null;
            }

            var progress = new ParsingProgressPresenter();
            results = progress.Parse(_parser, _vbe.ActiveVBProject);

            var selection = _vbe.SelectedVBComponent;
            if (selection != null)
            {
                var componentName = selection.Name;
                var matches = results.Declarations[componentName].ToList();
                if (matches.Count == 1)
                {
                    return matches.Single();
                }

                var result = matches.SingleOrDefault(item =>
                    (item.DeclarationType == DeclarationType.Class || item.DeclarationType == DeclarationType.Module)
                    && item.Project == project);

                return result;
            }

            return results.Declarations[project.Name].SingleOrDefault(item =>
                item.DeclarationType == DeclarationType.Project && item.Project == project);
        }
Пример #3
0
        public void FindAllImplementations(Declaration target)
        {
            var progress    = new ParsingProgressPresenter();
            var parseResult = progress.Parse(_parser, IDE.ActiveVBProject);

            FindAllImplementations(target, parseResult);
        }
Пример #4
0
        public void FindAllImplementations()
        {
            var selection   = IDE.ActiveCodePane.GetSelection();
            var progress    = new ParsingProgressPresenter();
            var parseResult = progress.Parse(_parser, IDE.ActiveVBProject);

            var implementsStatement = parseResult.Declarations.FindInterfaces()
                                      .SelectMany(i => i.References.Where(reference => reference.Context.Parent is VBAParser.ImplementsStmtContext))
                                      .SingleOrDefault(r => r.QualifiedModuleName == selection.QualifiedName && r.Selection.Contains(selection.Selection));

            if (implementsStatement != null)
            {
                FindAllImplementations(implementsStatement.Declaration, parseResult);
            }

            var member = parseResult.Declarations.FindInterfaceImplementationMembers()
                         .SingleOrDefault(m => m.Project == selection.QualifiedName.Project &&
                                          m.ComponentName == selection.QualifiedName.ComponentName &&
                                          m.Selection.Contains(selection.Selection)) ??
                         parseResult.Declarations.FindInterfaceMembers()
                         .SingleOrDefault(m => m.Project == selection.QualifiedName.Project &&
                                          m.ComponentName == selection.QualifiedName.ComponentName &&
                                          m.Selection.Contains(selection.Selection));

            if (member == null)
            {
                return;
            }

            FindAllImplementations(member, parseResult);
        }
Пример #5
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);
                }
            }
        }
Пример #6
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);
                }
            }
        }
Пример #7
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);
            }
        }
Пример #8
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);
            }
        }
Пример #9
0
        private void ExtractMethod()
        {
            var progress = new ParsingProgressPresenter();
            var result   = progress.Parse(_parser, IDE.ActiveVBProject);

            var declarations = result.Declarations;
            var factory      = new ExtractMethodPresenterFactory(_editor, declarations);
            var refactoring  = new ExtractMethodRefactoring(factory, _editor);

            refactoring.InvalidSelection += refactoring_InvalidSelection;
            refactoring.Refactor();
        }
Пример #10
0
        private void FindSymbol()
        {
            var progress     = new ParsingProgressPresenter();
            var result       = progress.Parse(_parser, IDE.ActiveVBProject);
            var declarations = result.Declarations;
            var vm           = new FindSymbolViewModel(declarations.Items.Where(item => !item.IsBuiltIn), _iconCache);

            using (var view = new FindSymbolDialog(vm))
            {
                view.Navigate += view_Navigate;
                view.ShowDialog();
            }
        }
Пример #11
0
        public void FindAllReferences()
        {
            var selection = IDE.ActiveCodePane.GetSelection();
            var progress  = new ParsingProgressPresenter();
            var result    = progress.Parse(_parser, IDE.ActiveVBProject);

            if (result == null)
            {
                return; // bug/todo: something's definitely wrong, exception thrown in resolver code
            }

            var declarations = result.Declarations.Items
                               .Where(item => item.DeclarationType != DeclarationType.ModuleOption)
                               .ToList();

            var target = declarations.SingleOrDefault(item =>
                                                      item.IsSelectedDeclaration(selection) ||
                                                      item.References.Any(r => r.IsSelectedReference(selection)));

            if (target != null)
            {
                FindAllReferences(target);
            }
        }
Пример #12
0
        public void FindAllImplementations()
        {
            var selection = IDE.ActiveCodePane.GetSelection();
            var progress = new ParsingProgressPresenter();
            var parseResult = progress.Parse(_parser, IDE.ActiveVBProject);

            var implementsStatement = parseResult.Declarations.FindInterfaces()
                .SelectMany(i => i.References.Where(reference => reference.Context.Parent is VBAParser.ImplementsStmtContext))
                .SingleOrDefault(r => r.QualifiedModuleName == selection.QualifiedName && r.Selection.Contains(selection.Selection));

            if (implementsStatement != null)
            {
                FindAllImplementations(implementsStatement.Declaration, parseResult);
            }

            var member = parseResult.Declarations.FindInterfaceImplementationMembers()
                .SingleOrDefault(m => m.Project == selection.QualifiedName.Project
                                      && m.ComponentName == selection.QualifiedName.ComponentName
                                      && m.Selection.Contains(selection.Selection)) ??
                         parseResult.Declarations.FindInterfaceMembers()
                                          .SingleOrDefault(m => m.Project == selection.QualifiedName.Project
                                                                && m.ComponentName == selection.QualifiedName.ComponentName
                                                                && m.Selection.Contains(selection.Selection));

            if (member == null)
            {
                return;
            }

            FindAllImplementations(member, parseResult);
        }
Пример #13
0
 private void FindSymbol()
 {
     var progress = new ParsingProgressPresenter();
     var result = progress.Parse(_parser, IDE.ActiveVBProject);
     var declarations = result.Declarations;
     var vm = new FindSymbolViewModel(declarations.Items.Where(item => !item.IsBuiltIn), _iconCache);
     using (var view = new FindSymbolDialog(vm))
     {
         view.Navigate += view_Navigate;
         view.ShowDialog();
     }
 }
Пример #14
0
        public void FindAllReferences()
        {
            var selection = IDE.ActiveCodePane.GetSelection();
            var progress = new ParsingProgressPresenter();
            var result = progress.Parse(_parser, IDE.ActiveVBProject);
            if (result == null)
            {
                return; // bug/todo: something's definitely wrong, exception thrown in resolver code
            }

            var declarations = result.Declarations.Items
                                     .Where(item => item.DeclarationType != DeclarationType.ModuleOption)
                                     .ToList();

            var target = declarations.SingleOrDefault(item =>
                item.IsSelectedDeclaration(selection)
                || item.References.Any(r => r.IsSelectedReference(selection)));

            if (target != null)
            {
                FindAllReferences(target);
            }
        }
Пример #15
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);
            }
        }
Пример #16
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);
            }
        }
Пример #17
0
        private void ExtractMethod()
        {
            var progress = new ParsingProgressPresenter();
            var result = progress.Parse(_parser, IDE.ActiveVBProject);

            var declarations = result.Declarations;
            var factory = new ExtractMethodPresenterFactory(_editor, declarations);
            var refactoring = new ExtractMethodRefactoring(factory, _editor);
            refactoring.InvalidSelection += refactoring_InvalidSelection;
            refactoring.Refactor();
        }
Пример #18
0
 public void FindAllImplementations(Declaration target)
 {
     var progress = new ParsingProgressPresenter();
     var parseResult = progress.Parse(_parser, IDE.ActiveVBProject);
     FindAllImplementations(target, parseResult);
 }