コード例 #1
0
        protected override IEnumerable <IInspectionResult> DoGetInspectionResults()
        {
            var excel = State.DeclarationFinder.Projects.SingleOrDefault(item => !item.IsUserDefined && item.IdentifierName == "Excel");

            if (excel == null)
            {
                return(Enumerable.Empty <IInspectionResult>());
            }

            var members = new HashSet <string>(BuiltInDeclarations.Where(decl => decl.DeclarationType == DeclarationType.Function &&
                                                                         decl.ParentDeclaration != null &&
                                                                         decl.ParentDeclaration.ComponentName.Equals("WorksheetFunction"))
                                               .Select(decl => decl.IdentifierName));

            var usages = BuiltInDeclarations.Where(decl => decl.References.Any() &&
                                                   decl.ProjectName.Equals("Excel") &&
                                                   decl.ComponentName.Equals("Application") &&
                                                   members.Contains(decl.IdentifierName));

            return(from usage in usages
                   // filtering on references isn't the default ignore filtering
                   from reference in usage.References.Where(use => !use.IsIgnoringInspectionResultFor(AnnotationName))
                   let qualifiedSelection = new QualifiedSelection(reference.QualifiedModuleName, reference.Selection)
                                            select new IdentifierReferenceInspectionResult(this,
                                                                                           string.Format(InspectionResults.ApplicationWorksheetFunctionInspection, usage.IdentifierName),
                                                                                           State,
                                                                                           reference));
        }
コード例 #2
0
        public override IEnumerable <InspectionResultBase> GetInspectionResults()
        {
            var declarations = BuiltInDeclarations
                               // note: these *should* be functions, but somehow they're not defined as such
                               .Where(item => _tokens.Any(token => (item.IdentifierName == token || item.IdentifierName == "_B_var_" + token)) && item.References.Any());

            return(declarations.SelectMany(declaration => declaration.References
                                           .Select(item => new UntypedFunctionUsageInspectionResult(this, string.Format(Description, declaration.IdentifierName), item.QualifiedModuleName, item.Context))));
        }
コード例 #3
0
        public override IEnumerable <InspectionResultBase> GetInspectionResults()
        {
            var declarations = BuiltInDeclarations
                               // note: these *should* be functions, but somehow they're not defined as such
                               .Where(item =>
                                      _tokens.Any(token => item.IdentifierName == token || item.IdentifierName == "_B_var_" + token) &&
                                      item.References.Any(reference => _tokens.Contains(reference.IdentifierName)));

            return(declarations.SelectMany(declaration => declaration.References
                                           .Where(item => _tokens.Contains(item.IdentifierName))
                                           .Select(item => new UntypedFunctionUsageInspectionResult(this, item))));
        }
コード例 #4
0
        public override IEnumerable <InspectionResultBase> GetInspectionResults()
        {
            var declarations = BuiltInDeclarations
                               .Where(item =>
                                      _tokens.Any(token => item.IdentifierName == token || item.IdentifierName == "_B_var_" + token) &&
                                      item.Scope.StartsWith("VBE7.DLL;"));

            return(declarations.SelectMany(declaration => declaration.References
                                           .Where(item => _tokens.Contains(item.IdentifierName) &&
                                                  !IsInspectionDisabled(item.QualifiedModuleName.Component, item.Selection.StartLine))
                                           .Select(item => new UntypedFunctionUsageInspectionResult(this, item))));
        }
コード例 #5
0
        protected override IEnumerable <IInspectionResult> DoGetInspectionResults()
        {
            var declarations = BuiltInDeclarations
                               .Where(item =>
                                      _tokens.Any(token => item.IdentifierName == token || item.IdentifierName == "_B_var_" + token) &&
                                      item.Scope.StartsWith("VBE7.DLL;"));

            return(declarations.SelectMany(declaration => declaration.References
                                           .Where(item => _tokens.Contains(item.IdentifierName) &&
                                                  !IsIgnoringInspectionResultFor(item, AnnotationName))
                                           .Select(item => new IdentifierReferenceInspectionResult(this,
                                                                                                   string.Format(InspectionResults.UntypedFunctionUsageInspection, item.Declaration.IdentifierName),
                                                                                                   State,
                                                                                                   item))));
        }
コード例 #6
0
        public override IEnumerable <InspectionResultBase> GetInspectionResults()
        {
            if (_hostApp == null || _hostApp.ApplicationName != "Excel")
            {
                return(new InspectionResultBase[] { });
                // if host isn't Excel, the ExcelObjectModel declarations shouldn't be loaded anyway.
            }

            var issues = BuiltInDeclarations.Where(item => item.ParentScope.StartsWith("EXCEL.EXE;") &&
                                                   Targets.Contains(item.IdentifierName) &&
                                                   item.References.Any())
                         .SelectMany(declaration => declaration.References);

            return(issues.Select(issue =>
                                 new ImplicitActiveWorkbookReferenceInspectionResult(this, issue)));
        }
コード例 #7
0
        public override IEnumerable <InspectionResultBase> GetInspectionResults()
        {
            if (_hostApp == null || _hostApp.ApplicationName != "Excel")
            {
                return(new InspectionResultBase[] {});
                // if host isn't Excel, the ExcelObjectModel declarations shouldn't be loaded anyway.
            }

            var matches = BuiltInDeclarations.Where(item =>
                                                    Targets.Contains(item.IdentifierName)).ToList();

            var issues = matches.Where(item => item.References.Any())
                         .SelectMany(declaration => declaration.References);

            return(issues.Select(issue =>
                                 new ImplicitActiveSheetReferenceInspectionResult(this, issue)));
        }
        public override IEnumerable <InspectionResultBase> GetInspectionResults()
        {
            if (_hostApp().ApplicationName != "Excel")
            {
                return(new InspectionResultBase[] {});
                // if host isn't Excel, the ExcelObjectModel declarations shouldn't be loaded anyway.
            }

            var matches = BuiltInDeclarations.Where(item =>
                                                    (item.ParentScope == "Excel.Global" || item.ParentScope == "Excel.Application") &&
                                                    Targets.Contains(item.IdentifierName)).ToList();

            var issues = matches.Where(item => item.References.Any())
                         .SelectMany(declaration => declaration.References);

            return(issues.Select(issue =>
                                 new ImplicitActiveSheetReferenceInspectionResult(this, string.Format(Description, issue.Declaration.IdentifierName), issue.Context, issue.QualifiedModuleName)));
        }
コード例 #9
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 && !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));
        }
コード例 #10
0
        protected override IEnumerable <IInspectionResult> DoGetInspectionResults()
        {
            var declarations = State.DeclarationFinder.UserDeclarations(DeclarationType.Variable)
                               .Where(declaration => !declaration.IsArray &&
                                      State.DeclarationFinder.MatchName(declaration.AsTypeName)
                                      .All(d => d.DeclarationType != DeclarationType.UserDefinedType) &&
                                      !declaration.IsSelfAssigned &&
                                      !declaration.References.Any(reference => reference.IsAssignment));

            var excludedDeclarations = BuiltInDeclarations.Where(decl => IgnoredFunctions.Contains(decl.QualifiedName.ToString())).ToList();

            return(declarations
                   .Where(d => d.References.Any() && !excludedDeclarations.Any(excl => DeclarationReferencesContainsReference(excl, d)))
                   .SelectMany(d => d.References.Where(r => !IsAssignedByRefArgument(r.ParentScoping, r)))
                   .Distinct()
                   .Where(r => !r.Context.TryGetAncestor <VBAParser.RedimStmtContext>(out _) && !IsArraySubscriptAssignment(r))
                   .Select(r => new IdentifierReferenceInspectionResult(this,
                                                                        string.Format(InspectionResults.UnassignedVariableUsageInspection, r.IdentifierName),
                                                                        State,
                                                                        r)).ToList());
        }
コード例 #11
0
        protected override IEnumerable <IInspectionResult> DoGetInspectionResults()
        {
            var excel = State.DeclarationFinder.Projects.SingleOrDefault(item => !item.IsUserDefined && item.IdentifierName == "Excel");

            if (excel == null)
            {
                return(Enumerable.Empty <IInspectionResult>());
            }

            var targetProperties = BuiltInDeclarations
                                   .OfType <PropertyGetDeclaration>()
                                   .Where(x => InterestingMembers.Contains(x.IdentifierName) && InterestingClasses.Contains(x.ParentDeclaration?.IdentifierName))
                                   .ToList();

            var members = targetProperties.SelectMany(item =>
                                                      item.References.Where(reference => !IsIgnoringInspectionResultFor(reference, AnnotationName)));

            return(members.Select(issue => new IdentifierReferenceInspectionResult(this,
                                                                                   string.Format(InspectionResults.ImplicitActiveWorkbookReferenceInspection, issue.Context.GetText()),
                                                                                   State,
                                                                                   issue)));
        }
コード例 #12
0
        protected override IEnumerable <IInspectionResult> DoGetInspectionResults()
        {
            var excel = State.DeclarationFinder.Projects.SingleOrDefault(item => !item.IsUserDefined && item.IdentifierName == "Excel");

            if (excel == null)
            {
                return(Enumerable.Empty <IInspectionResult>());
            }

            var targetProperties = BuiltInDeclarations
                                   .OfType <PropertyDeclaration>()
                                   .Where(x => InterestingMembers.Contains(x.IdentifierName) && InterestingClasses.Contains(x.ParentDeclaration?.IdentifierName))
                                   .ToList();

            var references = targetProperties.SelectMany(declaration => declaration.References
                                                         .Where(reference => !IsIgnoringInspectionResultFor(reference, AnnotationName) &&
                                                                IsAccessedWithStringLiteralParameter(reference))
                                                         .Select(reference => new IdentifierReferenceInspectionResult(this,
                                                                                                                      InspectionResults.SheetAccessedUsingStringInspection, State, reference)));

            var issues = new List <IdentifierReferenceInspectionResult>();

            foreach (var reference in references)
            {
                using (var component = GetVBComponentMatchingSheetName(reference))
                {
                    if (component == null)
                    {
                        continue;
                    }
                    using (var properties = component.Properties)
                    {
                        reference.Properties.CodeName = (string)properties.Single(property => property.Name == "CodeName").Value;
                    }
                    issues.Add(reference);
                }
            }
            return(issues);
        }
コード例 #13
0
        protected override IEnumerable <IInspectionResult> DoGetInspectionResults()
        {
            var declarations = State.DeclarationFinder.UserDeclarations(DeclarationType.Variable)
                               .Where(result => !IsIgnoringInspectionResultFor(result, AnnotationName))
                               .Where(declaration =>
                                      State.DeclarationFinder.MatchName(declaration.AsTypeName).All(d => d.DeclarationType != DeclarationType.UserDefinedType) &&
                                      !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(declarations.Where(d => d.References.Any() &&
                                      !DeclarationReferencesContainsReference(lenFunction, d) &&
                                      !DeclarationReferencesContainsReference(lenbFunction, d))
                   .SelectMany(d => d.References)
                   .Select(r => new IdentifierReferenceInspectionResult(this,
                                                                        string.Format(InspectionsUI.UnassignedVariableUsageInspectionResultFormat, r.IdentifierName),
                                                                        State,
                                                                        r)).ToList());
        }
コード例 #14
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));
            }
        }
コード例 #15
0
        public override IEnumerable <InspectionResultBase> GetInspectionResults()
        {
            var excel = State.DeclarationFinder.Projects.SingleOrDefault(item => item.IsBuiltIn && item.IdentifierName == "Excel");

            if (excel == null)
            {
                return(Enumerable.Empty <InspectionResultBase>());
            }

            var members = new HashSet <string>(BuiltInDeclarations.Where(decl => decl.DeclarationType == DeclarationType.Function &&
                                                                         decl.ParentDeclaration != null &&
                                                                         decl.ParentDeclaration.ComponentName.Equals("WorksheetFunction"))
                                               .Select(decl => decl.IdentifierName));

            var usages = BuiltInDeclarations.Where(decl => decl.References.Any() &&
                                                   decl.ProjectName.Equals("Excel") &&
                                                   decl.ComponentName.Equals("Application") &&
                                                   members.Contains(decl.IdentifierName));

            return(from usage in usages
                   from reference in usage.References.Where(use => !IsIgnoringInspectionResultFor(use, AnnotationName))
                   let qualifiedSelection = new QualifiedSelection(reference.QualifiedModuleName, reference.Selection)
                                            select new ApplicationWorksheetFunctionInspectionResult(this, qualifiedSelection, usage.IdentifierName));
        }