FinishRefactoringOperation() public static method

public static FinishRefactoringOperation ( ) : void
return void
Ejemplo n.º 1
0
        public static void AcceptChanges(IProgressMonitor monitor, List <Change> changes, MonoDevelop.Projects.Text.ITextFileProvider fileProvider)
        {
            var rctx    = new RefactoringOptions(null);
            var handler = new RenameHandler(changes);

            FileService.FileRenamed += handler.FileRename;
            var fileNames = new HashSet <FilePath> ();

            for (int i = 0; i < changes.Count; i++)
            {
                changes[i].PerformChange(monitor, rctx);
                var replaceChange = changes[i] as TextReplaceChange;
                if (replaceChange == null)
                {
                    continue;
                }
                for (int j = i + 1; j < changes.Count; j++)
                {
                    var change = changes[j] as TextReplaceChange;
                    if (change == null)
                    {
                        continue;
                    }
                    fileNames.Add(change.FileName);
                    if (replaceChange.Offset >= 0 && change.Offset >= 0 && replaceChange.FileName == change.FileName)
                    {
                        if (replaceChange.Offset < change.Offset)
                        {
                            change.Offset -= replaceChange.RemovedChars;
                            if (!string.IsNullOrEmpty(replaceChange.InsertedText))
                            {
                                change.Offset += replaceChange.InsertedText.Length;
                            }
                        }
                        else if (replaceChange.Offset < change.Offset + change.RemovedChars)
                        {
                            change.RemovedChars = Math.Max(0, change.RemovedChars - replaceChange.RemovedChars);
                            change.Offset       = replaceChange.Offset + (!string.IsNullOrEmpty(replaceChange.InsertedText) ? replaceChange.InsertedText.Length : 0);
                        }
                    }
                }
            }
            FileService.NotifyFilesChanged(fileNames);
            FileService.FileRenamed -= handler.FileRename;
            TextReplaceChange.FinishRefactoringOperation();
        }
        public static void AcceptChanges(IProgressMonitor monitor, ProjectDom dom, List <Change> changes, MonoDevelop.Projects.Text.ITextFileProvider fileProvider)
        {
            RefactorerContext rctx    = new RefactorerContext(dom, fileProvider, null);
            RenameHandler     handler = new RenameHandler(changes);

            FileService.FileRenamed += handler.FileRename;
            for (int i = 0; i < changes.Count; i++)
            {
                changes[i].PerformChange(monitor, rctx);
                TextReplaceChange replaceChange = changes[i] as TextReplaceChange;
                if (replaceChange == null)
                {
                    continue;
                }
                for (int j = i + 1; j < changes.Count; j++)
                {
                    TextReplaceChange change = changes[j] as TextReplaceChange;
                    if (change == null)
                    {
                        continue;
                    }
                    if (replaceChange.Offset >= 0 && change.Offset >= 0 && replaceChange.FileName == change.FileName)
                    {
                        if (replaceChange.Offset < change.Offset)
                        {
                            change.Offset -= replaceChange.RemovedChars;
                            if (!string.IsNullOrEmpty(replaceChange.InsertedText))
                            {
                                change.Offset += replaceChange.InsertedText.Length;
                            }
                        }
                        else if (replaceChange.Offset < change.Offset + change.RemovedChars)
                        {
                            change.RemovedChars -= replaceChange.RemovedChars;
                            change.Offset        = replaceChange.Offset + replaceChange.InsertedText.Length;
                        }
                    }
                }
            }
            FileService.FileRenamed -= handler.FileRename;
            TextReplaceChange.FinishRefactoringOperation();
        }
Ejemplo n.º 3
0
        public static void AcceptChanges(ProgressMonitor monitor, IList <Change> changes, MonoDevelop.Ide.ITextFileProvider fileProvider)
        {
            var rctx    = new RefactoringOptions(null, null);
            var handler = new RenameHandler(changes);

            FileService.FileRenamed += handler.FileRename;
            var    fileNames = new HashSet <FilePath> ();
            var    ws        = TypeSystemService.Workspace as MonoDevelopWorkspace;
            string originalName;
            int    originalOffset;

            try {
                for (int i = 0; i < changes.Count; i++)
                {
                    var change = changes [i] as TextReplaceChange;
                    if (change == null)
                    {
                        continue;
                    }

                    if (ws.TryGetOriginalFileFromProjection(change.FileName, change.Offset, out originalName, out originalOffset))
                    {
                        fileNames.Add(change.FileName);
                        change.FileName = originalName;
                        change.Offset   = originalOffset;
                    }
                }
                if (changes.All(x => x is TextReplaceChange))
                {
                    List <Change> newChanges = new List <Change> (changes);
                    newChanges.Sort((Change x, Change y) => ((TextReplaceChange)x).Offset.CompareTo(((TextReplaceChange)y).Offset));
                    changes = newChanges;
                }


                for (int i = 0; i < changes.Count; i++)
                {
                    changes [i].PerformChange(monitor, rctx);
                    var replaceChange = changes [i] as TextReplaceChange;
                    if (replaceChange == null)
                    {
                        continue;
                    }

                    for (int j = i + 1; j < changes.Count; j++)
                    {
                        var change = changes [j] as TextReplaceChange;
                        if (change == null)
                        {
                            continue;
                        }

                        fileNames.Add(change.FileName);

                        if (replaceChange.Offset >= 0 && change.Offset >= 0 && replaceChange.FileName == change.FileName)
                        {
                            if (replaceChange.Offset < change.Offset)
                            {
                                change.Offset -= replaceChange.RemovedChars;
                                if (!string.IsNullOrEmpty(replaceChange.InsertedText))
                                {
                                    change.Offset += replaceChange.InsertedText.Length;
                                }
                            }
                            else if (replaceChange.Offset < change.Offset + change.RemovedChars)
                            {
                                change.RemovedChars = Math.Max(0, change.RemovedChars - replaceChange.RemovedChars);
                                change.Offset       = replaceChange.Offset + (!string.IsNullOrEmpty(replaceChange.InsertedText) ? replaceChange.InsertedText.Length : 0);
                            }
                        }
                    }
                }

                foreach (var renameChange in changes.OfType <RenameFileChange> ())
                {
                    if (fileNames.Contains(renameChange.OldName))
                    {
                        fileNames.Remove(renameChange.OldName);
                        fileNames.Add(renameChange.NewName);
                    }
                }

                foreach (var doc in IdeApp.Workbench.Documents)
                {
                    fileNames.Remove(doc.FileName);
                }
            } catch (Exception e) {
                LoggingService.LogError("Error while applying refactoring changes", e);
            } finally {
                FileService.NotifyFilesChanged(fileNames);
                FileService.FileRenamed -= handler.FileRename;
                TextReplaceChange.FinishRefactoringOperation();
            }
        }