Esempio n. 1
0
        public VBETypeLibsAccessor(IVBE ide)
        {
            // We need at least one project in the VBE.VBProjects collection to be accessible (i.e. unprotected)
            // in order to get access to the list of loaded project TypeLibs using this method

            foreach (var project in ide.VBProjects)
            {
                using (project)
                {
                    try
                    {
                        using (var references = project.References)
                        {
                            // Now we've got the references object, we can read the internal object structure to grab the ITypeLib
                            var internalReferencesObj = StructHelper.ReadComObjectStructure <VBEReferencesObj>(references.Target);

                            // Now we've got this one internalReferencesObj.typeLib, we can iterate through ALL loaded project TypeLibs
                            using (var typeLibIterator = new VBETypeLibsIterator(internalReferencesObj.TypeLib))
                            {
                                foreach (var typeLib in typeLibIterator)
                                {
                                    Add(typeLib);
                                }
                            }
                        }

                        // we only need access to a single VBProject References object to make it work, so we can return now.
                        return;
                    }
                    catch (Exception)
                    {
                        // probably a protected project, just move on to the next project.
                    }
                }
            }

            // return an empty list on error
        }
Esempio n. 2
0
        public RenameRefactoring(IVBE vbe, IRefactoringPresenterFactory <IRenamePresenter> factory, IMessageBox messageBox, RubberduckParserState state)
        {
            _vbe        = vbe;
            _factory    = factory;
            _messageBox = messageBox;
            _state      = state;
            _model      = null;
            var activeCodePane = _vbe.ActiveCodePane;

            _initialSelection = new Tuple <ICodePane, Selection>(activeCodePane, activeCodePane.IsWrappingNullReference ? Selection.Empty : activeCodePane.Selection);
            _modulesToRewrite = new List <QualifiedModuleName>();
            _renameActions    = new Dictionary <DeclarationType, Action>
            {
                { DeclarationType.Member, RenameMember },
                { DeclarationType.Parameter, RenameParameter },
                { DeclarationType.Event, RenameEvent },
                { DeclarationType.Variable, RenameVariable },
                { DeclarationType.Module, RenameModule },
                { DeclarationType.Project, RenameProject }
            };
            IsInterfaceMemberRename = false;
            RequestParseAfterRename = true;
            _neverRenameIdentifiers = NeverRenameList();
        }
Esempio n. 3
0
        private static TApplication ApplicationFromVbe(IVBE vbe, string applicationName)
        {
            TApplication application;

            try
            {
                using (var appProperty = ApplicationPropertyFromDocumentModule(vbe))
                {
                    if (appProperty != null)
                    {
                        application = (TApplication)appProperty.Object;
                    }
                    else
                    {
                        application = ApplicationFromComReflection(applicationName);
                    }
                }
            }
            catch (COMException exception)
            {
                _logger.Error(exception, $"Unexpected COM exception while acquiring the host application object for application {applicationName} from a document module.");
                application = null;
            }
            catch (InvalidCastException exception)
            {
                _logger.Error(exception, $"Unable to cast the host application object for application {applicationName} acquiered from a document module to its PIA type.");
                application = null;
            }
            catch (Exception exception)
            {
                //note: We catch all exceptions because we currently really do not need application object and there can be exceptions for unexpected system setups.
                _logger.Error(exception, $"Unexpected exception while acquiring the host application object for application {applicationName} from a document module.");
                application = null;
            }
            return(application);
        }
 public RefactorIntroduceParameterCommand(IVBE vbe, RubberduckParserState state, IMessageBox messageBox)
     : base(vbe)
 {
     _state      = state;
     _messageBox = messageBox;
 }
Esempio n. 5
0
 protected abstract CommandBase TestCommand(IVBE vbe, RubberduckParserState state, IRewritingManager rewritingManager, ISelectionService selectionService);
 public SyncCodeExplorerCommand(IVBE vbe, RubberduckParserState state, CodeExplorerViewModel explorer) : base(LogManager.GetCurrentClassLogger())
 {
     _vbe      = vbe;
     _state    = state;
     _explorer = explorer;
 }
Esempio n. 7
0
        public static (SynchronousParseCoordinator parser, IRewritingManager rewritingManager) CreateWithRewriteManager(IVBE vbe, RubberduckParserState state, IProjectsRepository projectRepository, string serializedComProjectsPath = null)
        {
            var vbeVersion = double.Parse(vbe.Version, CultureInfo.InvariantCulture);
            var compilationArgumentsProvider = MockCompilationArgumentsProvider(vbeVersion);
            var compilationsArgumentsCache   = new CompilationArgumentsCache(compilationArgumentsProvider);

            var path = serializedComProjectsPath ??
                       Path.Combine(Path.GetDirectoryName(Assembly.GetAssembly(typeof(MockParser)).Location), "Testfiles", "Resolver");
            var preprocessorErrorListenerFactory = new PreprocessingParseErrorListenerFactory();
            var preprocessorParser              = new VBAPreprocessorParser(preprocessorErrorListenerFactory, preprocessorErrorListenerFactory);
            var preprocessor                    = new VBAPreprocessor(preprocessorParser, compilationsArgumentsCache);
            var mainParseErrorListenerFactory   = new MainParseErrorListenerFactory();
            var mainTokenStreamParser           = new VBATokenStreamParser(mainParseErrorListenerFactory, mainParseErrorListenerFactory);
            var tokenStreamProvider             = new SimpleVBAModuleTokenStreamProvider();
            var stringParser                    = new TokenStreamParserStringParserAdapterWithPreprocessing(tokenStreamProvider, mainTokenStreamParser, preprocessor);
            var projectManager                  = new RepositoryProjectManager(projectRepository);
            var moduleToModuleReferenceManager  = new ModuleToModuleReferenceManager();
            var supertypeClearer                = new SynchronousSupertypeClearer(state);
            var parserStateManager              = new SynchronousParserStateManager(state);
            var referenceRemover                = new SynchronousReferenceRemover(state, moduleToModuleReferenceManager);
            var baseComDeserializer             = new XmlComProjectSerializer(path);
            var comDeserializer                 = new StaticCachingComDeserializerDecorator(baseComDeserializer);
            var referencedDeclarationsCollector = new SerializedReferencedDeclarationsCollector(comDeserializer);
            var comSynchronizer                 = new SynchronousCOMReferenceSynchronizer(
                state,
                parserStateManager,
                projectRepository,
                referencedDeclarationsCollector);
            var builtInDeclarationLoader = new BuiltInDeclarationLoader(
                state,
                new List <ICustomDeclarationLoader>
            {
                new DebugDeclarations(state),
                new SpecialFormDeclarations(state),
                new FormEventDeclarations(state),
                new AliasDeclarations(state),
            });
            var codePaneSourceCodeHandler = new CodePaneSourceCodeHandler(projectRepository);
            //We use the same handler because to achieve consistency between the return values.
            var attributesSourceCodeHandler = codePaneSourceCodeHandler;
            var moduleParser = new ModuleParser(
                codePaneSourceCodeHandler,
                attributesSourceCodeHandler,
                stringParser);
            var parseRunner = new SynchronousParseRunner(
                state,
                parserStateManager,
                moduleParser);
            var declarationResolveRunner = new SynchronousDeclarationResolveRunner(
                state,
                parserStateManager,
                comSynchronizer);
            var referenceResolveRunner = new SynchronousReferenceResolveRunner(
                state,
                parserStateManager,
                moduleToModuleReferenceManager,
                referenceRemover);
            var parsingStageService = new ParsingStageService(
                comSynchronizer,
                builtInDeclarationLoader,
                parseRunner,
                declarationResolveRunner,
                referenceResolveRunner
                );
            var parsingCacheService = new ParsingCacheService(
                state,
                moduleToModuleReferenceManager,
                referenceRemover,
                supertypeClearer,
                compilationsArgumentsCache
                );
            var tokenStreamCache      = new StateTokenStreamCache(state);
            var moduleRewriterFactory = new ModuleRewriterFactory(
                codePaneSourceCodeHandler,
                attributesSourceCodeHandler);
            var rewriterProvider      = new RewriterProvider(tokenStreamCache, moduleRewriterFactory);
            var rewriteSessionFactory = new RewriteSessionFactory(state, rewriterProvider);
            var rewritingManager      = new RewritingManager(rewriteSessionFactory);

            var parser = new SynchronousParseCoordinator(
                state,
                parsingStageService,
                parsingCacheService,
                projectManager,
                parserStateManager,
                rewritingManager);

            return(parser, rewritingManager);
        }
Esempio n. 8
0
        public static (SynchronousParseCoordinator parser, IRewritingManager rewritingManager) CreateWithRewriteManager(IVBE vbe, string serializedComProjectsPath = null, Mock <IVBEEvents> vbeEvents = null)
        {
            var declarationFinderFactory = new DeclarationFinderFactory();
            var projectRepository        = new ProjectsRepository(vbe);
            var state = new RubberduckParserState(vbe, projectRepository, declarationFinderFactory, vbeEvents?.Object ?? MockVbeEvents.CreateMockVbeEvents(new Mock <IVBE>()).Object);

            return(CreateWithRewriteManager(vbe, state, projectRepository, serializedComProjectsPath));
        }
Esempio n. 9
0
        public static (RubberduckParserState state, IRewritingManager rewritingManager) CreateAndParseWithRewritingManager(IVBE vbe, string serializedComProjectsPath = null)
        {
            var(parser, rewritingManager) = CreateWithRewriteManager(vbe, serializedComProjectsPath);
            parser.Parse(new CancellationTokenSource());
            if (parser.State.Status >= ParserState.Error)
            {
                Assert.Inconclusive("Parser Error");
            }

            return(parser.State, rewritingManager);
        }
Esempio n. 10
0
 public CodeExplorerAddComponentService(IParseManager parseManager, IAddComponentService addComponentService, IVBE vbe)
 {
     _parseManager        = parseManager;
     _addComponentService = addComponentService;
     _vbe = vbe;
 }
Esempio n. 11
0
 public AddTestComponentCommand(IVBE vbe, RubberduckParserState state, IGeneralConfigService configLoader, IMessageBox messageBox, IVBEInteraction interaction)
     : base(vbe, state, configLoader, messageBox, interaction)
 {
 }
Esempio n. 12
0
 public RefactorImplementInterfaceCommand(IVBE vbe, RubberduckParserState state, IMessageBox msgBox)
     : base(vbe)
 {
     _state  = state;
     _msgBox = msgBox;
 }
Esempio n. 13
0
 public RubberduckIoCInstaller(IVBE vbe, IAddIn addin, GeneralSettings initialSettings)
 {
     _vbe             = vbe;
     _addin           = addin;
     _initialSettings = initialSettings;
 }
Esempio n. 14
0
 public ExtractInterfaceRefactoring(IVBE vbe, IMessageBox messageBox, IRefactoringPresenterFactory <IExtractInterfacePresenter> factory)
 {
     _vbe        = vbe;
     _messageBox = messageBox;
     _factory    = factory;
 }
Esempio n. 15
0
 public CommandBars(MSO.CommandBars target, IVBE vbe, bool rewrapping = false)
     : base(target, rewrapping)
 {
     _vbe = vbe;
 }
Esempio n. 16
0
 public TestMethod(Declaration declaration, IVBE vbe)
 {
     _declaration = declaration;
     _hostApp     = vbe.HostApplication();
 }
Esempio n. 17
0
 public static SynchronousParseCoordinator Create(IVBE vbe, RubberduckParserState state, IProjectsRepository projectRepository, string serializedComProjectsPath = null)
 {
     return(CreateWithRewriteManager(vbe, state, projectRepository, serializedComProjectsPath).parser);
 }
Esempio n. 18
0
 public ProjectApp(IVBE vbe) : base(vbe, "MSProject", true)
 {
 }
Esempio n. 19
0
 public static RubberduckParserState CreateAndParse(IVBE vbe, string serializedComProjectsPath = null)
 {
     return(CreateAndParseWithRewritingManager(vbe, serializedComProjectsPath).state);
 }
Esempio n. 20
0
        public static (RubberduckParserState state, IRewritingManager rewritingManager) CreateAndParseWithRewritingManager(IVBE vbe, string serializedComProjectsPath = null, IDictionary <string, IEnumerable <string> > documentModuleSupertypeNames = null)
        {
            var(parser, rewritingManager) = CreateWithRewriteManager(vbe, serializedComProjectsPath, documentModuleSupertypeNames: documentModuleSupertypeNames);
            parser.Parse(new CancellationTokenSource());
            if (parser.State.Status >= ParserState.Error)
            {
                Assert.Inconclusive("Parser Error");
            }

            return(parser.State, rewritingManager);
        }
Esempio n. 21
0
 public static SynchronousParseCoordinator Create(IVBE vbe, string serializedDeclarationsPath = null, Mock <IVBEEvents> vbeEvents = null)
 {
     return(CreateWithRewriteManager(vbe, serializedDeclarationsPath, vbeEvents).parser);
 }
Esempio n. 22
0
 public static RubberduckParserState CreateAndParse(IVBE vbe, string serializedComProjectsPath = null, IDictionary <string, IEnumerable <string> > documentModuleSupertypeNames = null) =>
 CreateAndParseWithRewritingManager(vbe, serializedComProjectsPath, documentModuleSupertypeNames: documentModuleSupertypeNames).state;
 public CodeExplorerSyncProvider(IVBE vbe, RubberduckParserState state)
 {
     _vbe   = vbe;
     _state = state;
 }
Esempio n. 24
0
 public static SynchronousParseCoordinator Create(IVBE vbe, string serializedDeclarationsPath = null, Mock <IVbeEvents> vbeEvents = null, IDictionary <string, IEnumerable <string> > documentModuleSupertypeNames = null)
 {
     return(CreateWithRewriteManager(vbe, serializedDeclarationsPath, vbeEvents, documentModuleSupertypeNames).parser);
 }
Esempio n. 25
0
        private void ShutdownAddIn()
        {
            var currentDomain = AppDomain.CurrentDomain;

            try
            {
                _logger.Log(LogLevel.Info, "Rubberduck is shutting down.");
                _logger.Log(LogLevel.Trace, "Unhooking VBENativeServices events...");
                VbeNativeServices.UnhookEvents();
                VbeProvider.Terminate();

                _logger.Log(LogLevel.Trace, "Releasing dockable hosts...");

                using (var windows = _vbe.Windows)
                {
                    windows.ReleaseDockableHosts();
                }

                if (_app != null)
                {
                    _logger.Log(LogLevel.Trace, "Initiating App.Shutdown...");
                    _app.Shutdown();
                    _app = null;
                }

                if (_container != null)
                {
                    _logger.Log(LogLevel.Trace, "Disposing IoC container...");
                    _container.Dispose();
                    _container = null;
                }
            }
            catch (Exception e)
            {
                _logger.Error(e);
                _logger.Log(LogLevel.Warn, "Exception is swallowed.");
                //throw; // <<~ uncomment to crash the process
            }
            finally
            {
                try
                {
                    _logger.Log(LogLevel.Trace, "Disposing COM safe...");
                    ComSafeManager.DisposeAndResetComSafe();
                    _addin = null;
                    _vbe   = null;

                    _isInitialized = false;
                    _logger.Log(LogLevel.Info, "No exceptions were thrown.");
                }
                catch (Exception e)
                {
                    _logger.Error(e);
                    _logger.Log(LogLevel.Warn, "Exception disposing the ComSafe has been swallowed.");
                    //throw; // <<~ uncomment to crash the process
                }
                finally
                {
                    _logger.Log(LogLevel.Trace, "Unregistering AppDomain handlers....");
                    currentDomain.AssemblyResolve    -= LoadFromSameFolder;
                    currentDomain.UnhandledException -= HandlAppDomainException;
                    _logger.Log(LogLevel.Trace, "Done. Main Shutdown completed. Toolwindows follow. Quack!");
                    _isInitialized = false;
                }
            }
        }
Esempio n. 26
0
        public static (SynchronousParseCoordinator parser, IRewritingManager rewritingManager) CreateWithRewriteManager(IVBE vbe, RubberduckParserState state, IProjectsRepository projectRepository, string serializedComProjectsPath = null, IDictionary <string, IEnumerable <string> > documentModuleSupertypeNames = null)
        {
            var vbeVersion = double.Parse(vbe.Version, CultureInfo.InvariantCulture);
            var compilationArgumentsProvider      = MockCompilationArgumentsProvider(vbeVersion);
            var compilationsArgumentsCache        = new CompilationArgumentsCache(compilationArgumentsProvider);
            var userComProjectsRepository         = MockUserComProjectRepository();
            var documentSuperTypesProvider        = MockDocumentSuperTypeNamesProvider(documentModuleSupertypeNames);
            var ignoredProjectsSettingsProvider   = MockIgnoredProjectsSettingsProviderMock();
            var projectsToBeLoadedFromComSelector = new ProjectsToResolveFromComProjectsSelector(projectRepository, ignoredProjectsSettingsProvider);

            var path = serializedComProjectsPath ??
                       Path.Combine(Path.GetDirectoryName(Assembly.GetAssembly(typeof(MockParser)).Location), "Testfiles", "Resolver");
            var preprocessorErrorListenerFactory = new PreprocessingParseErrorListenerFactory();
            var preprocessorParser               = new VBAPreprocessorParser(preprocessorErrorListenerFactory, preprocessorErrorListenerFactory);
            var preprocessor                     = new VBAPreprocessor(preprocessorParser, compilationsArgumentsCache);
            var mainParseErrorListenerFactory    = new MainParseErrorListenerFactory();
            var mainTokenStreamParser            = new VBATokenStreamParser(mainParseErrorListenerFactory, mainParseErrorListenerFactory);
            var tokenStreamProvider              = new SimpleVBAModuleTokenStreamProvider();
            var stringParser                     = new TokenStreamParserStringParserAdapterWithPreprocessing(tokenStreamProvider, mainTokenStreamParser, preprocessor);
            var vbaParserAnnotationFactory       = new VBAParserAnnotationFactory(WellKnownAnnotations());
            var projectManager                   = new RepositoryProjectManager(projectRepository);
            var moduleToModuleReferenceManager   = new ModuleToModuleReferenceManager();
            var supertypeClearer                 = new SynchronousSupertypeClearer(state);
            var parserStateManager               = new SynchronousParserStateManager(state);
            var referenceRemover                 = new SynchronousReferenceRemover(state, moduleToModuleReferenceManager);
            var baseComDeserializer              = new XmlComProjectSerializer(new MockFileSystem(), path);
            var comDeserializer                  = new StaticCachingComDeserializerDecorator(baseComDeserializer);
            var declarationsFromComProjectLoader = new DeclarationsFromComProjectLoader();
            var referencedDeclarationsCollector  = new SerializedReferencedDeclarationsCollector(declarationsFromComProjectLoader, comDeserializer);
            var userComProjectSynchronizer       = new UserComProjectSynchronizer(state, declarationsFromComProjectLoader, userComProjectsRepository, projectsToBeLoadedFromComSelector);
            var comSynchronizer                  = new SynchronousCOMReferenceSynchronizer(
                state,
                parserStateManager,
                projectRepository,
                referencedDeclarationsCollector);
            var builtInDeclarationLoader = new BuiltInDeclarationLoader(
                state,
                new List <ICustomDeclarationLoader>
            {
                new DebugDeclarations(state),
                new SpecialFormDeclarations(state),
                new FormEventDeclarations(state),
                new AliasDeclarations(state),
            });
            var codePaneComponentSourceCodeHandler = new CodeModuleComponentSourceCodeHandler();
            var codePaneSourceCodeHandler          = new ComponentSourceCodeHandlerSourceCodeHandlerAdapter(codePaneComponentSourceCodeHandler, projectRepository);
            //We use the same handler because to achieve consistency between the return values.
            var attributesSourceCodeHandler = codePaneSourceCodeHandler;
            var moduleParser = new ModuleParser(
                codePaneSourceCodeHandler,
                attributesSourceCodeHandler,
                stringParser,
                vbaParserAnnotationFactory);
            var parseRunner = new SynchronousParseRunner(
                state,
                parserStateManager,
                moduleParser);
            var declarationResolveRunner = new SynchronousDeclarationResolveRunner(
                state,
                parserStateManager,
                comSynchronizer);
            var referenceResolveRunner = new SynchronousReferenceResolveRunner(
                state,
                parserStateManager,
                moduleToModuleReferenceManager,
                referenceRemover,
                documentSuperTypesProvider);
            var parsingStageService = new ParsingStageService(
                comSynchronizer,
                builtInDeclarationLoader,
                parseRunner,
                declarationResolveRunner,
                referenceResolveRunner,
                userComProjectSynchronizer
                );
            var parsingCacheService = new ParsingCacheService(
                state,
                moduleToModuleReferenceManager,
                referenceRemover,
                supertypeClearer,
                compilationsArgumentsCache,
                userComProjectsRepository,
                projectsToBeLoadedFromComSelector
                );
            var tokenStreamCache      = new StateTokenStreamCache(state);
            var moduleRewriterFactory = new ModuleRewriterFactory(
                codePaneSourceCodeHandler,
                attributesSourceCodeHandler);
            var rewriterProvider              = new RewriterProvider(tokenStreamCache, moduleRewriterFactory);
            var selectionService              = new SelectionService(vbe, projectRepository);
            var selectionRecoverer            = new SelectionRecoverer(selectionService, state);
            var rewriteSessionFactory         = new RewriteSessionFactory(state, rewriterProvider, selectionRecoverer);
            var stubMembersAttributeRecoverer = new Mock <IMemberAttributeRecovererWithSettableRewritingManager>().Object;
            var rewritingManager              = new RewritingManager(rewriteSessionFactory, stubMembersAttributeRecoverer);

            var parser = new SynchronousParseCoordinator(
                state,
                parsingStageService,
                parsingCacheService,
                projectManager,
                parserStateManager,
                rewritingManager);

            return(parser, rewritingManager);
        }
 public EncapsulateFieldRefactoring(IVBE vbe, IIndenter indenter, IRefactoringPresenterFactory <IEncapsulateFieldPresenter> factory)
 {
     _vbe      = vbe;
     _indenter = indenter;
     _factory  = factory;
 }
 public IndentCurrentModuleCommand(IVBE vbe, IIndenter indenter, RubberduckParserState state) : base(LogManager.GetCurrentClassLogger())
 {
     _vbe      = vbe;
     _indenter = indenter;
     _state    = state;
 }
Esempio n. 29
0
 internal static void Initialize(IVBE vbe, IVbeNativeApi vbeNativeApi, IBeepInterceptor beepInterceptor)
 {
     Vbe             = vbe;
     VbeNativeApi    = vbeNativeApi;
     BeepInterceptor = beepInterceptor;
 }
Esempio n. 30
0
 public Indenter(IVBE vbe, Func <IIndenterSettings> settings)
 {
     _vbe      = vbe;
     _settings = settings;
 }