public override IEnumerable <InspectionResultBase> GetInspectionResults()
        {
            if (ParseTreeResults == null)
            {
                Logger.Debug("Aborting GetInspectionResults because ParseTree results were not passed");
                return(new InspectionResultBase[] { });
            }
            var subStmts = ParseTreeResults.ArgListsWithOneByRefParam
                           .Where(context => context.Context.Parent is VBAParser.SubStmtContext)
                           .Select(context => (VBAParser.SubStmtContext)context.Context.Parent)
                           .ToList();

            var subStmtsNotImplementingInterfaces = subStmts
                                                    .Where(c =>
            {
                var declaration =
                    UserDeclarations.SingleOrDefault(d => d.Context == c);

                if (UserDeclarations.FindInterfaceMembers().Contains(declaration))
                {
                    return(false);
                }

                var interfaceImplementation = UserDeclarations.FindInterfaceImplementationMembers().SingleOrDefault(m => m.Equals(declaration));
                if (interfaceImplementation == null)
                {
                    return(true);
                }

                var interfaceMember = UserDeclarations.FindInterfaceMember(interfaceImplementation);

                return(interfaceMember == null);
            });

            var subStmtsNotImplementingEvents = subStmts
                                                .Where(c =>
            {
                var declaration = UserDeclarations.SingleOrDefault(d => d.Context == c);

                if (declaration == null)
                {
                    return(false);
                }                                               // rather be safe than sorry

                return(UserDeclarations.Where(item => item.IsWithEvents)
                       .All(withEvents => UserDeclarations.FindEventProcedures(withEvents) == null) &&
                       !State.AllDeclarations.FindBuiltInEventHandlers().Contains(declaration));
            });

            return(ParseTreeResults.ArgListsWithOneByRefParam
                   .Where(context => context.Context.Parent is VBAParser.SubStmtContext &&
                          subStmtsNotImplementingInterfaces.Contains(context.Context.Parent) &&
                          subStmtsNotImplementingEvents.Contains(context.Context.Parent))
                   .Select(context => new ProcedureShouldBeFunctionInspectionResult(this,
                                                                                    State,
                                                                                    new QualifiedContext <VBAParser.ArgListContext>(context.ModuleName,
                                                                                                                                    context.Context as VBAParser.ArgListContext),
                                                                                    new QualifiedContext <VBAParser.SubStmtContext>(context.ModuleName,
                                                                                                                                    context.Context.Parent as VBAParser.SubStmtContext))));
        }
        public override IEnumerable <InspectionResultBase> GetInspectionResults()
        {
            // Note: This inspection does not find dictionary calls (e.g. foo!bar) since we do not know what the
            // default member is of a class.
            var interfaceMembers = UserDeclarations.FindInterfaceMembers().ToList();
            var interfaceImplementationMembers = UserDeclarations.FindInterfaceImplementationMembers();
            var functions             = UserDeclarations.Where(function => function.DeclarationType == DeclarationType.Function).ToList();
            var interfaceMemberIssues = GetInterfaceMemberIssues(interfaceMembers);
            var nonInterfaceFunctions = functions.Except(interfaceMembers.Union(interfaceImplementationMembers));
            var nonInterfaceIssues    = GetNonInterfaceIssues(nonInterfaceFunctions);

            return(interfaceMemberIssues.Union(nonInterfaceIssues));
        }
Esempio n. 3
0
        protected override IEnumerable <IInspectionResult> DoGetInspectionResults()
        {
            // Note: This inspection does not find dictionary calls (e.g. foo!bar) since we do not know what the
            // default member is of a class.
            var interfaceMembers = UserDeclarations.FindInterfaceMembers().ToList();
            var interfaceImplementationMembers = UserDeclarations.FindInterfaceImplementationMembers();
            var functions = State.DeclarationFinder
                            .UserDeclarations(DeclarationType.Function)
                            .Where(item => !IsIgnoringInspectionResultFor(item, AnnotationName))
                            .ToList();
            var interfaceMemberIssues = GetInterfaceMemberIssues(interfaceMembers);
            var nonInterfaceFunctions = functions.Except(interfaceMembers.Union(interfaceImplementationMembers));
            var nonInterfaceIssues    = GetNonInterfaceIssues(nonInterfaceFunctions);

            return(interfaceMemberIssues.Union(nonInterfaceIssues));
        }