コード例 #1
0
ファイル: Change.cs プロジェクト: highattack30/monodevelop-1
        public override void PerformChange(IProgressMonitor monitor, RefactorerContext rctx)
        {
            if (rctx == null)
            {
                throw new InvalidOperationException("Refactory context not available.");
            }

            TextEditorData textEditorData = this.TextEditorData;

            if (textEditorData == null)
            {
                IEditableTextFile file = rctx.GetFile(FileName);
                if (file != null)
                {
                    if (RemovedChars > 0)
                    {
                        file.DeleteText(Offset, RemovedChars);
                    }
                    if (!string.IsNullOrEmpty(InsertedText))
                    {
                        file.InsertText(Offset, InsertedText);
                    }
                    rctx.Save();
                }
            }
            else if (textEditorData != null)
            {
                int charsInserted = textEditorData.Replace(Offset, RemovedChars, InsertedText);
                if (MoveCaretToReplace)
                {
                    textEditorData.Caret.Offset = Offset + charsInserted;
                }
            }
        }
コード例 #2
0
        public override IClass RenameClass(RefactorerContext ctx, IClass cls, string newName)
        {
            IEditableTextFile file = ctx.GetFile(cls.Region.FileName);

            if (file == null)
            {
                return(null);
            }

            int    pos1 = file.GetPositionFromLineColumn(cls.Region.BeginLine, cls.Region.BeginColumn);
            int    pos2 = file.GetPositionFromLineColumn(cls.Region.EndLine, cls.Region.EndColumn);
            string txt  = file.GetText(pos1, pos2);

            Regex targetExp = new Regex(@"\sclass\s*(" + cls.Name + @")\s", RegexOptions.Multiline);
            Match match     = targetExp.Match(" " + txt + " ");

            if (!match.Success)
            {
                return(null);
            }

            int pos = pos1 + match.Groups [1].Index - 1;

            file.DeleteText(pos, cls.Name.Length);
            file.InsertText(pos, newName);

            return(GetGeneratedClass(ctx, file, cls));
        }
コード例 #3
0
        public virtual void Rename(string newName)
        {
            if (rctx == null)
            {
                throw new InvalidOperationException("Refactory context not available.");
            }

            IEditableTextFile file = rctx.GetFile(fileName);

            if (file != null)
            {
                Console.WriteLine("Replacing text \"{0}\" with \"{1}\" @ {2},{3}", name, newName, line, column);
                file.DeleteText(position, name.Length);
                file.InsertText(position, newName);
                rctx.Save();
            }
        }