protected override IEnumerable <IInspectionResult> DoGetInspectionResults()
        {
            var interestingDeclarations =
                State.AllDeclarations.Where(item =>
                                            item.AsTypeDeclaration != null &&
                                            ClassModuleDeclaration.HasDefaultMember(item.AsTypeDeclaration));

            var interestingReferences = interestingDeclarations
                                        .SelectMany(declaration => declaration.References)
                                        .Where(reference =>
            {
                var letStmtContext = reference.Context.GetAncestor <VBAParser.LetStmtContext>();
                return(reference.IsAssignment &&
                       letStmtContext != null &&
                       letStmtContext.LET() == null &&
                       !reference.IsIgnoringInspectionResultFor(AnnotationName));
            });

            return(interestingReferences.Select(reference => new IdentifierReferenceInspectionResult(this,
                                                                                                     string.Format(InspectionResults.ImplicitDefaultMemberAssignmentInspection,
                                                                                                                   reference.Declaration.IdentifierName,
                                                                                                                   reference.Declaration.AsTypeDeclaration.IdentifierName),
                                                                                                     State,
                                                                                                     reference)));
        }
Exemple #2
0
        private static bool MayRequireAssignmentUsingSet(Declaration declaration)
        {
            if (declaration.DeclarationType == DeclarationType.PropertyLet)
            {
                return(false);
            }

            if (declaration.AsTypeName == Tokens.Variant)
            {
                return(true);
            }

            if (declaration.IsArray)
            {
                return(false);
            }

            if (declaration.AsTypeDeclaration != null)
            {
                if ((ClassModuleDeclaration.HasDefaultMember(declaration.AsTypeDeclaration) ||
                     declaration.AsTypeDeclaration.DeclarationType == DeclarationType.Enumeration))
                {
                    return(false);
                }
            }

            if (SymbolList.ValueTypes.Contains(declaration.AsTypeName))
            {
                return(false);
            }
            return(true);
        }
        public override IEnumerable <InspectionResultBase> GetInspectionResults()
        {
            var interestingDeclarations =
                State.AllDeclarations.Where(item =>
                                            item.AsTypeDeclaration != null &&
                                            ClassModuleDeclaration.HasDefaultMember(item.AsTypeDeclaration));

            var interestingReferences = interestingDeclarations
                                        .SelectMany(declaration => declaration.References)
                                        .Where(reference =>
            {
                var letStmtContext = ParserRuleContextHelper.GetParent <VBAParser.LetStmtContext>(reference.Context);
                return(reference.IsAssignment && letStmtContext != null && letStmtContext.LET() == null);
            });

            return(interestingReferences.Select(reference => new ImplicitDefaultMemberAssignmentInspectionResult(this, reference)));
        }
        public override IEnumerable <InspectionResultBase> GetInspectionResults()
        {
            var interestingDeclarations =
                State.AllUserDeclarations.Where(item =>
                                                !item.IsSelfAssigned &&
                                                !item.IsArray &&
                                                !SymbolList.ValueTypes.Contains(item.AsTypeName) &&
                                                (item.AsTypeDeclaration == null || (!ClassModuleDeclaration.HasDefaultMember(item.AsTypeDeclaration) &&
                                                                                    item.AsTypeDeclaration.DeclarationType != DeclarationType.Enumeration &&
                                                                                    item.AsTypeDeclaration.DeclarationType != DeclarationType.UserDefinedType)) &&
                                                (item.DeclarationType == DeclarationType.Variable ||
                                                 item.DeclarationType == DeclarationType.Parameter));

            var interestingMembers =
                State.AllUserDeclarations.Where(item =>
                                                (item.DeclarationType == DeclarationType.Function || item.DeclarationType == DeclarationType.PropertyGet) &&
                                                !item.IsArray &&
                                                item.IsTypeSpecified &&
                                                !SymbolList.ValueTypes.Contains(item.AsTypeName) &&
                                                (item.AsTypeDeclaration == null || // null if unresolved (e.g. in unit tests)
                                                 (item.AsTypeDeclaration.DeclarationType != DeclarationType.Enumeration && item.AsTypeDeclaration.DeclarationType != DeclarationType.UserDefinedType &&
                                                  item.AsTypeDeclaration != null &&
                                                  !ClassModuleDeclaration.HasDefaultMember(item.AsTypeDeclaration))));

            var interestingReferences = interestingDeclarations
                                        .Union(interestingMembers.SelectMany(item =>
                                                                             item.References.Where(reference => reference.ParentScoping.Equals(item) && reference.IsAssignment)
                                                                             .Select(reference => reference.Declaration)))
                                        .SelectMany(declaration =>
                                                    declaration.References.Where(reference =>
            {
                var letStmtContext = ParserRuleContextHelper.GetParent <VBAParser.LetStmtContext>(reference.Context);
                return(reference.IsAssignment && letStmtContext != null && letStmtContext.LET() == null);
            })
                                                    );


            return(interestingReferences.Select(reference => new ObjectVariableNotSetInspectionResult(this, reference)));
        }