protected override IEnumerable <IInspectionResult> DoGetInspectionResults()
        {
            var settings         = _settings.Load(new CodeInspectionSettings()) ?? new CodeInspectionSettings();
            var whitelistedNames = settings.WhitelistedIdentifiers.Select(s => s.Identifier).ToArray();

            var handlers = State.DeclarationFinder.FindEventHandlers();

            var issues = UserDeclarations
                         .Where(declaration => !string.IsNullOrEmpty(declaration.IdentifierName) &&
                                !IgnoreDeclarationTypes.Contains(declaration.DeclarationType) &&
                                !(declaration.Context is LineNumberLabelContext) &&
                                (declaration.ParentDeclaration == null ||
                                 !IgnoreDeclarationTypes.Contains(declaration.ParentDeclaration.DeclarationType) &&
                                 !handlers.Contains(declaration.ParentDeclaration)) &&
                                !whitelistedNames.Contains(declaration.IdentifierName) &&
                                !VariableNameValidator.IsMeaningfulName(declaration.IdentifierName));

            return((from issue in issues
                    let props = issue.DeclarationType.HasFlag(DeclarationType.Module) ||
                                issue.DeclarationType.HasFlag(DeclarationType.Project)
                        ? new Dictionary <string, string> {
                { "DisableFixes", "IgnoreOnceQuickFix" }
            } : null
                    select new DeclarationInspectionResult(this,
                                                           string.Format(InspectionsUI.IdentifierNameInspectionResultFormat,
                                                                         RubberduckUI.ResourceManager.GetString("DeclarationType_" + issue.DeclarationType,
                                                                                                                CultureInfo.CurrentUICulture), issue.IdentifierName), issue, properties: props))
                   .ToList());
        }
        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()
        {
            return(UserDeclarations
                   .Where(declaration =>
            {
                if (declaration.DeclarationType != DeclarationType.Variable ||
                    !new[] { DeclarationType.ClassModule, DeclarationType.ProceduralModule }.Contains(declaration.ParentDeclaration.DeclarationType))
                {
                    return false;
                }

                var firstReference = declaration.References.FirstOrDefault();

                if (firstReference == null ||
                    declaration.References.Any(r => r.ParentScoping != firstReference.ParentScoping))
                {
                    return false;
                }

                var parentDeclaration = ParentDeclaration(firstReference);

                return parentDeclaration != null &&
                !new[]
                {
                    DeclarationType.PropertyGet,
                    DeclarationType.PropertyLet,
                    DeclarationType.PropertySet
                }.Contains(parentDeclaration.DeclarationType);
            })
                   .Select(issue =>
                           new MoveFieldCloserToUsageInspectionResult(this, issue, State, _wrapperFactory, new MessageBox())));
        }
Beispiel #4
0
        public override IEnumerable <InspectionResultBase> GetInspectionResults()
        {
            var declarations = UserDeclarations.ToList();

            var classes = UserDeclarations.Where(item => item.DeclarationType == DeclarationType.ClassModule).ToList();
            var modules = UserDeclarations.Where(item => item.DeclarationType == DeclarationType.ProceduralModule).ToList();

            var handlers = declarations.Where(item => item.DeclarationType == DeclarationType.Control)
                           .SelectMany(control => declarations.FindEventHandlers(control)).ToList();

            var withEventFields = UserDeclarations.Where(item => item.DeclarationType == DeclarationType.Variable && item.IsWithEvents);

            handlers.AddRange(withEventFields.SelectMany(field => declarations.FindEventProcedures(field)));

            var forms = declarations.Where(item => item.DeclarationType == DeclarationType.ClassModule &&
                                           item.QualifiedName.QualifiedModuleName.Component.Type == vbext_ComponentType.vbext_ct_MSForm)
                        .ToList();

            if (forms.Any())
            {
                handlers.AddRange(forms.SelectMany(form => State.FindFormEventHandlers(form)));
            }

            handlers.AddRange(State.AllDeclarations.FindBuiltInEventHandlers());

            var items = declarations
                        .Where(item => !IsIgnoredDeclaration(declarations, item, handlers, classes, modules) &&
                               !IsInspectionDisabled(item, AnnotationName)).ToList();
            var issues = items.Select(issue => new IdentifierNotUsedInspectionResult(this, issue, issue.Context, issue.QualifiedName.QualifiedModuleName));

            issues = DocumentNames.DocumentEventHandlerPrefixes.Aggregate(issues, (current, item) => current.Where(issue => !issue.Description.Contains("'" + item)));

            return(issues.ToList());
        }
Beispiel #5
0
        public override IEnumerable <InspectionResultBase> GetInspectionResults()
        {
            var results = UserDeclarations.Where(declaration =>
                                                 declaration.DeclarationType == DeclarationType.Constant && !declaration.References.Any());

            return(results.Select(issue =>
                                  new IdentifierNotUsedInspectionResult(this, issue, ((dynamic)issue.Context).identifier(), issue.QualifiedName.QualifiedModuleName)).Cast <InspectionResultBase>());
        }
        public override IEnumerable <InspectionResultBase> GetInspectionResults()
        {
            var issues = UserDeclarations
                         .Where(declaration => declaration.DeclarationType == DeclarationType.Variable &&
                                declaration.Accessibility == Accessibility.Public)
                         .Select(issue => new EncapsulatePublicFieldInspectionResult(this, issue, State))
                         .ToList();

            return(issues);
        }
Beispiel #7
0
        public override IEnumerable <InspectionResultBase> GetInspectionResults()
        {
            var issues = UserDeclarations
                         .Where(declaration => declaration.DeclarationType == DeclarationType.Project &&
                                declaration.IdentifierName.StartsWith("VBAProject"))
                         .Select(issue => new DefaultProjectNameInspectionResult(this, issue, State))
                         .ToList();

            return(issues);
        }
        public override IEnumerable <InspectionResultBase> GetInspectionResults()
        {
            var declarations = UserDeclarations.Where(declaration =>
                                                      !declaration.IsWithEvents &&
                                                      declaration.DeclarationType == DeclarationType.Variable &&
                                                      declaration.References.All(reference => reference.IsAssignment));

            return(declarations.Select(issue =>
                                       new IdentifierNotUsedInspectionResult(this, issue, ((dynamic)issue.Context).identifier(), issue.QualifiedName.QualifiedModuleName)));
        }
Beispiel #9
0
        public override IEnumerable <InspectionResultBase> GetInspectionResults()
        {
            var issues = UserDeclarations.Where(declaration =>
                                                (declaration.DeclarationType == DeclarationType.ClassModule ||
                                                 declaration.DeclarationType == DeclarationType.ProceduralModule) &&
                                                declaration.Annotations.Count(annotation => annotation.AnnotationType == AnnotationType.Folder) > 1);

            return(issues.Select(issue =>
                                 new MultipleFolderAnnotationsInspectionResult(this, issue)));
        }
Beispiel #10
0
 public override IEnumerable <InspectionResultBase> GetInspectionResults()
 {
     return(UserDeclarations
            .Where(declaration => declaration.IsSelfAssigned &&
                   declaration.IsTypeSpecified() &&
                   !ValueTypes.Contains(declaration.AsTypeName) &&
                   declaration.DeclarationType == DeclarationType.Variable &&
                   declaration.ParentScopeDeclaration != null &&
                   declaration.ParentScopeDeclaration.DeclarationType.HasFlag(DeclarationType.Member))
            .Select(issue => new SelfAssignedDeclarationInspectionResult(this, issue)));
 }
        public override IEnumerable <InspectionResultBase> GetInspectionResults()
        {
            var issues = UserDeclarations
                         .Where(item => item.DeclarationType == DeclarationType.Variable ||
                                item.DeclarationType == DeclarationType.Constant)
                         .GroupBy(variable => variable.Context.Parent as ParserRuleContext)
                         .Where(grouping => grouping.Count() > 1)
                         .Select(grouping => new MultipleDeclarationsInspectionResult(this, new QualifiedContext <ParserRuleContext>(grouping.First().QualifiedName.QualifiedModuleName, grouping.Key)));

            return(issues);
        }
Beispiel #12
0
        public override IEnumerable <InspectionResultBase> GetInspectionResults()
        {
            var assignedByValParameters = UserDeclarations.Where(declaration =>
                                                                 declaration.DeclarationType == DeclarationType.Parameter &&
                                                                 ((VBAParser.ArgContext)declaration.Context).BYVAL() != null &&
                                                                 declaration.References.Any(reference => reference.IsAssignment));

            var issues = assignedByValParameters
                         .Select(param => new AssignedByValParameterInspectionResult(this, param));

            return(issues);
        }
Beispiel #13
0
        public override IEnumerable <InspectionResultBase> GetInspectionResults()
        {
            var multilineParameters = from p in UserDeclarations
                                      .Where(item => item.DeclarationType == DeclarationType.Parameter)
                                      where p.Context.GetSelection().LineCount > 1
                                      select p;

            var issues = multilineParameters
                         .Select(param => new MultilineParameterInspectionResult(this, param));

            return(issues);
        }
Beispiel #14
0
        public override IEnumerable <InspectionResultBase> GetInspectionResults()
        {
            var subStmts = State.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.DeclarationType == DeclarationType.Procedure &&
                                                     d.IdentifierName == c.identifier().GetText() &&
                                                     d.Context.GetSelection().Equals(c.GetSelection()));

                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.DeclarationType == DeclarationType.Procedure &&
                                                                   d.IdentifierName == c.identifier().GetText() &&
                                                                   d.Context.GetSelection().Equals(c.GetSelection()));

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

                return(UserDeclarations.Where(item => item.IsWithEvents)
                       .All(withEvents => UserDeclarations.FindEventProcedures(withEvents) == null));
            });

            return(State.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));
        }
Beispiel #16
0
        public override IEnumerable <InspectionResultBase> GetInspectionResults()
        {
            var issues = UserDeclarations
                         .Where(declaration => declaration.DeclarationType != DeclarationType.ModuleOption &&
                                (declaration.IdentifierName.Length < 3 ||
                                 char.IsDigit(declaration.IdentifierName.Last()) ||
                                 !declaration.IdentifierName.Any(c =>
                                                                 "aeiouy".Any(a => string.Compare(a.ToString(), c.ToString(), StringComparison.OrdinalIgnoreCase) == 0))))
                         .Select(issue => new UseMeaningfulNameInspectionResult(this, issue, State, _wrapperFactory, _messageBox))
                         .ToList();

            return(issues);
        }
Beispiel #17
0
        public override IEnumerable <InspectionResultBase> GetInspectionResults()
        {
            var settings         = _settings.Load(new CodeInspectionSettings()) ?? new CodeInspectionSettings();
            var whitelistedNames = settings.WhitelistedIdentifiers.Select(s => s.Identifier).ToList();

            var hungarians = UserDeclarations
                             .Where(declaration => !whitelistedNames.Contains(declaration.IdentifierName) &&
                                    TargetDeclarationTypes.Contains(declaration.DeclarationType) &&
                                    HungarianIdentifierRegex.IsMatch(declaration.IdentifierName))
                             .Select(issue => new IdentifierNameInspectionResult(this, issue, State, _messageBox, _settings))
                             .ToList();

            return(hungarians);
        }
        public override IEnumerable <InspectionResultBase> GetInspectionResults()
        {
            var usages = UserDeclarations.Where(declaration =>
                                                declaration.DeclarationType == DeclarationType.Variable &&
                                                !UserDeclarations.Any(d => d.DeclarationType == DeclarationType.UserDefinedType &&
                                                                      d.IdentifierName == declaration.AsTypeName) &&
                                                !declaration.IsSelfAssigned &&
                                                !declaration.References.Any(reference => reference.IsAssignment))
                         .SelectMany(declaration => declaration.References)
                         .Where(usage => !usage.IsInspectionDisabled(AnnotationName));

            foreach (var issue in usages)
            {
                yield return(new UnassignedVariableUsageInspectionResult(this, issue.Context, issue.QualifiedModuleName, issue.Declaration));
            }
        }
Beispiel #19
0
        protected override IEnumerable <IInspectionResult> DoGetInspectionResults()
        {
            var settings         = _settings.Load(new CodeInspectionSettings()) ?? new CodeInspectionSettings();
            var whitelistedNames = settings.WhitelistedIdentifiers.Select(s => s.Identifier).ToList();

            var hungarians = UserDeclarations
                             .Where(declaration => !whitelistedNames.Contains(declaration.IdentifierName) &&
                                    TargetDeclarationTypes.Contains(declaration.DeclarationType) &&
                                    HungarianIdentifierRegex.IsMatch(declaration.IdentifierName))
                             .Select(issue => new DeclarationInspectionResult(this,
                                                                              string.Format(Resources.Inspections.InspectionResults.IdentifierNameInspection,
                                                                                            RubberduckUI.ResourceManager.GetString($"DeclarationType_{issue.DeclarationType}", CultureInfo.CurrentUICulture),
                                                                                            issue.IdentifierName),
                                                                              issue));

            return(hungarians);
        }
Beispiel #20
0
        public override IEnumerable <InspectionResultBase> GetInspectionResults()
        {
            var options = UserDeclarations
                          .Where(declaration => declaration.DeclarationType == DeclarationType.ModuleOption &&
                                 declaration.Context is VBAParser.OptionBaseStmtContext)
                          .ToList();

            if (!options.Any())
            {
                return(new List <InspectionResultBase>());
            }

            var issues = options.Where(option => ((VBAParser.OptionBaseStmtContext)option.Context).numberLiteral().GetText() == "1")
                         .Select(issue => new OptionBaseInspectionResult(this, issue));

            return(issues);
        }
        public override IEnumerable <InspectionResultBase> GetInspectionResults()
        {
            var settings         = _settings.Load(new CodeInspectionSettings()) ?? new CodeInspectionSettings();
            var whitelistedNames = settings.WhitelistedIdentifiers.Select(s => s.Identifier).ToList();

            var issues = UserDeclarations
                         .Where(declaration => declaration.DeclarationType != DeclarationType.ModuleOption &&
                                !whitelistedNames.Contains(declaration.IdentifierName) &&
                                (declaration.IdentifierName.Length < 3 ||
                                 char.IsDigit(declaration.IdentifierName.Last()) ||
                                 !declaration.IdentifierName.Any(c =>
                                                                 "aeiouy".Any(a => string.Compare(a.ToString(), c.ToString(), StringComparison.OrdinalIgnoreCase) == 0))))
                         .Select(issue => new UseMeaningfulNameInspectionResult(this, issue, State, _messageBox))
                         .ToList();

            return(issues);
        }
        public override IEnumerable <InspectionResultBase> GetInspectionResults()
        {
            var declarations = UserDeclarations.Where(declaration =>
                                                      declaration.DeclarationType == DeclarationType.Variable &&
                                                      !UserDeclarations.Any(d => d.DeclarationType == DeclarationType.UserDefinedType &&
                                                                            d.IdentifierName == declaration.AsTypeName) &&
                                                      !declaration.IsSelfAssigned &&
                                                      !declaration.References.Any(reference => reference.IsAssignment && !IsIgnoringInspectionResultFor(reference, AnnotationName)));

            //The parameter scoping was apparently incorrect before - need to filter for the actual function.
            var lenFunction  = BuiltInDeclarations.SingleOrDefault(s => s.DeclarationType == DeclarationType.Function && s.Scope.Equals("VBE7.DLL;VBA.Strings.Len"));
            var lenbFunction = BuiltInDeclarations.SingleOrDefault(s => s.DeclarationType == DeclarationType.Function && s.Scope.Equals("VBE7.DLL;VBA.Strings.Len"));

            return(from issue in declarations
                   where issue.References.Any() &&
                   !DeclarationReferencesContainsReference(lenFunction, issue) &&
                   !DeclarationReferencesContainsReference(lenbFunction, issue)
                   select new UnassignedVariableUsageInspectionResult(this, issue.Context, issue.QualifiedName.QualifiedModuleName, issue));
        }
        public override IEnumerable <InspectionResultBase> GetInspectionResults()
        {
            var settings         = _settings.Load(new CodeInspectionSettings()) ?? new CodeInspectionSettings();
            var whitelistedNames = settings.WhitelistedIdentifiers.Select(s => s.Identifier).ToArray();

            var handlers = State.DeclarationFinder.FindEventHandlers();

            var issues = UserDeclarations
                         .Where(declaration => !string.IsNullOrEmpty(declaration.IdentifierName) &&
                                !IgnoreDeclarationTypes.Contains(declaration.DeclarationType) &&
                                (declaration.ParentDeclaration == null ||
                                 !IgnoreDeclarationTypes.Contains(declaration.ParentDeclaration.DeclarationType) &&
                                 !handlers.Contains(declaration.ParentDeclaration)) &&
                                !whitelistedNames.Contains(declaration.IdentifierName) &&
                                !VariableNameValidator.IsMeaningfulName(declaration.IdentifierName))
                         .Select(issue => new IdentifierNameInspectionResult(this, issue, State, _messageBox, _settings))
                         .ToList();

            return(issues);
        }
        protected override IEnumerable <IInspectionResult> DoGetInspectionResults()
        {
            var settings         = _settings.Read();
            var whitelistedNames = settings.WhitelistedIdentifiers.Select(s => s.Identifier).ToArray();

            var handlers = State.DeclarationFinder.FindEventHandlers();

            var issues = UserDeclarations
                         .Where(declaration => !string.IsNullOrEmpty(declaration.IdentifierName) &&
                                !IgnoreDeclarationTypes.Contains(declaration.DeclarationType) &&
                                !(declaration.Context is LineNumberLabelContext) &&
                                (declaration.ParentDeclaration == null ||
                                 !IgnoreDeclarationTypes.Contains(declaration.ParentDeclaration.DeclarationType) &&
                                 !handlers.Contains(declaration.ParentDeclaration)) &&
                                !whitelistedNames.Contains(declaration.IdentifierName) &&
                                !VBAIdentifierValidator.IsMeaningfulIdentifier(declaration.IdentifierName));

            return((from issue in issues select CreateInspectionResult(this, issue))
                   .ToList());
        }
Beispiel #25
0
        protected ParameterDeclaration GetParameterForReference(IdentifierReference reference)
        {
            // First case is for unqualified use: IsMissing(foo)
            // Second case if for use as a member access: VBA.IsMissing(foo)
            var argument = ((ParserRuleContext)reference.Context.Parent).GetDescendent <VBAParser.ArgumentExpressionContext>() ??
                           ((ParserRuleContext)reference.Context.Parent.Parent).GetDescendent <VBAParser.ArgumentExpressionContext>();

            var name = argument?.GetDescendent <VBAParser.SimpleNameExprContext>();

            if (name == null || name.Parent.Parent != argument)
            {
                return(null);
            }

            var procedure = reference.Context.GetAncestor <VBAParser.ModuleBodyElementContext>();

            return(UserDeclarations.Where(decl => decl is ModuleBodyElementDeclaration)
                   .Cast <ModuleBodyElementDeclaration>()
                   .FirstOrDefault(decl => decl.Context.Parent == procedure)?
                   .Parameters.FirstOrDefault(param => param.IdentifierName.Equals(name.GetText())));
        }
        protected override IEnumerable <IInspectionResult> DoGetInspectionResults()
        {
            var builtInEventHandlers = State.DeclarationFinder.FindEventHandlers().ToHashSet();

            var issues = new List <IInspectionResult>();

            var allUserProjects = State.DeclarationFinder.UserDeclarations(DeclarationType.Project).Cast <ProjectDeclaration>();

            foreach (var userProject in allUserProjects)
            {
                var referencedProjectIds = userProject.ProjectReferences.Select(reference => reference.ReferencedProjectId).ToHashSet();

                var userDeclarations = UserDeclarations.Where(declaration =>
                                                              declaration.ProjectId == userProject.ProjectId &&
                                                              // User has no control over build-in event handlers or their parameters, so we skip them
                                                              !DeclarationIsPartOfBuiltInEventHandler(declaration, builtInEventHandlers));

                foreach (var userDeclaration in userDeclarations)
                {
                    var shadowedDeclaration = State.DeclarationFinder
                                              .MatchName(userDeclaration.IdentifierName).FirstOrDefault(declaration =>
                                                                                                        !declaration.Equals(userDeclaration) &&
                                                                                                        DeclarationCanBeShadowed(declaration, userDeclaration, GetDeclarationSite(declaration, userDeclaration, referencedProjectIds)));

                    if (shadowedDeclaration != null)
                    {
                        issues.Add(new DeclarationInspectionResult(this,
                                                                   string.Format(InspectionsUI.ShadowedDeclarationInspectionResultFormat,
                                                                                 RubberduckUI.ResourceManager.GetString("DeclarationType_" + userDeclaration.DeclarationType, CultureInfo.CurrentUICulture),
                                                                                 userDeclaration.QualifiedName,
                                                                                 RubberduckUI.ResourceManager.GetString("DeclarationType_" + shadowedDeclaration.DeclarationType, CultureInfo.CurrentUICulture),
                                                                                 shadowedDeclaration.QualifiedName),
                                                                   userDeclaration));
                    }
                }
            }

            return(issues);
        }
        protected override IEnumerable <IInspectionResult> DoGetInspectionResults()
        {
            var interfaceImplementationMembers = State.DeclarationFinder.FindAllInterfaceImplementingMembers().ToHashSet();

            var excludeParameterMembers = State.DeclarationFinder.FindEventHandlers().ToHashSet();

            excludeParameterMembers.UnionWith(interfaceImplementationMembers);

            var result = UserDeclarations
                         .Where(declaration =>
                                declaration.AsTypeName == Tokens.Integer &&
                                !interfaceImplementationMembers.Contains(declaration) &&
                                declaration.DeclarationType != DeclarationType.LibraryFunction &&
                                (declaration.DeclarationType != DeclarationType.Parameter || IncludeParameterDeclaration(declaration, excludeParameterMembers)))
                         .Select(issue =>
                                 new DeclarationInspectionResult(this,
                                                                 string.Format(Resources.Inspections.InspectionResults.IntegerDataTypeInspection,
                                                                               RubberduckUI.ResourceManager.GetString($"DeclarationType_{issue.DeclarationType}", CultureInfo.CurrentUICulture), issue.IdentifierName),
                                                                 issue));

            return(result);
        }
Beispiel #28
0
        public override IEnumerable <InspectionResultBase> GetInspectionResults()
        {
            var declarations = UserDeclarations.Where(declaration =>
                                                      declaration.DeclarationType == DeclarationType.Variable &&
                                                      !UserDeclarations.Any(d => d.DeclarationType == DeclarationType.UserDefinedType &&
                                                                            d.IdentifierName == declaration.AsTypeName) &&
                                                      !declaration.IsSelfAssigned &&
                                                      !declaration.References.Any(reference => reference.IsAssignment));

            var lenFunction  = BuiltInDeclarations.SingleOrDefault(s => s.Scope == "VBE7.DLL;VBA.Strings.Len");
            var lenbFunction = BuiltInDeclarations.SingleOrDefault(s => s.Scope == "VBE7.DLL;VBA.Strings.LenB");

            foreach (var issue in declarations)
            {
                if (DeclarationReferencesContainsReference(lenFunction, issue) ||
                    DeclarationReferencesContainsReference(lenbFunction, issue))
                {
                    continue;
                }

                yield return(new UnassignedVariableUsageInspectionResult(this, issue.Context, issue.QualifiedName.QualifiedModuleName, issue));
            }
        }
 public override IEnumerable <InspectionResultBase> GetInspectionResults()
 {
     return(UserDeclarations.Where(item => item.IsUndeclared && item.DeclarationType == DeclarationType.Variable)
            .Select(item => new UndeclaredVariableInspectionResult(this, item)));
 }