Beispiel #1
0
        void FindOverrides(object sender, EventArgs e)
        {
            MenuCommand              item           = (MenuCommand)sender;
            IMember                  member         = (IMember)item.Tag;
            IEnumerable <IClass>     derivedClasses = RefactoringService.FindDerivedClasses(member.DeclaringType, ParserService.AllProjectContents, false);
            List <SearchResultMatch> results        = new List <SearchResultMatch>();
            IAmbience                ambience       = AmbienceService.GetCurrentAmbience();

            ambience.ConversionFlags = ConversionFlags.UseFullyQualifiedMemberNames | ConversionFlags.ShowTypeParameterList;
            foreach (IClass derivedClass in derivedClasses)
            {
                if (derivedClass.CompilationUnit == null)
                {
                    continue;
                }
                if (derivedClass.CompilationUnit.FileName == null)
                {
                    continue;
                }
                IMember m = MemberLookupHelper.FindSimilarMember(derivedClass, member);
                if (m != null && !m.Region.IsEmpty)
                {
                    string            matchText = ambience.Convert(m);
                    SearchResultMatch res       = new SimpleSearchResultMatch(matchText, new TextLocation(m.Region.BeginColumn - 1, m.Region.BeginLine - 1));
                    res.ProvidedDocumentInformation = FindReferencesAndRenameHelper.GetDocumentInformation(m.DeclaringType.CompilationUnit.FileName);
                    results.Add(res);
                }
            }
            SearchResultPanel.Instance.ShowSearchResults(new SearchResult(
                                                             StringParser.Parse("${res:SharpDevelop.Refactoring.OverridesOf}", new string[, ] {
                { "Name", member.Name }
            }),
                                                             results
                                                             ));
        }
Beispiel #2
0
            protected ContextActionViewModel MakeGoToMemberAction(IClass containingClass, ObservableCollection <ContextActionViewModel> childActions)
            {
                var overridenMember = MemberLookupHelper.FindSimilarMember(containingClass, this.member);

                if (overridenMember == null || overridenMember.Region.IsEmpty)
                {
                    return(null);
                }

                return(new ContextActionViewModel {
                    Action = new GoToMemberAction(overridenMember, this.LabelAmbience),
                    Image = ClassBrowserIconService.GetIcon(overridenMember).ImageSource,
                    Comment = string.Format("(in {0})", containingClass.FullyQualifiedName),
                    ChildActions = childActions
                });
            }
        void CreateInterfaceImplementations(IMember currentMember, ParametrizedNode memberDecl, List <InterfaceImplementation> interfaceImplementations)
        {
            if (currentMember != null &&
                (memberDecl.Modifier & Modifiers.Visibility) == Modifiers.None &&
                interfaceImplementations.Count == 1)
            {
                // member is explicitly implementing an interface member
                // to convert explicit interface implementations to VB, make the member private
                // and ensure its name does not collide with another member
                memberDecl.Modifier |= Modifiers.Private;
                memberDecl.Name      = interfaceImplementations[0].InterfaceType.Type.Replace('.', '_') + "_" + memberDecl.Name;
            }

            if (currentMember != null && currentMember.IsPublic &&
                currentMember.DeclaringType.ClassType != ClassType.Interface)
            {
                // member could be implicitly implementing an interface member,
                // search for interfaces containing the member
                foreach (IReturnType directBaseType in currentMember.DeclaringType.GetCompoundClass().BaseTypes)
                {
                    IClass directBaseClass = directBaseType.GetUnderlyingClass();
                    if (directBaseClass != null && directBaseClass.ClassType == ClassType.Interface)
                    {
                        // include members inherited from other interfaces in the search:
                        foreach (IReturnType baseType in MemberLookupHelper.GetTypeInheritanceTree(directBaseType))
                        {
                            IClass baseClass = baseType.GetUnderlyingClass();
                            if (baseClass != null && baseClass.ClassType == ClassType.Interface)
                            {
                                IMember similarMember = MemberLookupHelper.FindSimilarMember(baseClass, currentMember);
                                // add an interface implementation for similarMember
                                // only when similarMember is not explicitly implemented by another member in this class
                                if (similarMember != null && !HasExplicitImplementationFor(similarMember, baseType, memberDecl.Parent))
                                {
                                    interfaceImplementations.Add(new InterfaceImplementation(
                                                                     Refactoring.CodeGenerator.ConvertType(baseType, CreateContext()),
                                                                     currentMember.Name));
                                }
                            }
                        }
                    }
                }
            }
        }