From 61a20439ea0e499fc7632fe242f130ffe13ae1a6 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Sat, 17 Jan 2009 19:37:56 +0000 Subject: [PATCH] fixed bugs in Extract Method git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/3.0@3755 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61 --- .../Misc/SharpRefactoring/Src/CSharpMethodExtractor.cs | 1 - .../Misc/SharpRefactoring/Src/ExtractMethodCommand.cs | 6 +++--- .../Misc/SharpRefactoring/Src/Forms/ExtractMethodForm.cs | 9 +++++++-- .../Misc/SharpRefactoring/Src/MethodExtractorBase.cs | 4 ++-- 4 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/AddIns/Misc/SharpRefactoring/Src/CSharpMethodExtractor.cs b/src/AddIns/Misc/SharpRefactoring/Src/CSharpMethodExtractor.cs index 1eeba16840..29bbfa361c 100644 --- a/src/AddIns/Misc/SharpRefactoring/Src/CSharpMethodExtractor.cs +++ b/src/AddIns/Misc/SharpRefactoring/Src/CSharpMethodExtractor.cs @@ -125,7 +125,6 @@ namespace SharpRefactoring otherReturnValues.Add(new VariableDeclaration(variable.Name, variable.Initializer, variable.TypeRef)); } - FindReferenceVisitor frv = new FindReferenceVisitor(true, variable.Name, start, end); parentNode.AcceptVisitor(frv, null); diff --git a/src/AddIns/Misc/SharpRefactoring/Src/ExtractMethodCommand.cs b/src/AddIns/Misc/SharpRefactoring/Src/ExtractMethodCommand.cs index e640723683..e1fe90c703 100644 --- a/src/AddIns/Misc/SharpRefactoring/Src/ExtractMethodCommand.cs +++ b/src/AddIns/Misc/SharpRefactoring/Src/ExtractMethodCommand.cs @@ -5,7 +5,6 @@ // $Revision$ // -using ICSharpCode.TextEditor; using System; using System.Collections.Generic; using System.IO; @@ -20,6 +19,7 @@ using ICSharpCode.SharpDevelop.Dom; using ICSharpCode.SharpDevelop.Gui; using ICSharpCode.SharpDevelop.Project; using ICSharpCode.SharpDevelop.Refactoring; +using ICSharpCode.TextEditor; using ICSharpCode.TextEditor.Document; using SharpRefactoring.Forms; using SharpRefactoring.Transformers; @@ -54,11 +54,11 @@ namespace SharpRefactoring MethodExtractorBase GetCurrentExtractor(TextEditorControl editor) { - switch (ProjectService.CurrentProject.Language) { + switch (LanguageBindingService.GetCodonPerCodeFileName(editor.FileName).Language) { case "C#": return new CSharpMethodExtractor(editor, editor.ActiveTextAreaControl.SelectionManager.SelectionCollection[0]); default: - MessageService.ShowError(string.Format(StringParser.Parse("${res:AddIns.SharpRefactoring.ExtractMethodNotSupported}"), ProjectService.CurrentProject.Language)); + MessageService.ShowError(string.Format(StringParser.Parse("${res:AddIns.SharpRefactoring.ExtractMethodNotSupported}"), LanguageBindingService.GetCodonPerCodeFileName(editor.FileName).Language)); return null; } } diff --git a/src/AddIns/Misc/SharpRefactoring/Src/Forms/ExtractMethodForm.cs b/src/AddIns/Misc/SharpRefactoring/Src/Forms/ExtractMethodForm.cs index f89013bcbf..ae54c52e69 100644 --- a/src/AddIns/Misc/SharpRefactoring/Src/Forms/ExtractMethodForm.cs +++ b/src/AddIns/Misc/SharpRefactoring/Src/Forms/ExtractMethodForm.cs @@ -8,8 +8,11 @@ */ using System; +using System.Collections.Generic; using System.Drawing; +using System.Linq; using System.Windows.Forms; + using ICSharpCode.Core; namespace SharpRefactoring.Forms @@ -54,9 +57,11 @@ namespace SharpRefactoring.Forms string afterName = text.Substring(text.IndexOf('(')); - string type = text.Split(' ')[0]; + List list = text.Split(' ').ToList(); + + list.RemoveAt(list.Count - 1); - this.txtPreview.Text = type + " " + this.txtName.Text + afterName; + this.txtPreview.Text = string.Join(" ", list.ToArray()) + " " + this.txtName.Text + afterName; } } } diff --git a/src/AddIns/Misc/SharpRefactoring/Src/MethodExtractorBase.cs b/src/AddIns/Misc/SharpRefactoring/Src/MethodExtractorBase.cs index 910961b0f8..79dcbd6ed9 100644 --- a/src/AddIns/Misc/SharpRefactoring/Src/MethodExtractorBase.cs +++ b/src/AddIns/Misc/SharpRefactoring/Src/MethodExtractorBase.cs @@ -64,7 +64,7 @@ namespace SharpRefactoring Statement caller; InvocationExpression expr = new InvocationExpression(new IdentifierExpression(method.Name), CreateArgumentExpressions(method.Parameters)); - if (method.TypeReference.Type != "void") { + if (method.TypeReference.Type != "System.Void") { if (parent is MethodDeclaration) { if (method.TypeReference == (parent as MethodDeclaration).TypeReference) caller = new ReturnStatement(expr); @@ -100,7 +100,7 @@ namespace SharpRefactoring newMethod.Body.Children.Add(new ReturnStatement(new IdentifierExpression(possibleReturnValues[possibleReturnValues.Count - 1].Name))); this.returnedVariable = possibleReturnValues[possibleReturnValues.Count - 1]; } else { - newMethod.TypeReference = new TypeReference("void"); + newMethod.TypeReference = new TypeReference("System.Void", true); this.returnedVariable = null; } }