示例#1
0
        private static void FixMemberDescriptionAnnotation(RubberduckParserState state, QualifiedMemberName memberName)
        {
            var moduleName = memberName.QualifiedModuleName;
            var rewriter   = state.GetRewriter(moduleName);

            var attributes = state
                             .GetModuleAttributes(moduleName)
                             .Where(a => a.Key.Item1.StartsWith(memberName.MemberName) &&
                                    a.Key.Item2.HasFlag(DeclarationType.Member))
                             .ToArray();

            Debug.Assert(attributes.Length == 1, "Member has too many attributes");
            var attribute = attributes.SingleOrDefault();

            if (!attribute.Value.HasMemberDescriptionAttribute(memberName.MemberName, out var node))
            {
                return;
            }

            var value  = node.Context.attributeValue().SingleOrDefault()?.GetText() ?? "\"\"";
            var member = state.DeclarationFinder.Members(memberName.QualifiedModuleName)
                         .First(m => m.IdentifierName == memberName.MemberName);

            var insertAt = member.Context.Start;

            rewriter.InsertBefore(insertAt.TokenIndex, $"'@Description({value})\r\n");
        }
示例#2
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}");
        }
示例#3
0
        private static void FixExposedAttribute(RubberduckParserState state, QualifiedModuleName moduleName)
        {
            var attributes = state.GetModuleAttributes(moduleName);
            var rewriter   = state.GetAttributeRewriter(moduleName);

            foreach (var attribute in attributes.Values)
            {
                var exposedAttribute = attribute.ExposedAttribute;
                if (exposedAttribute == null)
                {
                    continue;
                }

                var valueToken = exposedAttribute.Context.attributeValue().Single().Start;
                Debug.Assert(valueToken.Text == "False");

                rewriter.Replace(valueToken, "True");
            }
        }
示例#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);
        }