Example #1
0
        protected override IEnumerable <Declaration> ObjectionableDeclarations(DeclarationFinder finder)
        {
            var excel = finder.Projects.SingleOrDefault(item => !item.IsUserDefined && item.IdentifierName == "Excel");

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

            if (!(finder.FindClassModule("WorksheetFunction", excel, true) is ModuleDeclaration worksheetFunctionsModule))
            {
                return(Enumerable.Empty <Declaration>());
            }

            if (!(finder.FindClassModule("Application", excel, true) is ModuleDeclaration excelApplicationClass))
            {
                return(Enumerable.Empty <Declaration>());
            }

            var worksheetFunctionNames = worksheetFunctionsModule.Members
                                         .Where(decl => decl.DeclarationType == DeclarationType.Function)
                                         .Select(decl => decl.IdentifierName)
                                         .ToHashSet();

            return(excelApplicationClass.Members
                   .Where(decl => worksheetFunctionNames.Contains(decl.IdentifierName)));
        }
Example #2
0
        protected override IEnumerable <Declaration> ObjectionableDeclarations(DeclarationFinder finder)
        {
            if (!finder.TryFindProjectDeclaration("Excel", out var excel))
            {
                // [RequiredHost] attribute puts this in "should not happen" territory.
                yield break;
            }
            var sheetsClass = (ModuleDeclaration)finder.FindClassModule("Sheets", excel, true);

            if (sheetsClass == null)
            {
                // [RequiredHost] attribute puts this in "should not happen" territory.
                yield break;
            }

            if (sheetsClass != null)
            {
                foreach (var property in sheetsClass.Members.OfType <PropertyDeclaration>())
                {
                    if (InterestingProperties.Any(name => name.Equals(property.IdentifierName, System.StringComparison.InvariantCultureIgnoreCase)))
                    {
                        yield return(property);
                    }
                }
            }
        }
Example #3
0
        protected override IEnumerable <Declaration> ObjectionableDeclarations(DeclarationFinder finder)
        {
            if (Excel == null)
            {
                if (!finder.TryFindProjectDeclaration("Excel", out var excel))
                {
                    return(Enumerable.Empty <Declaration>());
                }
                Excel = excel;
            }

            if (_relevantClasses == null)
            {
                _relevantClasses = InterestingClasses
                                   .Select(className => finder.FindClassModule(className, Excel, true))
                                   .OfType <ModuleDeclaration>()
                                   .ToList();
            }

            if (_relevantProperties == null)
            {
                _relevantProperties = _relevantClasses
                                      .SelectMany(classDeclaration => classDeclaration.Members)
                                      .OfType <PropertyGetDeclaration>()
                                      .Where(member => InterestingMembers.Contains(member.IdentifierName))
                                      .ToList();
            }

            return(_relevantProperties);
        }
Example #4
0
        private static Declaration FormsClassModuleFromParserState(DeclarationFinder finder)
        {
            var msForms = finder.FindProject("MSForms");

            if (msForms == null)
            {
                //The corresponding COM reference has not been loaded.
                return(null);
            }

            return(finder.FindClassModule("FormEvents", msForms, true));
        }
        protected override bool IsResultReference(IdentifierReference reference, DeclarationFinder finder)
        {
            var qualifiers  = base.GetQualifierCandidates(reference, finder);
            var isQualified = qualifiers.Any();
            var document    = Declaration.GetModuleParent(reference.ParentNonScoping) as DocumentModuleDeclaration;

            var isHostWorkbook = (document?.SupertypeNames.Contains("Workbook") ?? false) &&
                                 (document?.ProjectId?.Equals(reference.QualifiedModuleName.ProjectId) ?? false);

            if (!isQualified)
            {
                // unqualified calls aren't referring to ActiveWorkbook only inside a Workbook module:
                return(!isHostWorkbook);
            }
            else
            {
                if (_applicationCandidates == null)
                {
                    var applicationClass = finder.FindClassModule("Application", base.Excel, includeBuiltIn: true);
                    // note: underscored declarations would be for unqualified calls
                    var workbookClass  = finder.FindClassModule("Workbook", base.Excel, includeBuiltIn: true);
                    var worksheetClass = finder.FindClassModule("Worksheet", base.Excel, includeBuiltIn: true);
                    var hostBook       = finder.UserDeclarations(DeclarationType.Document)
                                         .Cast <DocumentModuleDeclaration>()
                                         .SingleOrDefault(doc => doc.ProjectId.Equals(reference.QualifiedModuleName.ProjectId) &&
                                                          doc.SupertypeNames.Contains("Workbook"));

                    _applicationCandidates = finder.MatchName("Application")
                                             .Where(m => m.Equals(applicationClass) ||
                                                    (m.ParentDeclaration.Equals(workbookClass) && m.DeclarationType.HasFlag(DeclarationType.PropertyGet)) ||
                                                    (m.ParentDeclaration.Equals(worksheetClass) && m.DeclarationType.HasFlag(DeclarationType.PropertyGet)) ||
                                                    (m.ParentDeclaration.Equals(hostBook) && m.DeclarationType.HasFlag(DeclarationType.PropertyGet)))
                                             .ToList();
                }

                // qualified calls are referring to ActiveWorkbook if qualifier is the Application object:
                return(_applicationCandidates.Any(candidate => qualifiers.Any(q => q.Equals(candidate))));
            }
        }
        protected override IEnumerable <Declaration> ObjectionableDeclarations(DeclarationFinder finder)
        {
            var excel = finder.Projects.SingleOrDefault(item => !item.IsUserDefined && item.IdentifierName == "Excel");

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

            var globalModules = GlobalObjectClassNames
                                .Select(className => finder.FindClassModule(className, excel, true))
                                .OfType <ModuleDeclaration>();

            return(globalModules
                   .SelectMany(moduleClass => moduleClass.Members)
                   .Where(declaration => TargetMemberNames.Contains(declaration.IdentifierName) &&
                          declaration.DeclarationType.HasFlag(DeclarationType.Member) &&
                          declaration.AsTypeName == "Range"));
        }
Example #7
0
        protected override IEnumerable<Declaration> ObjectionableDeclarations(DeclarationFinder finder)
        {
            var excel = finder.Projects
                .SingleOrDefault(project => project.IdentifierName == "Excel" && !project.IsUserDefined);
            if (excel == null)
            {
                return Enumerable.Empty<Declaration>();
            }

            var relevantClasses = InterestingClasses
                .Select(className => finder.FindClassModule(className, excel, true))
                .OfType<ModuleDeclaration>();

            var relevantProperties = relevantClasses
                .SelectMany(classDeclaration => classDeclaration.Members)
                .OfType<PropertyGetDeclaration>()
                .Where(member => InterestingMembers.Contains(member.IdentifierName));

            return relevantProperties;
        }