Ejemplo n.º 1
0
        void SetLocationTextData(Gtk.TreeViewColumn tree_column, Gtk.CellRenderer cell, Gtk.TreeModel model, Gtk.TreeIter iter)
        {
            CellRendererText cellRendererText = (CellRendererText)cell;
            Change           change           = store.GetValue(iter, objColumn) as Change;

            cellRendererText.Visible = (bool)store.GetValue(iter, statusVisibleColumn);
            TextReplaceChange replaceChange = change as TextReplaceChange;

            if (replaceChange == null)
            {
                cellRendererText.Text = "";
                return;
            }

            var doc = TextEditorFactory.CreateNewDocument();

            doc.Text = TextFileUtility.ReadAllText(replaceChange.FileName);
            var loc = doc.OffsetToLocation(replaceChange.Offset);

            string text = string.Format(GettextCatalog.GetString("(Line:{0}, Column:{1})"), loc.Line, loc.Column);

            if (treeviewPreview.Selection.IterIsSelected(iter))
            {
                cellRendererText.Text = text;
            }
            else
            {
                var color = Style.Text(StateType.Insensitive);
                var c     = string.Format("#{0:X02}{1:X02}{2:X02}", color.Red / 256, color.Green / 256, color.Blue / 256);
                cellRendererText.Markup = "<span foreground=\"" + c + "\">" + text + "</span>";
            }
        }
Ejemplo n.º 2
0
        public override List<Change> PerformChanges(RefactoringOptions options, object properties)
        {
            List<Change> changes = new List<Change>();
            var resolveResult = options.ResolveResult;
            if (resolveResult == null) throw new InvalidOperationException("Cannot generate class here");
            var resType = resolveResult.ResolvedType;

            var doc = options.Document;
            var editor = doc.Editor;
            var currentDir = doc.FileName.ParentDirectory;
            var nspace = resType.Namespace;
            string typeName = resolveResult.ResolvedExpression.Expression;
            var body = resType.Type.BodyRegion;
            var content = editor.GetTextBetween(body.Start.Line, 1, body.End.Line, body.End.Column);
            var contentLength = content.Length;
            content = fileFormatResolver.GetNewTypeFileContent(content, nspace, editor.EolMarker);
            CreateFileChange createFileChange = new CreateFileChange(@"{0}\{1}.cs".ToFormat(currentDir, typeName), content);
            changes.Add(createFileChange);

            TextReplaceChange textReplaceChange = new TextReplaceChange();
            textReplaceChange.FileName = context.GetCurrentFilePath();
            textReplaceChange.RemovedChars = contentLength + 1;
            int num = editor.Document.LocationToOffset(body.Start.Line, 1);
            textReplaceChange.Offset = num - 1;
            textReplaceChange.InsertedText = string.Empty;
            changes.Add (textReplaceChange);

            return changes;
        }
Ejemplo n.º 3
0
 void FillChanges()
 {
     foreach (Change change in changes)
     {
         TreeIter iter = GetFile(change);
         if (iter.Equals(TreeIter.Zero))
         {
             iter = store.AppendValues(ImageService.GetIcon(MonoDevelop.Ide.Gui.Stock.ReplaceIcon, IconSize.Menu), change.Description, change, true);
         }
         else
         {
             iter = store.AppendValues(iter, ImageService.GetIcon(MonoDevelop.Ide.Gui.Stock.ReplaceIcon, IconSize.Menu), change.Description, change, true);
         }
         TextReplaceChange replaceChange = change as TextReplaceChange;
         if (replaceChange != null && replaceChange.Offset >= 0)
         {
             store.AppendValues(iter, null, null, change, false);
         }
     }
     if (changes.Count < 4)
     {
         treeviewPreview.ExpandAll();
     }
     else
     {
         foreach (TreeIter iter in fileDictionary.Values)
         {
             treeviewPreview.ExpandRow(store.GetPath(iter), false);
         }
     }
 }
Ejemplo n.º 4
0
        void SetDiffCellData(Gtk.TreeViewColumn tree_column, Gtk.CellRenderer cell, Gtk.TreeModel model, Gtk.TreeIter iter)
        {
            try {
                CellRendererDiff cellRendererDiff = (CellRendererDiff)cell;
                Change           change           = store.GetValue(iter, objColumn) as Change;
                cellRendererDiff.Visible = !(bool)store.GetValue(iter, statusVisibleColumn);
                if (change == null || !cellRendererDiff.Visible)
                {
                    cellRendererDiff.InitCell(treeviewPreview, false, "", "");
                    return;
                }
                TextReplaceChange replaceChange = change as TextReplaceChange;
                if (replaceChange == null)
                {
                    return;
                }

                Mono.TextEditor.Document originalDocument = new Mono.TextEditor.Document();
                originalDocument.FileName = replaceChange.FileName;
                originalDocument.Text     = System.IO.File.ReadAllText(replaceChange.FileName);

                Mono.TextEditor.Document changedDocument = new Mono.TextEditor.Document();
                changedDocument.FileName = replaceChange.FileName;
                changedDocument.Text     = originalDocument.Text;

                ((Mono.TextEditor.IBuffer)changedDocument).Replace(replaceChange.Offset, replaceChange.RemovedChars, replaceChange.InsertedText);

                string diffString = Mono.TextEditor.Utils.Diff.GetDiffString(originalDocument, changedDocument);

                cellRendererDiff.InitCell(treeviewPreview, true, diffString, replaceChange.FileName);
            } catch (Exception e) {
                Console.WriteLine(e);
            }
        }
Ejemplo n.º 5
0
        void SetLocationTextData(Gtk.TreeViewColumn tree_column, Gtk.CellRenderer cell, Gtk.TreeModel model, Gtk.TreeIter iter)
        {
            CellRendererText cellRendererText = (CellRendererText)cell;
            Change           change           = store.GetValue(iter, objColumn) as Change;

            cellRendererText.Visible = (bool)store.GetValue(iter, statusVisibleColumn);
            TextReplaceChange replaceChange = change as TextReplaceChange;

            if (replaceChange == null)
            {
                cellRendererText.Text = "";
                return;
            }

            Mono.TextEditor.Document doc = new Mono.TextEditor.Document();
            doc.Text = System.IO.File.ReadAllText(replaceChange.FileName);
            DocumentLocation loc = doc.OffsetToLocation(replaceChange.Offset);

            string text = string.Format(GettextCatalog.GetString("(Line:{0}, Column:{1})"), loc.Line, loc.Column);

            if (treeviewPreview.Selection.IterIsSelected(iter))
            {
                cellRendererText.Text = text;
            }
            else
            {
                cellRendererText.Markup = "<span foreground=\"" + MonoDevelop.Components.PangoCairoHelper.GetColorString(Style.Text(StateType.Insensitive)) + "\">" + text + "</span>";
            }
        }
    TreeIter GetFile (Change change)
    {
        TextReplaceChange replaceChange = change as TextReplaceChange;
        if (replaceChange == null)
            return TreeIter.Zero;

        TreeIter result;
        if (!fileDictionary.TryGetValue (replaceChange.FileName, out result))
            fileDictionary[replaceChange.FileName] = result = store.AppendValues (DesktopService.GetPixbufForFile (replaceChange.FileName, IconSize.Menu), System.IO.Path.GetFileName (replaceChange.FileName), null, true);
        return result;
    }
Ejemplo n.º 7
0
		public static TextReplaceChange GetRemoveNodeChange (this TextEditorData editor, AstNode n)
		{
			var change = new TextReplaceChange ();
			change.FileName = editor.FileName;
			change.Offset = editor.LocationToOffset (n.StartLocation);
			change.RemovedChars = editor.LocationToOffset (n.EndLocation) - change.Offset;
			
			// remove EOL, when line is empty
			var line = editor.GetLineByOffset (change.Offset);
			if (line != null && line.Length == change.RemovedChars)
				change.RemovedChars += line.DelimiterLength;
			return change;
		}
 public void FileRename(object sender, FileCopyEventArgs args)
 {
     foreach (Change change in changes)
     {
         TextReplaceChange replaceChange = change as TextReplaceChange;
         if (replaceChange == null)
         {
             continue;
         }
         if (args.SourceFile == replaceChange.FileName)
         {
             replaceChange.FileName = args.TargetFile;
         }
     }
 }
Ejemplo n.º 9
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();
        }
Ejemplo n.º 10
0
        TreeIter GetFile(Change change)
        {
            TextReplaceChange replaceChange = change as TextReplaceChange;

            if (replaceChange == null)
            {
                return(TreeIter.Zero);
            }

            TreeIter result;

            if (!fileDictionary.TryGetValue(replaceChange.FileName, out result))
            {
                fileDictionary[replaceChange.FileName] = result = store.AppendValues(IdeServices.DesktopService.GetIconForFile(replaceChange.FileName, IconSize.Menu), System.IO.Path.GetFileName(replaceChange.FileName), null, true);
            }
            return(result);
        }
Ejemplo n.º 11
0
        void SetDiffCellData(Gtk.TreeViewColumn tree_column, Gtk.CellRenderer cell, Gtk.TreeModel model, Gtk.TreeIter iter)
        {
            try {
                CellRendererDiff cellRendererDiff = (CellRendererDiff)cell;
                Change           change           = store.GetValue(iter, objColumn) as Change;
                cellRendererDiff.Visible = !(bool)store.GetValue(iter, statusVisibleColumn);
                if (change == null || !cellRendererDiff.Visible)
                {
                    cellRendererDiff.InitCell(treeviewPreview, false, "", "");
                    return;
                }
                TextReplaceChange replaceChange = change as TextReplaceChange;
                if (replaceChange == null)
                {
                    return;
                }

                var openDocument     = IdeApp.Workbench.GetDocument(replaceChange.FileName);
                var originalDocument = TextEditorFactory.CreateNewDocument();
                originalDocument.FileName = replaceChange.FileName;
                if (openDocument == null)
                {
                    originalDocument.Text = TextFileUtility.ReadAllText(replaceChange.FileName);
                }
                else
                {
                    originalDocument.Text = openDocument.Editor.Text;
                }

                var changedDocument = TextEditorFactory.CreateNewDocument();
                changedDocument.FileName = replaceChange.FileName;
                changedDocument.Text     = originalDocument.Text;

                changedDocument.ReplaceText(replaceChange.Offset, replaceChange.RemovedChars, replaceChange.InsertedText);

                string diffString = originalDocument.GetDiffAsString(changedDocument);

                cellRendererDiff.InitCell(treeviewPreview, true, diffString, replaceChange.FileName);
            } catch (Exception e) {
                Console.WriteLine(e);
            }
        }
        void SetDiffCellData(Gtk.TreeViewColumn tree_column, Gtk.CellRenderer cell, Gtk.TreeModel model, Gtk.TreeIter iter)
        {
            try {
                CellRendererDiff cellRendererDiff = (CellRendererDiff)cell;
                Change           change           = store.GetValue(iter, objColumn) as Change;
                cellRendererDiff.Visible = !(bool)store.GetValue(iter, statusVisibleColumn);
                if (change == null || !cellRendererDiff.Visible)
                {
                    cellRendererDiff.InitCell(treeviewPreview, false, "", "");
                    return;
                }
                TextReplaceChange replaceChange = change as TextReplaceChange;
                if (replaceChange == null)
                {
                    return;
                }

                Mono.TextEditor.Document doc = new Mono.TextEditor.Document();
                doc.Text = System.IO.File.ReadAllText(replaceChange.FileName);
                List <string> before = new List <string> ();
                foreach (var line in doc.Lines)
                {
                    before.Add(doc.GetTextAt(line.Offset, line.EditableLength));
                }

                ((Mono.TextEditor.IBuffer)doc).Replace(replaceChange.Offset, replaceChange.RemovedChars, replaceChange.InsertedText);

                List <string> after = new List <string> ();
                foreach (var line in doc.Lines)
                {
                    after.Add(doc.GetTextAt(line.Offset, line.EditableLength));
                }

                Diff diff = new Diff(before.ToArray(), after.ToArray(), true, true);

                System.IO.StringWriter w = new System.IO.StringWriter();
                UnifiedDiff.WriteUnifiedDiff(diff, w, replaceChange.FileName, replaceChange.FileName, 2);
                cellRendererDiff.InitCell(treeviewPreview, true, w.ToString().Trim(), replaceChange.FileName);
            } catch (Exception e) {
                Console.WriteLine(e);
            }
        }
        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.º 14
0
 public override List<Change> PerformChanges(RefactoringOptions options, object prop)
 {
     string newName = (string) prop;
     List<Change> changes = new List<Change>();
     using (var dialogProgressMonitor = new MessageDialogProgressMonitor(true, false, false, true)) {
         var references = finder.FindReferences((NamespaceResolveResult)options.ResolveResult, dialogProgressMonitor);
         if (references == null)
           return changes;
         foreach (MemberReference memberReference in references)
         {
             TextReplaceChange textReplaceChange = new TextReplaceChange();
             textReplaceChange.FileName = (string) memberReference.FileName;
             textReplaceChange.Offset = memberReference.Position;
             textReplaceChange.RemovedChars = memberReference.Name.Length;
             textReplaceChange.InsertedText = newName;
             textReplaceChange.Description = string.Format(GettextCatalog.GetString("Replace '{0}' with '{1}'"), (object) memberReference.Name, (object) newName);
             changes.Add((Change) textReplaceChange);
         }
     }
     return changes;
 }
Ejemplo n.º 15
0
        public override List<Change> PerformChanges(RefactoringOptions options, object properties)
        {
            List<Change> changes = new List<Change>();
            var textReplaceChange = new TextReplaceChange();
            textReplaceChange.FileName = context.GetCurrentFilePath();
            textReplaceChange.RemovedChars = 0;
            int num = data.Document.LocationToOffset(insertionPoint.Location);
            textReplaceChange.Offset = num;

            var resolveResult = context.GetResolvedTypeNameResult ();
            if (resolveResult == null) throw new InvalidOperationException("Cannot generate class here");
            var nspace = resolveResult.CallingType.Namespace;
            string newTypeName = resolveResult.ResolvedExpression.Expression;
            StringBuilder contentBuilder = new StringBuilder();
            if (insertionPoint.LineBefore == NewLineInsertion.Eol) contentBuilder.Append(data.EolMarker);
            contentBuilder.Append(data.EolMarker);
            contentBuilder.Append(data.EolMarker);
            var content = fileFormatResolver.GetNewTypeContent(newTypeName, indent, data.EolMarker);
            contentBuilder.Append(content);
            if (insertionPoint.LineAfter == NewLineInsertion.None) contentBuilder.Append(data.EolMarker);
            textReplaceChange.InsertedText = contentBuilder.ToString();

            changes.Add(textReplaceChange);
            return changes;
        }
Ejemplo n.º 16
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();
            }
        }
		public override List<Change> PerformChanges (RefactoringOptions options, object prop)
		{
			List<Change> result = new List<Change> ();
			TextReplaceChange insertNewMethod = new TextReplaceChange ();
			insertNewMethod.FileName = fileName;
			insertNewMethod.RemovedChars = insertionPoint.LineBefore == NewLineInsertion.Eol ? 0 : insertionPoint.Location.Column;
			var data = options.GetTextEditorData ();
			int insertionOffset = data.Document.LocationToOffset (insertionPoint.Location);
			insertNewMethod.Offset = insertionOffset - insertNewMethod.RemovedChars;
			
			StringBuilder sb = new StringBuilder ();
			sb.AppendLine ();
			switch (insertionPoint.LineBefore) {
			case NewLineInsertion.Eol:
				sb.AppendLine ();
				break;
			case NewLineInsertion.BlankLine:
				sb.AppendLine ();
				sb.Append (indent);
				sb.AppendLine ();
				break;
			}

			var generator = options.Document.CreateCodeGenerator ();
			sb.Append (generator.CreateMemberImplementation (declaringType, ConstructMethod (options), false).Code);
			
			switch (insertionPoint.LineAfter) {
			case NewLineInsertion.Eol:
				sb.AppendLine ();
				break;
			case NewLineInsertion.BlankLine:
				sb.AppendLine ();
				sb.AppendLine ();
				sb.Append (indent);
				break;
			}
			
			insertNewMethod.InsertedText = sb.ToString ();
			result.Add (insertNewMethod);
			selectionStart = selectionEnd = insertNewMethod.Offset;
			int idx = insertNewMethod.InsertedText.IndexOf ("throw");
			if (idx >= 0) {
				selectionStart = insertNewMethod.Offset + idx;
				selectionEnd   = insertNewMethod.Offset + insertNewMethod.InsertedText.IndexOf (';', idx) + 1;
			} else {
				selectionStart = selectionEnd = insertNewMethod.Offset;
			}
			return result;
		}
		public override List<Change> PerformChanges (RefactoringOptions options, object prop)
		{
			List<Change> result = new List<Change> ();
			ExtractMethodParameters param = (ExtractMethodParameters)prop;
			var data = options.GetTextEditorData ();
		//	IResolver resolver = options.GetResolver ();
			
			TextReplaceChange replacement = new TextReplaceChange ();
			replacement.Description = string.Format (GettextCatalog.GetString ("Substitute selected statement(s) with call to {0}"), param.Name);
			replacement.FileName = options.Document.FileName;
			replacement.Offset = param.StartOffset;
			replacement.RemovedChars = param.EndOffset - param.StartOffset;
			replacement.MoveCaretToReplace = true;
			replacement.InsertedText = GenerateMethodCall (options, param);
			result.Add (replacement);
			
			TextReplaceChange insertNewMethod = new TextReplaceChange ();
			insertNewMethod.FileName = options.Document.FileName;
			insertNewMethod.Description = string.Format (GettextCatalog.GetString ("Create new method {0} from selected statement(s)"), param.Name);
			var insertionPoint = param.InsertionPoint;
			if (insertionPoint == null) {
				var points = CodeGenerationService.GetInsertionPoints (options.Document, param.DeclaringMember.DeclaringType);
				insertionPoint = points.LastOrDefault (p => p.Location.Line < param.DeclaringMember.Location.Line);
				if (insertionPoint == null)
					insertionPoint = points.FirstOrDefault ();
			}
			
			insertNewMethod.RemovedChars = 0; //insertionPoint.LineBefore == NewLineInsertion.Eol ? 0 : insertionPoint.Location.Column - 1;
			insertNewMethod.Offset = data.Document.LocationToOffset (insertionPoint.Location) - insertNewMethod.RemovedChars;
			insertNewMethod.InsertedText = GenerateMethodDeclaration (options, param);
			result.Add (insertNewMethod);
			/*
			
			ExtractMethodAstTransformer transformer = new ExtractMethodAstTransformer (param.VariablesToGenerate);
			node.AcceptVisitor (transformer, null);
			if (!param.OneChangedVariable && node is Expression) {
				ResolveResult resolveResult = resolver.Resolve (new ExpressionResult ("(" + provider.OutputNode (options.Dom, node) + ")"), new DomLocation (options.Document.Editor.Caret.Line, options.Document.Editor.Caret.Column));
				if (resolveResult.ResolvedType != null)
					returnType = options.ShortenTypeName (resolveResult.ResolvedType).ConvertToTypeReference ();
			}
			
			MethodDeclaration methodDecl = new MethodDeclaration ();
			methodDecl.Name = param.Name;
			methodDecl.Modifier = param.Modifiers;
			methodDecl.TypeReference = returnType;
			
			
			if (node is BlockStatement) {
				methodDecl.Body = new BlockStatement ();
				methodDecl.Body.AddChild (new EmptyStatement ());
				if (param.OneChangedVariable)
					methodDecl.Body.AddChild (new ReturnStatement (new IdentifierExpression (param.ChangedVariables.First ())));
			} else if (node is Expression) {
				methodDecl.Body = new BlockStatement ();
				methodDecl.Body.AddChild (new ReturnStatement (node as Expression));
			}
			
			foreach (VariableDescriptor var in param.VariablesToDefine) {
				BlockStatement block = methodDecl.Body;
				LocalVariableDeclaration varDecl = new LocalVariableDeclaration (options.ShortenTypeName (var.ReturnType).ConvertToTypeReference ());
				varDecl.Variables.Add (new VariableDeclaration (var.Name));
				block.Children.Insert (0, varDecl);
			}
			
			
			
			string indent = options.GetIndent (param.DeclaringMember);
			StringBuilder methodText = new StringBuilder ();
			switch (param.InsertionPoint.LineBefore) {
			case NewLineInsertion.Eol:
				methodText.AppendLine ();
				break;
			case NewLineInsertion.BlankLine:
				methodText.Append (indent);
				methodText.AppendLine ();
				break;
			}
			if (param.GenerateComment) {
				methodText.Append (indent);
				methodText.AppendLine ("/// <summary>");
				methodText.Append (indent);
				methodText.AppendLine ("/// TODO: write a comment.");
				methodText.Append (indent);
				methodText.AppendLine ("/// </summary>");
				Ambience ambience = AmbienceService.GetAmbienceForFile (options.Document.FileName);
				foreach (ParameterDeclarationExpression pde in methodDecl.Parameters) {
					methodText.Append (indent);
					methodText.Append ("/// <param name=\"");
					methodText.Append (pde.ParameterName);
					methodText.Append ("\"> A ");
					methodText.Append (ambience.GetString (pde.TypeReference.ConvertToReturnType (), OutputFlags.IncludeGenerics | OutputFlags.UseFullName));
					methodText.Append (" </param>");
					methodText.AppendLine ();
				}
				if (methodDecl.TypeReference.Type != "System.Void") {
					methodText.Append (indent);
					methodText.AppendLine ("/// <returns>");
					methodText.Append (indent);
					methodText.Append ("/// A ");
					methodText.AppendLine (ambience.GetString (methodDecl.TypeReference.ConvertToReturnType (), OutputFlags.IncludeGenerics | OutputFlags.UseFullName));
					methodText.Append (indent);
					methodText.AppendLine ("/// </returns>");
				}
			}
			
			methodText.Append (indent);
			
			if (node is BlockStatement) {
				string text = provider.OutputNode (options.Dom, methodDecl, indent).Trim ();
				int emptyStatementMarker = text.LastIndexOf (';');
				if (param.OneChangedVariable)
					emptyStatementMarker = text.LastIndexOf (';', emptyStatementMarker - 1);
				StringBuilder sb = new StringBuilder ();
				sb.Append (text.Substring (0, emptyStatementMarker));
				sb.Append (AddIndent (param.Text, indent + "\t"));
				sb.Append (text.Substring (emptyStatementMarker + 1));
				
				methodText.Append (sb.ToString ());
			} else {
				methodText.Append (provider.OutputNode (options.Dom, methodDecl, options.GetIndent (param.DeclaringMember)).Trim ());
			}
			
			 */
			return result;
		}