Esempio n. 1
0
        public Declaration FindMemberEnclosingModule(Declaration callingModule, Declaration callingParent, string memberName, DeclarationType memberType)
        {
            // We do not explicitly pass the callingProject here because we have to walk up the type hierarchy
            // and thus the project differs depending on the callingModule.
            var callingProject = Declaration.GetProjectParent(callingModule);
            var allMatches     = MatchName(memberName);
            var memberMatches  = allMatches.Where(m =>
                                                  m.DeclarationType.HasFlag(memberType) &&
                                                  Declaration.GetProjectParent(m).Equals(callingProject) &&
                                                  callingModule.Equals(Declaration.GetModuleParent(m)));
            var accessibleMembers = memberMatches.Where(m => AccessibilityCheck.IsMemberAccessible(callingProject, callingModule, callingParent, m));
            var match             = accessibleMembers.FirstOrDefault();

            if (match != null)
            {
                return(match);
            }
            // Classes such as Worksheet have properties such as Range that can be access in a user defined class such as Sheet1,
            // that's why we have to walk the type hierarchy and find these implementations.
            foreach (var supertype in ClassModuleDeclaration.GetSupertypes(callingModule))
            {
                // Only built-in classes such as Worksheet can be considered "real base classes".
                // User created interfaces work differently and don't allow accessing accessing implementations.
                if (!supertype.IsBuiltIn)
                {
                    continue;
                }
                var supertypeMatch = FindMemberEnclosingModule(supertype, callingParent, memberName, memberType);
                if (supertypeMatch != null)
                {
                    return(supertypeMatch);
                }
            }
            return(match);
        }
        public bool IsIgnoringInspectionResultFor(string inspectionName)
        {
            var isIgnoredAtModuleLevel =
                Declaration.GetModuleParent(ParentScoping).Annotations
                .Any(annotation => annotation.AnnotationType == AnnotationType.IgnoreModule &&
                     ((IgnoreModuleAnnotation)annotation).IsIgnored(inspectionName));

            return(isIgnoredAtModuleLevel || Annotations.Any(annotation =>
                                                             annotation.AnnotationType == AnnotationType.Ignore &&
                                                             ((IgnoreAnnotation)annotation).IsIgnored(inspectionName)));
        }
Esempio n. 3
0
        private void AnnotateType(Declaration declaration)
        {
            if (declaration.DeclarationType == DeclarationType.ClassModule ||
                declaration.DeclarationType == DeclarationType.UserDefinedType ||
                declaration.DeclarationType == DeclarationType.ComAlias)
            {
                declaration.AsTypeDeclaration = declaration;
                return;
            }
            string typeExpression;

            if (declaration.AsTypeContext != null && declaration.AsTypeContext.type().complexType() != null)
            {
                var typeContext = declaration.AsTypeContext;
                typeExpression = typeContext.type().complexType().GetText();
            }
            else if (!string.IsNullOrWhiteSpace(declaration.AsTypeNameWithoutArrayDesignator) && !SymbolList.BaseTypes.Contains(declaration.AsTypeNameWithoutArrayDesignator.ToUpperInvariant()))
            {
                typeExpression = declaration.AsTypeNameWithoutArrayDesignator;
            }
            else
            {
                return;
            }
            var module = Declaration.GetModuleParent(declaration);

            if (module == null)
            {
                Logger.Warn("Type annotation failed for {0} because module parent is missing.", typeExpression);
                return;
            }
            var expressionContext = _expressionParser.Parse(typeExpression.Trim());
            var boundExpression   = _bindingService.ResolveType(module, declaration.ParentDeclaration, expressionContext);

            if (boundExpression.Classification != ExpressionClassification.ResolutionFailed)
            {
                declaration.AsTypeDeclaration = boundExpression.ReferencedDeclaration;
            }
            else
            {
                const string IGNORE_THIS = "DISPATCH";
                if (typeExpression != IGNORE_THIS)
                {
                    Logger.Warn("Failed to resolve type {0}", typeExpression);
                }
            }
        }
Esempio n. 4
0
        public Declaration FindMemberEnclosedProjectWithoutEnclosingModule(Declaration callingProject, Declaration callingModule, Declaration callingParent, string memberName, DeclarationType memberType)
        {
            var project = callingProject;
            var module  = callingModule;
            var parent  = callingParent;

            var allMatches    = MatchName(memberName);
            var memberMatches = allMatches.Where(m =>
                                                 m.DeclarationType.HasFlag(memberType) &&
                                                 Declaration.GetModuleParent(m).DeclarationType == DeclarationType.ProceduralModule &&
                                                 Declaration.GetProjectParent(m).Equals(callingProject) &&
                                                 !callingModule.Equals(Declaration.GetModuleParent(m)));
            var accessibleMembers = memberMatches.Where(m => AccessibilityCheck.IsMemberAccessible(callingProject, callingModule, callingParent, m));
            var match             = accessibleMembers.FirstOrDefault();

            return(match);
        }
Esempio n. 5
0
        public Declaration FindMemberEnclosedProjectInModule(Declaration callingProject, Declaration callingModule, Declaration callingParent, Declaration memberModule, string memberName, DeclarationType memberType)
        {
            var allMatches    = MatchName(memberName);
            var memberMatches = allMatches.Where(m =>
                                                 m.DeclarationType.HasFlag(memberType) &&
                                                 Declaration.GetProjectParent(m).Equals(callingProject) &&
                                                 memberModule.Equals(Declaration.GetModuleParent(m)));
            var accessibleMembers = memberMatches.Where(m => AccessibilityCheck.IsMemberAccessible(callingProject, callingModule, callingParent, m));
            var match             = accessibleMembers.FirstOrDefault();

            if (match != null)
            {
                return(match);
            }
            foreach (var supertype in ClassModuleDeclaration.GetSupertypes(memberModule))
            {
                var supertypeMember = FindMemberEnclosedProjectInModule(callingProject, callingModule, callingParent, supertype, memberName, memberType);
                if (supertypeMember != null)
                {
                    return(supertypeMember);
                }
            }
            return(null);
        }
Esempio n. 6
0
        public static bool IsMemberAccessible(Declaration callingProject, Declaration callingModule, Declaration callingParent, Declaration calleeMember)
        {
            if (calleeMember == null)
            {
                return(false);
            }
            if (IsInstanceMemberOfModuleOrOneOfItsSupertypes(callingModule, calleeMember) ||
                IsLocalMemberOfTheCallingSubroutineOrProperty(callingParent, calleeMember))
            {
                return(true);
            }
            if (!calleeMember.IsUserDefined && calleeMember.Accessibility > Accessibility.Friend)
            {
                return(true);
            }
            var memberModule = Declaration.GetModuleParent(calleeMember);

            return(IsModuleAccessible(callingProject, callingModule, memberModule) &&
                   (calleeMember.DeclarationType.HasFlag(DeclarationType.EnumerationMember) ||
                    calleeMember.DeclarationType.HasFlag(DeclarationType.UserDefinedTypeMember) ||
                    calleeMember.DeclarationType.HasFlag(DeclarationType.ComAlias) ||
                    HasPublicScope(calleeMember) ||
                    (IsEnclosingProject(callingProject, memberModule) && IsAccessibleThroughoutTheSameProject(calleeMember))));
        }
Esempio n. 7
0
        public Declaration FindEvent(Declaration module, string eventName)
        {
            var matches = MatchName(eventName);

            return(matches.Where(m => module.Equals(Declaration.GetModuleParent(m)) && m.DeclarationType == DeclarationType.Event).FirstOrDefault());
        }
Esempio n. 8
0
        public Declaration FindMemberReferencedProjectInGlobalClassModule(Declaration callingProject, Declaration callingModule, Declaration callingParent, string memberName, DeclarationType memberType)
        {
            var memberMatches     = FindAllInReferencedProjectByPriority(callingProject, memberName, p => p.DeclarationType.HasFlag(memberType) && (Declaration.GetModuleParent(p) == null || Declaration.GetModuleParent(p).DeclarationType == DeclarationType.ClassModule) && ((ClassModuleDeclaration)Declaration.GetModuleParent(p)).IsGlobalClassModule);
            var accessibleMembers = memberMatches.Where(m => AccessibilityCheck.IsMemberAccessible(callingProject, callingModule, callingParent, m));
            var match             = accessibleMembers.FirstOrDefault();

            return(match);
        }
Esempio n. 9
0
        public Declaration FindMemberReferencedProject(Declaration callingProject, Declaration callingModule, Declaration callingParent, string memberName, DeclarationType memberType)
        {
            bool isInstanceSensitive = IsInstanceSensitive(memberType);
            var  memberMatches       = FindAllInReferencedProjectByPriority(callingProject, memberName, p => (!isInstanceSensitive || Declaration.GetModuleParent(p) == null || Declaration.GetModuleParent(p).DeclarationType != DeclarationType.ClassModule) && p.DeclarationType.HasFlag(memberType));
            var  accessibleMembers   = memberMatches.Where(m => AccessibilityCheck.IsMemberAccessible(callingProject, callingModule, callingParent, m));
            var  match = accessibleMembers.FirstOrDefault();

            return(match);
        }