public static void RenameClass(IClass c, string newName) { c = c.GetCompoundClass(); // get compound class if class is partial List <Reference> list = RefactoringService.FindReferences(c, null); if (list == null) { return; } // Add the class declaration(s) foreach (IClass part in GetClassParts(c)) { AddDeclarationAsReference(list, part.CompilationUnit.FileName, part.Region, part.Name); } // Add the constructors foreach (IMethod m in c.Methods) { if (m.IsConstructor) { AddDeclarationAsReference(list, m.DeclaringType.CompilationUnit.FileName, m.Region, c.Name); } } FindReferencesAndRenameHelper.RenameReferences(list, newName); }
public static void RunFindReferences(LocalResolveResult local) { FindReferencesAndRenameHelper.ShowAsSearchResults( StringParser.Parse("${res:SharpDevelop.Refactoring.ReferencesTo}", new StringTagPair("Name", local.VariableName)), RefactoringService.FindReferences(local, null) ); }
public static void RunFindReferences(IClass c) { using (AsynchronousWaitDialog monitor = AsynchronousWaitDialog.ShowWaitDialog("${res:SharpDevelop.Refactoring.FindReferences}", true)) { FindReferencesAndRenameHelper.ShowAsSearchResults( StringParser.Parse("${res:SharpDevelop.Refactoring.ReferencesTo}", new StringTagPair("Name", c.Name)), RefactoringService.FindReferences(c, monitor) ); } }
public static void RunFindReferences(IMember member) { string memberName = member.DeclaringType.Name + "." + member.Name; using (AsynchronousWaitDialog monitor = AsynchronousWaitDialog.ShowWaitDialog("${res:SharpDevelop.Refactoring.FindReferences}", true)) { FindReferencesAndRenameHelper.ShowAsSearchResults( StringParser.Parse("${res:SharpDevelop.Refactoring.ReferencesTo}", new StringTagPair("Name", memberName)), RefactoringService.FindReferences(member, monitor)); } }
public override void Run() { LocalResolveResult local = (LocalResolveResult)Owner; FindReferencesAndRenameHelper.ShowAsSearchResults( StringParser.Parse("${res:SharpDevelop.Refactoring.ReferencesTo}", new string[, ] { { "Name", local.Field.Name } }), RefactoringService.FindReferences(local, null) ); }
public override void Run() { RefactoringMenuContext context = (RefactoringMenuContext)Owner; LocalResolveResult local = (LocalResolveResult)context.ResolveResult; FindReferencesAndRenameHelper.ShowAsSearchResults( StringParser.Parse("${res:SharpDevelop.Refactoring.ReferencesTo}", new string[, ] { { "Name", local.VariableName } }), RefactoringService.FindReferences(local, null) ); }
public static ContextActionsPopup MakePopupWithDerivedClasses(IClass baseClass) { var derivedClassesTree = RefactoringService.FindDerivedClassesTree(baseClass); var popupViewModel = new ContextActionsViewModel { Title = MenuService.ConvertLabel(StringParser.Parse( "${res:SharpDevelop.Refactoring.ClassesDerivingFrom}", new StringTagPair("Name", baseClass.Name))) }; popupViewModel.Actions = new PopupTreeViewModelBuilder().BuildTreeViewModel(derivedClassesTree); return(new ContextActionsPopup { Actions = popupViewModel, Symbol = baseClass }); }
public static ContextActionsPopup MakePopupWithOverrides(IMember member) { var derivedClassesTree = RefactoringService.FindDerivedClassesTree(member.DeclaringType); var popupViewModel = new ContextActionsViewModel { Title = MenuService.ConvertLabel(StringParser.Parse( "${res:SharpDevelop.Refactoring.OverridesOf}", new string[, ] { { "Name", member.FullyQualifiedName } })) }; popupViewModel.Actions = new OverridesPopupTreeViewModelBuilder(member).BuildTreeViewModel(derivedClassesTree); return(new ContextActionsPopup { Actions = popupViewModel, Symbol = member }); }
public static void Run(LocalResolveResult local) { string newName = MessageService.ShowInputBox("${res:SharpDevelop.Refactoring.Rename}", "${res:SharpDevelop.Refactoring.RenameMemberText}", local.VariableName); if (!FindReferencesAndRenameHelper.CheckName(newName, local.VariableName)) { return; } List <Reference> list = RefactoringService.FindReferences(local, null); if (list == null) { return; } FindReferencesAndRenameHelper.RenameReferences(list, newName); }
public override void Run() { LocalResolveResult local = (LocalResolveResult)Owner; string newName = MessageService.ShowInputBox("${res:SharpDevelop.Refactoring.Rename}", "${res:SharpDevelop.Refactoring.RenameMemberText}", local.Field.Name); if (!FindReferencesAndRenameHelper.CheckName(newName, local.Field.Name)) { return; } List <Reference> list = RefactoringService.FindReferences(local, null); if (list == null) { return; } FindReferencesAndRenameHelper.RenameReferences(list, newName); }
public static bool RenameMember(IMember member, string newName) { List <Reference> list; using (AsynchronousWaitDialog monitor = AsynchronousWaitDialog.ShowWaitDialog("${res:SharpDevelop.Refactoring.Rename}")) { list = RefactoringService.FindReferences(member, monitor); if (list == null) { return(false); } FindReferencesAndRenameHelper.RenameReferences(list, newName); } if (member is IField) { IProperty property = FindProperty((IField)member); if (property != null) { string newPropertyName = member.DeclaringType.ProjectContent.Language.CodeGenerator.GetPropertyName(newName); if (newPropertyName != newName && newPropertyName != property.Name) { if (MessageService.AskQuestionFormatted("${res:SharpDevelop.Refactoring.Rename}", "${res:SharpDevelop.Refactoring.RenameFieldAndProperty}", property.FullyQualifiedName, newPropertyName)) { using (AsynchronousWaitDialog monitor = AsynchronousWaitDialog.ShowWaitDialog("${res:SharpDevelop.Refactoring.Rename}")) { list = RefactoringService.FindReferences(property, monitor); if (list != null) { FindReferencesAndRenameHelper.RenameReferences(list, newPropertyName); } } } } } } return(true); }
public ToolStripItem[] BuildSubmenu(Codon codon, object owner) { ToolStripMenuItem item; TextEditorControl textEditorControl = (TextEditorControl)owner; if (textEditorControl.FileName == null) { return(new ToolStripItem[0]); } List <ToolStripItem> resultItems = new List <ToolStripItem>(); TextArea textArea = textEditorControl.ActiveTextAreaControl.TextArea; IDocument doc = textArea.Document; int caretLine = textArea.Caret.Line; // list of dotnet names that have definition bookmarks in this line List <string> definitions = new List <string>(); // Include definitions (use the bookmarks which should already be present) foreach (Bookmark mark in doc.BookmarkManager.Marks) { if (mark != null && mark.LineNumber == caretLine) { ClassMemberBookmark cmb = mark as ClassMemberBookmark; ClassBookmark cb = mark as ClassBookmark; IClass type = null; if (cmb != null) { definitions.Add(cmb.Member.DotNetName); item = new ToolStripMenuItem(MemberNode.GetText(cmb.Member), ClassBrowserIconService.ImageList.Images[cmb.IconIndex]); MenuService.AddItemsToMenu(item.DropDown.Items, mark, ClassMemberBookmark.ContextMenuPath); resultItems.Add(item); type = cmb.Member.DeclaringType; } else if (cb != null) { type = cb.Class; } if (type != null) { definitions.Add(type.DotNetName); item = new ToolStripMenuItem(type.Name, ClassBrowserIconService.ImageList.Images[ClassBrowserIconService.GetIcon(type)]); MenuService.AddItemsToMenu(item.DropDown.Items, cb ?? new ClassBookmark(textArea.Document, type), ClassBookmark.ContextMenuPath); resultItems.Add(item); } } } // Include menu for member that has been clicked on IExpressionFinder expressionFinder = ParserService.GetExpressionFinder(textEditorControl.FileName); ExpressionResult expressionResult; ResolveResult rr; int insertIndex = resultItems.Count; // Insert items at this position to get the outermost expression first, followed by the inner expressions (if any). expressionResult = FindFullExpressionAtCaret(textArea, expressionFinder); repeatResolve: rr = ResolveExpressionAtCaret(textArea, expressionResult); item = null; if (rr is MethodResolveResult) { item = MakeItem(definitions, ((MethodResolveResult)rr).GetMethodIfSingleOverload()); } else if (rr is MemberResolveResult) { MemberResolveResult mrr = (MemberResolveResult)rr; item = MakeItem(definitions, mrr.ResolvedMember); if (RefactoringService.FixIndexerExpression(expressionFinder, ref expressionResult, mrr)) { if (item != null) { resultItems.Insert(insertIndex, item); } // Include menu for the underlying expression of the // indexer expression as well. goto repeatResolve; } } else if (rr is TypeResolveResult) { item = MakeItem(definitions, ((TypeResolveResult)rr).ResolvedClass); } else if (rr is LocalResolveResult) { item = MakeItem((LocalResolveResult)rr, caretLine + 1 == ((LocalResolveResult)rr).Field.Region.BeginLine); insertIndex = 0; // Insert local variable menu item at the topmost position. } if (item != null) { resultItems.Insert(insertIndex, item); } // Include menu for current class and method IMember callingMember = null; if (rr != null) { callingMember = rr.CallingMember; } else { ParseInformation parseInfo = ParserService.GetParseInformation(textEditorControl.FileName); if (parseInfo != null) { ICompilationUnit cu = parseInfo.MostRecentCompilationUnit; if (cu != null) { IClass callingClass = cu.GetInnermostClass(caretLine + 1, textArea.Caret.Column + 1); callingMember = GetCallingMember(callingClass, caretLine + 1, textArea.Caret.Column + 1); } } } if (callingMember != null) { item = MakeItem(definitions, callingMember); if (item != null) { item.Text = StringParser.Parse("${res:SharpDevelop.Refactoring.CurrentMethod}: ") + callingMember.Name; resultItems.Add(item); } } if (resultItems.Count == 0) { return(new ToolStripItem[0]); } else { resultItems.Add(new MenuSeparator()); return(resultItems.ToArray()); } }