|
|
@ -2,8 +2,10 @@ |
|
|
|
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
|
|
|
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
|
|
|
|
|
|
|
|
|
|
|
using System; |
|
|
|
using System; |
|
|
|
|
|
|
|
using System.Linq; |
|
|
|
using ICSharpCode.AvalonEdit.Editing; |
|
|
|
using ICSharpCode.AvalonEdit.Editing; |
|
|
|
using ICSharpCode.AvalonEdit.Snippets; |
|
|
|
using ICSharpCode.AvalonEdit.Snippets; |
|
|
|
|
|
|
|
using ICSharpCode.NRefactory.Ast; |
|
|
|
using ICSharpCode.SharpDevelop; |
|
|
|
using ICSharpCode.SharpDevelop; |
|
|
|
using ICSharpCode.SharpDevelop.Dom; |
|
|
|
using ICSharpCode.SharpDevelop.Dom; |
|
|
|
using ICSharpCode.SharpDevelop.Dom.Refactoring; |
|
|
|
using ICSharpCode.SharpDevelop.Dom.Refactoring; |
|
|
@ -17,6 +19,14 @@ namespace SharpRefactoring |
|
|
|
{ |
|
|
|
{ |
|
|
|
public void Insert(CompletionContext context, ICompletionItem item) |
|
|
|
public void Insert(CompletionContext context, ICompletionItem item) |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
if (item == null) |
|
|
|
|
|
|
|
throw new ArgumentNullException("item"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!(item is OverrideCompletionItem)) |
|
|
|
|
|
|
|
throw new ArgumentException("item is not an OverrideCompletionItem"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
OverrideCompletionItem completionItem = item as OverrideCompletionItem; |
|
|
|
|
|
|
|
|
|
|
|
ITextEditor textEditor = context.Editor; |
|
|
|
ITextEditor textEditor = context.Editor; |
|
|
|
|
|
|
|
|
|
|
|
IEditorUIService uiService = textEditor.GetService(typeof(IEditorUIService)) as IEditorUIService; |
|
|
|
IEditorUIService uiService = textEditor.GetService(typeof(IEditorUIService)) as IEditorUIService; |
|
|
@ -31,21 +41,35 @@ namespace SharpRefactoring |
|
|
|
|
|
|
|
|
|
|
|
CodeGenerator generator = parseInfo.CompilationUnit.Language.CodeGenerator; |
|
|
|
CodeGenerator generator = parseInfo.CompilationUnit.Language.CodeGenerator; |
|
|
|
IClass current = parseInfo.CompilationUnit.GetInnermostClass(textEditor.Caret.Line, textEditor.Caret.Column); |
|
|
|
IClass current = parseInfo.CompilationUnit.GetInnermostClass(textEditor.Caret.Line, textEditor.Caret.Column); |
|
|
|
|
|
|
|
ClassFinder finder = new ClassFinder(current, textEditor.Caret.Line, textEditor.Caret.Column); |
|
|
|
|
|
|
|
|
|
|
|
if (current == null) |
|
|
|
if (current == null) |
|
|
|
return; |
|
|
|
return; |
|
|
|
|
|
|
|
|
|
|
|
ITextAnchor anchor = textEditor.Document.CreateAnchor(textEditor.Caret.Offset); |
|
|
|
ITextAnchor endAnchor = textEditor.Document.CreateAnchor(textEditor.Caret.Offset); |
|
|
|
anchor.MovementType = AnchorMovementType.AfterInsertion; |
|
|
|
endAnchor.MovementType = AnchorMovementType.AfterInsertion; |
|
|
|
|
|
|
|
|
|
|
|
ITextAnchor startAnchor = textEditor.Document.CreateAnchor(textEditor.Caret.Offset); |
|
|
|
ITextAnchor startAnchor = textEditor.Document.CreateAnchor(textEditor.Caret.Offset); |
|
|
|
anchor.MovementType = AnchorMovementType.BeforeInsertion; |
|
|
|
startAnchor.MovementType = AnchorMovementType.BeforeInsertion; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
MethodDeclaration member = (MethodDeclaration)generator.GetOverridingMethod(completionItem.Member, finder); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
string indent = DocumentUtilitites.GetWhitespaceBefore(textEditor.Document, textEditor.Caret.Offset); |
|
|
|
|
|
|
|
string codeForBaseCall = generator.GenerateCode(member.Body.Children.OfType<AbstractNode>().First(), ""); |
|
|
|
|
|
|
|
string code = generator.GenerateCode(member, indent); |
|
|
|
|
|
|
|
int marker = code.IndexOf(codeForBaseCall); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
textEditor.Document.Insert(startAnchor.Offset, code.Substring(0, marker).TrimStart()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ITextAnchor insertionPos = textEditor.Document.CreateAnchor(endAnchor.Offset); |
|
|
|
|
|
|
|
insertionPos.MovementType = AnchorMovementType.BeforeInsertion; |
|
|
|
|
|
|
|
|
|
|
|
InsertionContext insertionContext = new InsertionContext(textEditor.GetService(typeof(TextArea)) as TextArea, startAnchor.Offset); |
|
|
|
InsertionContext insertionContext = new InsertionContext(textEditor.GetService(typeof(TextArea)) as TextArea, startAnchor.Offset); |
|
|
|
|
|
|
|
|
|
|
|
AbstractInlineRefactorDialog dialog = new OverrideToStringMethodDialog(insertionContext, textEditor, startAnchor, anchor, current.Fields); |
|
|
|
AbstractInlineRefactorDialog dialog = new OverrideToStringMethodDialog(insertionContext, textEditor, startAnchor, insertionPos, current.Fields); |
|
|
|
|
|
|
|
dialog.Element = uiService.CreateInlineUIElement(insertionPos, dialog); |
|
|
|
|
|
|
|
|
|
|
|
dialog.Element = uiService.CreateInlineUIElement(anchor, dialog); |
|
|
|
textEditor.Document.InsertNormalized(endAnchor.Offset, Environment.NewLine + code.Substring(marker + codeForBaseCall.Length)); |
|
|
|
|
|
|
|
|
|
|
|
insertionContext.RegisterActiveElement(new InlineRefactorSnippetElement(cxt => null, ""), dialog); |
|
|
|
insertionContext.RegisterActiveElement(new InlineRefactorSnippetElement(cxt => null, ""), dialog); |
|
|
|
insertionContext.RaiseInsertionCompleted(EventArgs.Empty); |
|
|
|
insertionContext.RaiseInsertionCompleted(EventArgs.Empty); |
|
|
|