Beispiel #1
0
        protected bool IsIgnoringInspectionResultFor(QualifiedModuleName module, int line)
        {
            var annotations = State.GetModuleAnnotations(module).ToList();

            if (State.GetModuleAnnotations(module) == null)
            {
                return(false);
            }

            // VBE 1-based indexing
            for (var i = line; i >= 1; i--)
            {
                var annotation             = annotations.SingleOrDefault(a => a.QualifiedSelection.Selection.StartLine == i);
                var ignoreAnnotation       = annotation as IgnoreAnnotation;
                var ignoreModuleAnnotation = annotation as IgnoreModuleAnnotation;

                if (ignoreAnnotation?.InspectionNames.Contains(AnnotationName) == true)
                {
                    return(true);
                }

                if (ignoreModuleAnnotation != null &&
                    (ignoreModuleAnnotation.InspectionNames.Contains(AnnotationName) ||
                     !ignoreModuleAnnotation.InspectionNames.Any()))
                {
                    return(true);
                }
            }

            return(false);
        }
Beispiel #2
0
        protected bool IsInspectionDisabled(VBComponent component, int line)
        {
            var annotations = State.GetModuleAnnotations(component).ToList();

            if (State.GetModuleAnnotations(component) == null)
            {
                return(false);
            }

            // VBE 1-based indexing
            for (var i = line - 1; i >= 1; i--)
            {
                var annotation = annotations.SingleOrDefault(a => a.QualifiedSelection.Selection.StartLine == i) as IgnoreAnnotation;
                if (annotation != null && annotation.InspectionNames.Contains(AnnotationName))
                {
                    return(true);
                }
            }

            return(false);
        }
Beispiel #3
0
        protected void ResolveDeclarations(QualifiedModuleName module, IParseTree tree, IDictionary <string, ProjectDeclaration> projects, CancellationToken token)
        {
            var stopwatch = Stopwatch.StartNew();

            try
            {
                if (!projects.TryGetValue(module.ProjectId, out var projectDeclaration))
                {
                    Logger.Error($"Tried to add module {module} with projectId {module.ProjectId} for which no project declaration exists.");
                }
                Logger.Debug($"Creating declarations for module {module.Name}.");

                var annotations = _state.GetModuleAnnotations(module).ToList();
                var attributes  = _state.GetModuleAttributes(module);
                var membersAllowingAttributes = _state.GetMembersAllowingAttributes(module);

                var moduleDeclaration = NewModuleDeclaration(module, tree, annotations, attributes, projectDeclaration);
                _state.AddDeclaration(moduleDeclaration);

                var controlDeclarations = DeclarationsFromControls(moduleDeclaration);
                foreach (var declaration in controlDeclarations)
                {
                    _state.AddDeclaration(declaration);
                }

                var declarationsListener = new DeclarationSymbolsListener(moduleDeclaration, annotations, attributes, membersAllowingAttributes);
                ParseTreeWalker.Default.Walk(declarationsListener, tree);
                foreach (var createdDeclaration in declarationsListener.CreatedDeclarations)
                {
                    _state.AddDeclaration(createdDeclaration);
                }

                //This is a hack to deal with annotations on module level variables.
                var memberAnnotations = declarationsListener.CreatedDeclarations
                                        .SelectMany(declaration => declaration.Annotations)
                                        .ToHashSet();
                moduleDeclaration.RemoveAnnotations(memberAnnotations);
            }
            catch (Exception exception)
            {
                Logger.Error(exception, $"Exception thrown acquiring declarations for '{module.Name}' (thread {Thread.CurrentThread.ManagedThreadId}).");
                _parserStateManager.SetModuleState(module, ParserState.ResolverError, token);
            }
            stopwatch.Stop();
            Logger.Debug($"{stopwatch.ElapsedMilliseconds}ms to resolve declarations for component {module.Name}");
        }
Beispiel #4
0
        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), _state.GetMembersAllowingAttributes(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);
        }