AddDeclaration() public method

Adds the specified Declaration to the collection (replaces existing).
public AddDeclaration ( Rubberduck.Parsing.Symbols.Declaration declaration ) : void
declaration Rubberduck.Parsing.Symbols.Declaration
return void
        protected void ResolveDeclarations(QualifiedModuleName module, IParseTree tree, CancellationToken token)
        {
            var stopwatch = Stopwatch.StartNew();

            try
            {
                var projectDeclaration = GetOrCreateProjectDeclaration(module);

                Logger.Debug("Creating declarations for module {0}.", module.Name);

                var declarationsListener = new DeclarationSymbolsListener(_state, module, _state.GetModuleAnnotations(module), _state.GetModuleAttributes(module), projectDeclaration);
                ParseTreeWalker.Default.Walk(declarationsListener, tree);
                foreach (var createdDeclaration in declarationsListener.CreatedDeclarations)
                {
                    _state.AddDeclaration(createdDeclaration);
                }
            }
            catch (Exception exception)
            {
                Logger.Error(exception, "Exception thrown acquiring declarations for '{0}' (thread {1}).", module.Name, Thread.CurrentThread.ManagedThreadId);
                _parserStateManager.SetModuleState(module, ParserState.ResolverError, token);
            }
            stopwatch.Stop();
            Logger.Debug("{0}ms to resolve declarations for component {1}", stopwatch.ElapsedMilliseconds, module.Name);
        }
Exemplo n.º 2
0
        private void AddBuiltInDeclarations(IReadOnlyList <VBProject> projects)
        {
            var finder = new DeclarationFinder(_state.AllDeclarations, new CommentNode[] { }, new IAnnotation[] { });

            foreach (var item in finder.MatchName(Tokens.Err))
            {
                if (item.IsBuiltIn && item.DeclarationType == DeclarationType.Variable &&
                    item.Accessibility == Accessibility.Global)
                {
                    return;
                }
            }

            var vba = finder.FindProject("VBA");

            if (vba == null)
            {
                // if VBA project is null, we haven't loaded any COM references;
                // we're in a unit test and mock project didn't setup any references.
                return;
            }
            var informationModule = finder.FindStdModule("Information", vba, true);

            Debug.Assert(informationModule != null, "We expect the information module to exist in the VBA project.");
            var customDeclarations = CustomDeclarations.Load(vba, informationModule);

            lock (_state)
            {
                foreach (var customDeclaration in customDeclarations)
                {
                    _state.AddDeclaration(customDeclaration);
                }
            }
        }
        private void LoadReferenceByDeserialization(IReference localReference, ReferencedDeclarationsCollector comReflector)
        {
            Logger.Trace(string.Format("Deserializing reference '{0}'.", localReference.Name));
            var declarations = comReflector.LoadDeclarationsFromXml();

            foreach (var declaration in declarations)
            {
                _state.AddDeclaration(declaration);
            }
        }
Exemplo n.º 4
0
        private void AddNewUndeclaredVariablesToDeclarations()
        {
            var undeclared = _state.DeclarationFinder.FreshUndeclared;

            foreach (var declaration in undeclared)
            {
                _state.AddDeclaration(declaration);
            }
        }
Exemplo n.º 5
0
 public void LoadBuitInDeclarations()
 {
     LastLoadOfBuiltInDeclarationsLoadedDeclarations = false;
     foreach (var customDeclarationLoader in _customDeclarationLoaders)
     {
         try
         {
             var customDeclarations = customDeclarationLoader.Load();
             if (customDeclarations.Any())
             {
                 LastLoadOfBuiltInDeclarationsLoadedDeclarations = true;
                 foreach (var declaration in customDeclarations)
                 {
                     _state.AddDeclaration(declaration);
                 }
             }
         }
         catch (Exception exception)
         {
             Logger.Error(exception, "Exception thrown loading built-in declarations. (thread {0}).", Thread.CurrentThread.ManagedThreadId);
         }
     }
 }