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 Declaration FindMemberReferencedProjectInModule(Declaration callingProject, Declaration callingModule, Declaration callingParent, Declaration memberModule, string memberName, DeclarationType memberType) { var memberMatches = FindAllInReferencedProjectByPriority(callingProject, memberName, p => p.DeclarationType.HasFlag(memberType) && memberModule.Equals(Declaration.GetModuleParent(p))); 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 = FindMemberReferencedProjectInModule(callingProject, callingModule, callingParent, supertype, memberName, memberType); if (supertypeMember != null) { return(supertypeMember); } } return(null); }
public Declaration FindMemberWithParent(Declaration callingProject, Declaration callingModule, Declaration callingParent, Declaration parent, string memberName, DeclarationType memberType) { var allMatches = MatchName(memberName); var memberMatches = allMatches.Where(m => m.DeclarationType.HasFlag(memberType) && parent.Equals(m.ParentDeclaration)); 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(parent)) { var supertypeMember = FindMemberWithParent(callingProject, callingModule, callingParent, supertype, memberName, memberType); if (supertypeMember != null) { return(supertypeMember); } } return(null); }
private static bool IsInstanceMemberOfModuleOrOneOfItsSupertypes(Declaration module, Declaration member) { return(IsInstanceMemberOfModule(module, member) || ClassModuleDeclaration.GetSupertypes(module).Any(supertype => IsInstanceMemberOfModuleOrOneOfItsSupertypes(supertype, member))); //ClassModuleDeclaration.GetSuperTypes never returns null. }